@using Indotalent.Features.Utilities.Todo @using Indotalent.Features.Utilities.Todo.Cqrs @using Indotalent.Shared.Utils @using MudBlazor @inject TodoService TodoService @inject ISnackbar Snackbar Add New Todo Create a new master todo and its items. Todo Name Start Date Start Time End Date End Time Description Cancel @if (_processing) { Processing... } else { Create Todo } @code { [Parameter] public EventCallback OnCancel { get; set; } [Parameter] public EventCallback OnSuccess { get; set; } private MudForm _form = default!; private CreateTodoValidator _validator = new(); private CreateTodoRequest _model = new(); private bool _processing = false; private DateTime? _startDate = DateTime.Today; private TimeSpan? _startTime = DateTime.Now.TimeOfDay; private DateTime? _endDate = DateTime.Today; private TimeSpan? _endTime = DateTime.Now.TimeOfDay.Add(TimeSpan.FromHours(1)); private async Task Submit() { if (_startDate.HasValue && _startTime.HasValue) _model.StartTime = _startDate.Value.Date.Add(_startTime.Value); if (_endDate.HasValue && _endTime.HasValue) _model.EndTime = _endDate.Value.Date.Add(_endTime.Value); await _form.Validate(); if (!_form.IsValid) return; _processing = true; try { var response = await TodoService.CreateTodoAsync(_model); await Task.Delay(500); if (response != null && response.IsSuccess) { Snackbar.Add("Todo created successfully", Severity.Success); await OnSuccess.InvokeAsync(); } } catch (Exception ex) { Snackbar.Add($"Error: {ex.Message}", Severity.Error); } finally { _processing = false; } } }