Skip to content

Commit 84d3011

Browse files
committed
Uploading the project to the repository
1 parent 9025019 commit 84d3011

36 files changed

+1593
-1
lines changed

BlazorMVVMToDo.sln

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
2+
Microsoft Visual Studio Solution File, Format Version 12.00
3+
# Visual Studio Version 16
4+
VisualStudioVersion = 16.0.30204.135
5+
MinimumVisualStudioVersion = 10.0.40219.1
6+
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "BlazorMVVMToDo", "BlazorMVVMToDo\BlazorMVVMToDo.csproj", "{4D5C3353-4E71-42B9-B720-3B880FDA1120}"
7+
EndProject
8+
Global
9+
GlobalSection(SolutionConfigurationPlatforms) = preSolution
10+
Debug|Any CPU = Debug|Any CPU
11+
Release|Any CPU = Release|Any CPU
12+
EndGlobalSection
13+
GlobalSection(ProjectConfigurationPlatforms) = postSolution
14+
{4D5C3353-4E71-42B9-B720-3B880FDA1120}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
15+
{4D5C3353-4E71-42B9-B720-3B880FDA1120}.Debug|Any CPU.Build.0 = Debug|Any CPU
16+
{4D5C3353-4E71-42B9-B720-3B880FDA1120}.Release|Any CPU.ActiveCfg = Release|Any CPU
17+
{4D5C3353-4E71-42B9-B720-3B880FDA1120}.Release|Any CPU.Build.0 = Release|Any CPU
18+
EndGlobalSection
19+
GlobalSection(SolutionProperties) = preSolution
20+
HideSolutionNode = FALSE
21+
EndGlobalSection
22+
GlobalSection(ExtensibilityGlobals) = postSolution
23+
SolutionGuid = {178A8E83-BA9F-4907-8BDD-2C51C609C0E9}
24+
EndGlobalSection
25+
EndGlobal

BlazorMVVMToDo/App.razor

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
2+
<Router AppAssembly="@typeof(Program).Assembly">
3+
<Found Context="routeData">
4+
<RouteView RouteData="@routeData" DefaultLayout="@typeof(MainLayout)" />
5+
</Found>
6+
<NotFound>
7+
<LayoutView Layout="@typeof(MainLayout)">
8+
<p>Sorry, there's nothing at this address.</p>
9+
</LayoutView>
10+
</NotFound>
11+
</Router>

BlazorMVVMToDo/BlazorMVVMToDo.csproj

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
<Project Sdk="Microsoft.NET.Sdk.Web">
2+
3+
<PropertyGroup>
4+
<TargetFramework>netcoreapp3.1</TargetFramework>
5+
</PropertyGroup>
6+
7+
</Project>
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
<hr />
2+
3+
4+
<EditForm Model="@ViewModel.ToDoItem" OnValidSubmit="@SaveTodoItem">
5+
<div class="col-4">
6+
<div class="form-group">
7+
<label for="title">Title</label>
8+
<InputText class="form-control" id="title" @bind-Value=@ViewModel.ToDoItem.Title />
9+
</div>
10+
<div class="form-group">
11+
<label for="date">Date</label>
12+
<InputDate class="form-control" id="date" @bind-Value=@ViewModel.ToDoItem.Date />
13+
</div>
14+
<div class="form-group">
15+
<label for="notes">Notes</label>
16+
<InputTextArea class="form-control" id="notes" @bind-Value=@ViewModel.ToDoItem.Notes />
17+
</div>
18+
<div class="form-check">
19+
<InputCheckbox class="form-check-input" id="done" @bind-Value=@ViewModel.ToDoItem.Done />
20+
<label for="done" class="form-check-label">Done</label>
21+
</div>
22+
<input type="hidden" @bind-value="@ViewModel.ToDoItem.Id" />
23+
<button type="submit" class="btn btn-primary" disabled="@ViewModel.IsBusy">Save</button>
24+
</div>
25+
</EditForm>
26+
27+
28+
@code {
29+
[CascadingParameter(Name = "ViewModel")]
30+
IToDoViewModel ViewModel { get; set; }
31+
32+
void SaveTodoItem()
33+
{
34+
ViewModel.SaveToDoItem(ViewModel.ToDoItem);
35+
ViewModel.ToDoItem = new ToDoItem();
36+
}
37+
38+
}
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
@if (ViewModel?.ToDoItemList == null)
2+
{
3+
<p><em>Loading...</em></p>
4+
}
5+
else
6+
{
7+
<div class="card-deck" >
8+
@foreach (var todoitem in ViewModel.ToDoItemList.OrderBy(i => i.Date).ThenBy(i=>i.Done))
9+
{
10+
<div class="card mb-3 @(todoitem.Done ? "bg-light" : "text-white bg-dark" )" style="min-width: 18rem; max-width: 18rem;">
11+
<div class="card-header">@(todoitem.Date?.ToShortDateString() ?? string.Empty)</div>
12+
<div class="card-body">
13+
<h5 class="card-title">@todoitem.Title</h5>
14+
<p class="card-text">@todoitem.Notes</p>
15+
<button disabled="@ViewModel.IsBusy" class="btn @(todoitem.Done ? "btn-secondary" : "btn-primary")" @onclick="@(() => SetToDoItem(todoitem))">Edit</button>
16+
</div>
17+
</div>
18+
}
19+
</div>
20+
}
21+
22+
@code {
23+
[CascadingParameter(Name = "ViewModel")]
24+
IToDoViewModel ViewModel { get; set; }
25+
26+
void SetToDoItem(ToDoItem todoitem)
27+
{
28+
ViewModel.ToDoItem = todoitem;
29+
}
30+
}

BlazorMVVMToDo/Models/ToDoItem.cs

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.Linq;
4+
using System.Threading.Tasks;
5+
6+
namespace BlazorMVVMToDo.Models
7+
{
8+
public class ToDoItem
9+
{
10+
public ToDoItem()
11+
{
12+
Id = new Guid();
13+
Done = false;
14+
}
15+
16+
public Guid Id { get; set; }
17+
public string Title { get; set; }
18+
public string Notes { get; set; }
19+
public DateTime? Date { get; set; }
20+
public bool Done { get; set; }
21+
}
22+
}

BlazorMVVMToDo/Pages/Error.razor

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
@page "/error"
2+
3+
4+
<h1 class="text-danger">Error.</h1>
5+
<h2 class="text-danger">An error occurred while processing your request.</h2>
6+
7+
<h3>Development Mode</h3>
8+
<p>
9+
Swapping to <strong>Development</strong> environment will display more detailed information about the error that occurred.
10+
</p>
11+
<p>
12+
<strong>The Development environment shouldn't be enabled for deployed applications.</strong>
13+
It can result in displaying sensitive information from exceptions to end users.
14+
For local debugging, enable the <strong>Development</strong> environment by setting the <strong>ASPNETCORE_ENVIRONMENT</strong> environment variable to <strong>Development</strong>
15+
and restarting the app.
16+
</p>

BlazorMVVMToDo/Pages/Index.razor

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
@page "/"
2+
3+
<h3>Index</h3>
4+
5+
@code {
6+
7+
}

BlazorMVVMToDo/Pages/ToDoPage.razor

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
@page "/todo"
2+
3+
@inject IToDoViewModel ViewModel
4+
@using System.ComponentModel;
5+
@implements IDisposable
6+
7+
<h1>Items to do: @ViewModel.ToDoItems</h1>
8+
9+
<CascadingValue Value=@ViewModel Name="ViewModel">
10+
<ToDoListComponent />
11+
<ToDoFormComponent />
12+
</CascadingValue>
13+
14+
@code {
15+
16+
protected override async Task OnInitializedAsync()
17+
{
18+
ViewModel.PropertyChanged += async (sender, e) => {
19+
await InvokeAsync(() =>
20+
{
21+
StateHasChanged();
22+
});
23+
};
24+
await base.OnInitializedAsync();
25+
}
26+
27+
async void OnPropertyChangedHandler(object sender, PropertyChangedEventArgs e)
28+
{
29+
await InvokeAsync(() =>
30+
{
31+
StateHasChanged();
32+
});
33+
}
34+
35+
public void Dispose()
36+
{
37+
ViewModel.PropertyChanged -= OnPropertyChangedHandler;
38+
}
39+
}

BlazorMVVMToDo/Pages/_Host.cshtml

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
@page "/"
2+
@namespace BlazorMVVMToDo.Pages
3+
@addTagHelper *, Microsoft.AspNetCore.Mvc.TagHelpers
4+
@{
5+
Layout = null;
6+
}
7+
8+
<!DOCTYPE html>
9+
<html lang="en">
10+
<head>
11+
<meta charset="utf-8" />
12+
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
13+
<title>BlazorMVVMToDo</title>
14+
<base href="~/" />
15+
<link rel="stylesheet" href="css/bootstrap/bootstrap.min.css" />
16+
<link href="css/site.css" rel="stylesheet" />
17+
</head>
18+
<body>
19+
<app>
20+
<component type="typeof(App)" render-mode="ServerPrerendered" />
21+
</app>
22+
23+
<div id="blazor-error-ui">
24+
<environment include="Staging,Production">
25+
An error has occurred. This application may no longer respond until reloaded.
26+
</environment>
27+
<environment include="Development">
28+
An unhandled exception has occurred. See browser dev tools for details.
29+
</environment>
30+
<a href="" class="reload">Reload</a>
31+
<a class="dismiss">🗙</a>
32+
</div>
33+
34+
<script src="_framework/blazor.server.js"></script>
35+
</body>
36+
</html>

0 commit comments

Comments
 (0)