Untitled

mail@pastecode.io avatar
unknown
plain_text
a month ago
1.4 kB
3
Indexable
Never
@page "/add-task"
@inject ITaskManagement TaskManagerRepo;


<h3>Add Task</h3>

<EditForm Model="@task" OnValidSubmit="HandleSubmit" FormName="AddTask">
    <DataAnnotationsValidator />
    <ValidationSummary />

    <label>Title</label>
    <InputText @bind-Value="task.TaskTitle" />
    <ValidationMessage For="@(() => task.TaskTitle)" />

    <br />
    <label>Description</label>
    <InputText @bind-Value="task.TaskDescription" />
    <ValidationMessage For="@(() => task.TaskDescription)" />

    <br />
    <label>Start Date</label>
    <InputDate @bind-Value="task.StartDate" />
    <ValidationMessage For="@(() => task.StartDate)" />

    <br />
    <label>End Date</label>
    <InputDate @bind-Value="task.EndDate" />
    <ValidationMessage For="@(() => task.EndDate)" />

    <br />
    <button type="submit" class="btn btn-primary">Submit</button>
</EditForm>

@code {
    private TaskList task = new TaskList
    { 
        TaskTitle=string.Empty, 
        TaskDescription = string.Empty,
        StartDate=DateTime.Today,
        EndDate=DateTime.Today
    };

    async Task HandleSubmit()
    {
        try
        {
            await TaskManagerRepo.PostTask();
            task = new TaskList();
        }
        catch (Exception ex)
        {
            Console.WriteLine("Error adding task: " + ex.Message);
        }
    }
}
Leave a Comment