Untitled
unknown
plain_text
12 days ago
2.0 kB
2
Indexable
Never
@page "/add-task" @inject ITaskManagement TaskManagerRepo; <h3>Add Task</h3> <EditForm Model="@task" OnValidSubmit="HandleSubmit"> <DataAnnotationsValidator /> <ValidationSummary /> <DxFormLayout> <DxFormLayoutItem Caption="Title"> <DxTextBox @bind-Text="task.TaskTitle" /> <ValidationMessage For="@(() => task.TaskTitle)" /> </DxFormLayoutItem> <DxFormLayoutItem Caption="Description"> <DxMemo @bind-Text="task.TaskDescription" /> <ValidationMessage For="@(() => task.TaskDescription)" /> </DxFormLayoutItem> <DxFormLayoutItem Caption="Start Date"> <DxDateEdit @bind-Date="task.StartDate" /> <ValidationMessage For="@(() =>task.StartDate)" /> </DxFormLayoutItem> <DxFormLayoutItem Caption="End Date"> <DxDateEdit @bind-Date="task.EndDate" /> <ValidationMessage For="@(() => task.EndDate)" /> </DxFormLayoutItem> <DxFormLayoutItem> <DxButton Text="Submit" ButtonType="ButtonType.Primary" Type="submit" /> </DxFormLayoutItem> </DxFormLayout> </EditForm> @code { [SupplyParameterFromForm] private TaskList task{ get; set; } = new TaskList { TaskTitle = string.Empty, TaskDescription = string.Empty, StartDate = DateTime.UtcNow, EndDate = DateTime.UtcNow }; async Task HandleSubmit() { try { var result = await TaskManagerRepo.PostTask(task.TaskTitle, task.TaskDescription, task.StartDate, task.EndDate); if (result != null) task = new TaskList(); else Console.WriteLine("Failed to add task"); } catch (Exception ex) { Console.WriteLine("Error adding task: " + ex.Message); } } }
Leave a Comment