Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{}
Binary file added Csharp3-main/localdb.db
Binary file not shown.
12 changes: 6 additions & 6 deletions ToDoList/ToDoList.sln
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ToDoList.Test", "tests\ToDo
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ToDoList.Persistence", "src\ToDoList.Persistence\ToDoList.Persistence.csproj", "{9D93325A-6242-4417-AF1B-7B06DB3A7864}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ToDoList.Frontend", "src\ToDoList.Frontend\ToDoList.Frontend.csproj", "{2A4A356C-0F7A-476E-88C9-E101784C9F30}"
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ToDoList.Frontend", "src\ToDoList.Frontend\ToDoList.Frontend.csproj", "{04CA31F5-49D8-4978-B917-98D3B10CD156}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Expand All @@ -42,16 +42,16 @@ Global
{9D93325A-6242-4417-AF1B-7B06DB3A7864}.Debug|Any CPU.Build.0 = Debug|Any CPU
{9D93325A-6242-4417-AF1B-7B06DB3A7864}.Release|Any CPU.ActiveCfg = Release|Any CPU
{9D93325A-6242-4417-AF1B-7B06DB3A7864}.Release|Any CPU.Build.0 = Release|Any CPU
{2A4A356C-0F7A-476E-88C9-E101784C9F30}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{2A4A356C-0F7A-476E-88C9-E101784C9F30}.Debug|Any CPU.Build.0 = Debug|Any CPU
{2A4A356C-0F7A-476E-88C9-E101784C9F30}.Release|Any CPU.ActiveCfg = Release|Any CPU
{2A4A356C-0F7A-476E-88C9-E101784C9F30}.Release|Any CPU.Build.0 = Release|Any CPU
{04CA31F5-49D8-4978-B917-98D3B10CD156}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{04CA31F5-49D8-4978-B917-98D3B10CD156}.Debug|Any CPU.Build.0 = Debug|Any CPU
{04CA31F5-49D8-4978-B917-98D3B10CD156}.Release|Any CPU.ActiveCfg = Release|Any CPU
{04CA31F5-49D8-4978-B917-98D3B10CD156}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(NestedProjects) = preSolution
{D8E3A966-671F-4E7C-86BD-B51066E39B67} = {36FD4317-29CD-4B7B-AA95-92F1582DEC01}
{61CAF0A1-2EBB-410B-BB40-DA9590E88664} = {36FD4317-29CD-4B7B-AA95-92F1582DEC01}
{EEB409BA-8B59-4C14-84D3-301E75F542C4} = {D78FC9D1-46B7-4F93-AE9A-24719D8C82D2}
{9D93325A-6242-4417-AF1B-7B06DB3A7864} = {36FD4317-29CD-4B7B-AA95-92F1582DEC01}
{2A4A356C-0F7A-476E-88C9-E101784C9F30} = {36FD4317-29CD-4B7B-AA95-92F1582DEC01}
{04CA31F5-49D8-4978-B917-98D3B10CD156} = {36FD4317-29CD-4B7B-AA95-92F1582DEC01}
EndGlobalSection
EndGlobal
Binary file modified ToDoList/data/localdb.db
Binary file not shown.
4 changes: 2 additions & 2 deletions ToDoList/src/ToDoList.Domain/DTOs/ToDoItemCreateRequestDto.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ namespace ToDoList.Domain.DTOs;

using ToDoList.Domain.Models;

public record ToDoItemCreateRequestDto(string Name, string Description, bool IsCompleted) //id is generated
public record ToDoItemCreateRequestDto(string Name, string Description, bool IsCompleted, string? Category) //id is generated
{
public ToDoItem ToDomain() => new() { Name = Name, Description = Description, IsCompleted = IsCompleted };
public ToDoItem ToDomain() => new() { Name = Name, Description = Description, IsCompleted = IsCompleted, Category = Category };
}
4 changes: 2 additions & 2 deletions ToDoList/src/ToDoList.Domain/DTOs/ToDoItemGetResponseDto.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
namespace ToDoList.Domain.DTOs;
using ToDoList.Domain.Models;

public record class ToDoItemGetResponseDto(int Id, string Name, string Description, bool IsCompleted) //let client know the Id
public record class ToDoItemGetResponseDto(int Id, string Name, string Description, bool IsCompleted, string? Category) //let client know the Id
{
public static ToDoItemGetResponseDto FromDomain(ToDoItem item) => new(item.ToDoItemId, item.Name, item.Description, item.IsCompleted);
public static ToDoItemGetResponseDto FromDomain(ToDoItem item) => new(item.ToDoItemId, item.Name, item.Description, item.IsCompleted, item.Category);
}
4 changes: 2 additions & 2 deletions ToDoList/src/ToDoList.Domain/DTOs/ToDoItemUpdateRequestDto.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
namespace ToDoList.Domain.DTOs;
using ToDoList.Domain.Models;

public record class ToDoItemUpdateRequestDto(string Name, string Description, bool IsCompleted)
public record class ToDoItemUpdateRequestDto(string Name, string Description, bool IsCompleted, string? Category)
{
public ToDoItem ToDomain() => new() { Name = this.Name, Description = this.Description, IsCompleted = this.IsCompleted };
public ToDoItem ToDomain() => new() { Name = this.Name, Description = this.Description, IsCompleted = this.IsCompleted, Category = this.Category };
}
2 changes: 2 additions & 0 deletions ToDoList/src/ToDoList.Domain/Models/ToDoItem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,6 @@ public class ToDoItem
[StringLength(250)]
public string Description { get; set; }
public bool IsCompleted { get; set; }
[StringLength(250)]
public string? Category { get; set; }
}
8 changes: 5 additions & 3 deletions ToDoList/src/ToDoList.Frontend/Clients/ToDoItemsClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ public class ToDoItemsClient(HttpClient httpClient) : IToDoItemsClient //primary
{
public async Task CreateItemAsync(ToDoItemView itemView)
{
var itemRequest = new ToDoItemCreateRequestDto(itemView.Name, itemView.Description, itemView.IsCompleted);
var itemRequest = new ToDoItemCreateRequestDto(itemView.Name, itemView.Description, itemView.IsCompleted, itemView.Category);
try
{
var response = await httpClient.PostAsJsonAsync("api/ToDoItems", itemRequest);
Expand Down Expand Up @@ -65,6 +65,7 @@ public async Task DeleteItemAsync(ToDoItemView itemView)
Name = response.Name,
Description = response.Description,
IsCompleted = response.IsCompleted,
Category = response.Category
};
}
catch (Exception e)
Expand All @@ -90,7 +91,8 @@ public async Task<List<ToDoItemView>> ReadItemsAsync()
ToDoItemId = dto.Id,
Name = dto.Name,
Description = dto.Description,
IsCompleted = dto.IsCompleted
IsCompleted = dto.IsCompleted,
Category = dto.Category
}).ToList();
}
catch (Exception e)
Expand All @@ -104,7 +106,7 @@ public async Task UpdateItemAsync(ToDoItemView itemView)
{
try
{
var itemRequest = new ToDoItemUpdateRequestDto(itemView.Name, itemView.Description, itemView.IsCompleted);
var itemRequest = new ToDoItemUpdateRequestDto(itemView.Name, itemView.Description, itemView.IsCompleted,itemView.Category);
var response = await httpClient.PutAsJsonAsync($"api/ToDoItems/{itemView.ToDoItemId}", itemRequest);
if (response.StatusCode == System.Net.HttpStatusCode.NoContent)
{
Expand Down
12 changes: 12 additions & 0 deletions ToDoList/src/ToDoList.Frontend/Components/AhojSvete.razor
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
@page "/AhojSvete"

<PageTitle>Ahoj svete</PageTitle>

<h1>@ahojSvete</h1>

Vítej v moji aplikaci.

@code
{
string ahojSvete = "Ahoj světe přes c# z jiné stránky!";
}
4 changes: 4 additions & 0 deletions ToDoList/src/ToDoList.Frontend/Components/App.razor
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,16 @@
<base href="/" />
<link rel="stylesheet" href="app.css" />
<link rel="stylesheet" href="ToDoList.Frontend.styles.css" />
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.3/dist/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-QWTKZyjpPEjISv5WaRU9OFeRpok6YctnYmDr5pNlyT2bRjXh0JMhjY6hW+ALEwIH" crossorigin="anonymous">
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bootstrap-icons@1.11.3/font/bootstrap-icons.min.css">
<HeadOutlet />
</head>

<body>
<Routes />
<script src="_framework/blazor.web.js"></script>
<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.3.3/dist/js/bootstrap.bundle.min.js" integrity="sha384-YvpcrYf0tY3lHB60NNkmXc5s9fDVZLESaAA55NDzOxhy9GkcIdslK1eN7N6jIeHz" crossorigin="anonymous"></script>

</body>

</html>
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
@inherits LayoutComponentBase

<div class=" container">
@Body
</div>
12 changes: 0 additions & 12 deletions ToDoList/src/ToDoList.Frontend/Components/Pages/AhojSvete.razor

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
@page "/mujDashboard"
@rendermode InteractiveServer

<h1>DashBoard</h1>
<!--@((MarkupString)GenerateTable())-->
<table>
<thead>
<tr>
<th>
ID Seřadit
<button @onclick="OrderById">@((isSortedByIdAscending ? "Od nejvyššího" : "Od nejnižšího"))</button>
</th>
<th>
Name Seřadit
<button @onclick="OrderByName">@((isSortedByNameAscending ? "Z-A" : "A-Z"))</button>
</th>
</tr>
</thead>
<tbody>

@foreach (var todoItem in toDoItems)
{
<tr>
<td>@todoItem.ToDoItemId</td>
<td>@todoItem.Name</td>
</tr>
}
</tbody>
</table>

@code {
/* public string GenerateTable()
{
var html = new System.Text.StringBuilder();
html.Append("<table>");
foreach (var todoitem in toDoItems)
{
html.Append("<tr>");
html.Append($"<td>{todoitem.ToDoItemId}</td>");
html.Append($"<td>{todoitem.Name}</td>");
html.Append("</tr>");
}
html.Append("</table>");
return html.ToString();
}*/
private List<ToDoItemView> toDoItems = new List<ToDoItemView>
{
new ToDoItemView { ToDoItemId = 1, Name = "Udělat úkol na Czechitas", IsCompleted = false },
new ToDoItemView { ToDoItemId = 2, Name = "Udělat nepovinný úkol na Czechitas", IsCompleted = false }
};

private bool isSortedByIdAscending = true;
private bool isSortedByNameAscending = true;

private void OrderById()
{
if (isSortedByIdAscending)
toDoItems = toDoItems.OrderByDescending(item => item.ToDoItemId).ToList();
else
toDoItems = toDoItems.OrderBy(item => item.ToDoItemId).ToList();

isSortedByIdAscending = !isSortedByIdAscending;
}

private void OrderByName()
{
if (isSortedByNameAscending)
toDoItems = toDoItems.OrderByDescending(item => item.Name).ToList();
else
toDoItems = toDoItems.OrderBy(item => item.Name).ToList();

isSortedByNameAscending = !isSortedByNameAscending;
}

public class ToDoItemView
{
public int ToDoItemId { get; set; }
public string Name { get; set; }
public string Description { get; set; }
public bool IsCompleted { get; set; }
}
}
100 changes: 100 additions & 0 deletions ToDoList/src/ToDoList.Frontend/Components/Pages/DashBoard.razor
Original file line number Diff line number Diff line change
@@ -0,0 +1,100 @@
@using ToDoList.Frontend.Views
@using ToDoList.Frontend.Clients
@inject NavigationManager NavigationManager
@inject IToDoItemsClient ToDoItemsClient
@rendermode InteractiveServer

<h1>Dashboard</h1>
<button class="btn btn-dark" @onclick="OrderById">@((isSortedByIdAscending ? "Od nejvyššího" : "Od nejnižšího"))</button>
<button class ="btn btn-dark" @onclick="OrderByName">@((isSortedByNameAscending ? "Z-A" : "A-Z"))</button>
<table class="table table-hover">
<thead class="table-dark">
<tr>
<th>ID</th>
<th>Name</th>
<th>Description</th>
<th>IsCompleted</th>
<th>Category</th>
<th class="w-auto">Actions</th>
</tr>
</thead>
<tbody>
@if (toDoItems is not null)
{
@foreach (var toDoItem in toDoItems)
{
<tr class="@GetCorrectClassForTableLine(toDoItem.IsCompleted)">
<td>@toDoItem.ToDoItemId</td>
<td>@toDoItem.Name</td>
<td>@toDoItem.Description</td>
<td>@toDoItem.IsCompleted</td>
<td>@toDoItem.Category</td>
<td><div class="btn-group" role="group">
<button class="btn btn-success" @onclick="() => EditItem(toDoItem)"><i class="bi bi-pencil-square"></i></button>
<button class="btn btn-danger" @onclick="() => DeleteItem(toDoItem)"><i class="bi bi-trash"></i></button>
<button class="btn btn-warning btn-sm" @onclick="() => ToggleCompletion(toDoItem)"><i class="bi @(toDoItem.IsCompleted ? "bi-check-circle" : "bi-circle")"></i></button>
</div>
</td>


</tr>
}
}
</tbody>
</table>


@code
{
protected override async Task OnInitializedAsync()
{
toDoItems = await ToDoItemsClient.ReadItemsAsync();
}
private List<ToDoItemView>? toDoItems = [];


private bool isSortedByIdAscending = true;
private bool isSortedByNameAscending = true;

private void OrderById()
{
if (isSortedByIdAscending)
toDoItems = toDoItems.OrderByDescending(item => item.ToDoItemId).ToList();
else
toDoItems = toDoItems.OrderBy(item => item.ToDoItemId).ToList();

isSortedByIdAscending = !isSortedByIdAscending;
}

private void OrderByName()
{
if (isSortedByNameAscending)
toDoItems = toDoItems.OrderByDescending(item => item.Name).ToList();
else
toDoItems = toDoItems.OrderBy(item => item.Name).ToList();

isSortedByNameAscending = !isSortedByNameAscending;
}

protected string GetCorrectClassForTableLine(bool isCompleted)
{
return isCompleted ? "table-success" : "table-secondary";
}
public void EditItem(ToDoItemView toDoItem)
{
NavigationManager.NavigateTo($"editToDoItem/{toDoItem.ToDoItemId}");
}
public async Task DeleteItem(ToDoItemView ToDoItemId)
{
await ToDoItemsClient.DeleteItemAsync(ToDoItemId);
toDoItems = await ToDoItemsClient.ReadItemsAsync();
}

public async Task ToggleCompletion(ToDoItemView toDoItem)
{
toDoItem.IsCompleted = !toDoItem.IsCompleted;
await ToDoItemsClient.UpdateItemAsync(toDoItem);
toDoItems = await ToDoItemsClient.ReadItemsAsync();
}
}

Loading