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 @@
{}
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.
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!";
}
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; }
}
}
48 changes: 48 additions & 0 deletions ToDoList/src/ToDoList.Frontend/Components/Pages/DashBoard.razor
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
@using ToDoList.Frontend.Views
@using ToDoList.Frontend.Clients
@inject IToDoItemsClient ToDoItemsClient
@rendermode InteractiveServer

<h1>Dashboard</h1>

<table>
<tr>
<td><button @onclick="OrderById">Seradit Podle Id</button></td>
<td><button @onclick="OrderByName">Seradit Podle Jmena</button></td>
<td></td>
<td></td>
</tr>
@if(toDoItems!=null)
{

}
@foreach(var toDoItem in toDoItems)
{
<tr>
<td>@toDoItem.ToDoItemId</td>
<td>@toDoItem.Name</td>
<td>@toDoItem.Description</td>
<td>@toDoItem.IsCompleted</td>
</tr>
}
</table>


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

public void OrderByName()
{
toDoItems = toDoItems?.OrderBy(x => x.Name).ToList();
}

public void OrderById()
{
toDoItems = toDoItems?.OrderBy(x => x.ToDoItemId).ToList();
}
}
50 changes: 39 additions & 11 deletions ToDoList/src/ToDoList.Frontend/Components/Pages/Home.razor
Original file line number Diff line number Diff line change
@@ -1,27 +1,55 @@
@page "/"
@rendermode InteractiveServer
<PageTitle>Domovska stranka</PageTitle>

<PageTitle>Home</PageTitle>
<DashBoard/>

<Dashboard />
<!--<h1>@AhojSvete()</h1>

<h1>@ahojSvete</h1>

Vítej v mojí aplikaci.
Vítej v moji aplikaci.
<br>
<button @onclick="Increment">Moje tlačítko</button>

<button @onclick="Increment"> Moje tlačítko</button>
<br>
Hodnota počítadla: @counter;

Hodnota počítadla: @counter

<h2> Tohle je nadpis druhe urovne</h2>
<p> Tohle je odstavec <br> se zalomenym textem</p>
@VypisCisla1Az10();


<ul>
<li> polozka 1 </li>
<li> polozka 2</li>
</ul>
<ol>
<li>První položka</li>
<li>Druhá položka</li>
<li>Třetí položka</li>
</ol>
@code
{
string ahojSvete = "Ahoj světe ještě jednou!";

int counter = 0;

public void Increment()
{
counter++;
}

string ahojSvete = "Ahoj světe přes c#!";

public string AhojSvete()
{
return "Ahoj světe přes c# z metody";
}

public string VypisCisla1Az10()
{
string vypis = "";
for (int i = 1; i < 10; i++)
{
vypis += i;
}
return vypis;
}-->

}
7 changes: 5 additions & 2 deletions ToDoList/src/ToDoList.Frontend/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,10 @@

// Add services to the container.
builder.Services.AddRazorComponents()
.AddInteractiveServerComponents();
.AddInteractiveServerComponents();

builder.Services.AddScoped(sp => new HttpClient { BaseAddress = new Uri("http://localhost:5000") });
builder.Services.AddScoped<IToDoItemsClient, ToDoItemsClient>();

builder.Services.AddScoped(sp => new HttpClient { BaseAddress = new Uri("http://localhost:5000") });
builder.Services.AddScoped<IToDoItemsClient, ToDoItemsClient>();
Expand All @@ -26,6 +29,6 @@
app.UseAntiforgery();

app.MapRazorComponents<App>()
.AddInteractiveServerRenderMode();
.AddInteractiveServerRenderMode();

app.Run();
8 changes: 8 additions & 0 deletions ToDoList/src/ToDoList.Persistence/Repositories/IRepository.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,11 @@ public interface IRepository<T> where T : class
public void Update(T item);
public void Delete(T item);
}
public interface IRepositoryAsync<T> where T : class
{
public Task CreateAsync(T item);
public Task<IEnumerable<T>> ReadAllAsync();
public Task<T?> ReadByIdAsync(int id);
public Task UpdateAsync(T item);
public Task DeleteAsync(T item);
}
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
namespace ToDoList.Persistence.Repositories;

using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Microsoft.EntityFrameworkCore;
using ToDoList.Domain.Models;

public class ToDoItemsRepository : IRepository<ToDoItem>
public class ToDoItemsRepository : IRepositoryAsync<ToDoItem>
{
private readonly ToDoItemsContext context;

Expand All @@ -12,22 +15,31 @@ public ToDoItemsRepository(ToDoItemsContext context)
this.context = context;
}

public void Create(ToDoItem item)
public async Task CreateAsync(ToDoItem item)
{
context.ToDoItems.Add(item);
context.SaveChanges();
await context.ToDoItems.AddAsync(item);
await context.SaveChangesAsync();
}
public IEnumerable<ToDoItem> ReadAll() => context.ToDoItems.ToList();
public ToDoItem? ReadById(int id) => context.ToDoItems.Find(id);
public void Update(ToDoItem item)

public async Task<IEnumerable<ToDoItem>> ReadAllAsync()
{
return await context.ToDoItems.ToListAsync();
}

public async Task<ToDoItem?> ReadByIdAsync(int id)
{
return await context.ToDoItems.FindAsync(id);
}

public async Task UpdateAsync(ToDoItem item)
{
context.Entry(item).CurrentValues.SetValues(item);
context.SaveChanges();
await context.SaveChangesAsync();
}

public void Delete(ToDoItem item)
public async Task DeleteAsync(ToDoItem item)
{
context.ToDoItems.Remove(item);
context.SaveChanges();
await context.SaveChangesAsync();
}
}
Loading