Skip to content

Commit

Permalink
Lekce 11
Browse files Browse the repository at this point in the history
  • Loading branch information
Hijtec committed Jan 11, 2025
1 parent 262348d commit 264ca70
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 9 deletions.
19 changes: 15 additions & 4 deletions ToDoList/src/ToDoList.Frontend/Components/Pages/EditToDoItem.razor
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,20 @@

@if (ToDoItem is not null)
{
<EditForm Model="ToDoItem" FormName="EditToDoItem" OnSubmit="Submit">
<InputText id="Name" @bind-Value="ToDoItem.Name" />
<InputText id="Description" @bind-Value="ToDoItem.Description" />
<InputCheckbox id="IsCompleted" @bind-Value="ToDoItem.IsCompleted" />
<EditForm Model="ToDoItem" FormName="EditToDoItem" OnValidSubmit="Submit"> @*OnSubmit -> OnValidSubmit*@
<DataAnnotationsValidator />
<label for="Name" class="form-label">Name:</label>
<InputText id="Name" class="form-control" @bind-Value="ToDoItem.Name" />
<ValidationMessage For="() => ToDoItem.Name" />

<label for="Description" class="form-label">Description:</label>
<InputText id="Description" class="form-control" @bind-Value="ToDoItem.Description" />
<ValidationMessage For="() => ToDoItem.Description" />

<label for="IsCompleted" class="form-check-label">IsCompleted:</label>
<InputCheckbox id="IsCompleted" class="form-check" @bind-Value="ToDoItem.IsCompleted" />
<ValidationMessage For="() => ToDoItem.IsCompleted" />

<button type="submit">Submit</button>
</EditForm>
}
Expand All @@ -32,6 +42,7 @@

public async Task Submit()
{

await ToDoItemsClient.UpdateItemAsync(ToDoItem);
NavigationManager.NavigateTo("/");
}
Expand Down
3 changes: 2 additions & 1 deletion ToDoList/src/ToDoList.Frontend/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@
builder.Services.AddRazorComponents()
.AddInteractiveServerComponents();

builder.Services.AddScoped(sp => new HttpClient { BaseAddress = new Uri("http://localhost:5000") });
// builder.Services.AddScoped(sp => new HttpClient { BaseAddress = new Uri("http://localhost:5000") });
builder.Services.AddScoped(sp => new HttpClient { BaseAddress = new Uri(builder.Configuration["ToDoItemApiAddress"]) });

Check warning on line 11 in ToDoList/src/ToDoList.Frontend/Program.cs

View workflow job for this annotation

GitHub Actions / build

Possible null reference argument for parameter 'uriString' in 'Uri.Uri(string uriString)'.
builder.Services.AddScoped<IToDoItemsClient, ToDoItemsClient>();

var app = builder.Build();
Expand Down
10 changes: 8 additions & 2 deletions ToDoList/src/ToDoList.Frontend/Views/ToDoItemView.cs
Original file line number Diff line number Diff line change
@@ -1,9 +1,15 @@
namespace ToDoList.Frontend.Views;

using System.ComponentModel.DataAnnotations;

public class ToDoItemView
{
public int ToDoItemId { get; set; }
public string Name { get; set; }
public string Description { get; set; }
[Required(ErrorMessage = "Name is mandatory.")]
[Length(3, 50)]
public required string Name { get; set; }
[Required(ErrorMessage = "Description is mandatory.")]
[StringLength(250)]
public required string Description { get; set; }
public bool IsCompleted { get; set; }
}
5 changes: 3 additions & 2 deletions ToDoList/src/ToDoList.Frontend/appsettings.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,6 @@
"Microsoft.AspNetCore": "Warning"
}
},
"AllowedHosts": "*"
}
"AllowedHosts": "*",
"ToDoItemApiAddress": "http://localhost:5000"
}

0 comments on commit 264ca70

Please sign in to comment.