-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
e44c848
commit d1d7151
Showing
43 changed files
with
1,645 additions
and
8 deletions.
There are no files selected for viewing
9 changes: 9 additions & 0 deletions
9
OwnProjects/46_BlazorServerCourse/DataAccessDemo/BlazorApp/Models/SearchModel.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
using System.ComponentModel.DataAnnotations; | ||
|
||
namespace BlazorApp.Models; | ||
|
||
public class SearchModel | ||
{ | ||
[Required] | ||
public string SearchTerm { get; set; } | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
57 changes: 57 additions & 0 deletions
57
OwnProjects/46_BlazorServerCourse/DataAccessDemo/BlazorApp/Pages/Search.razor
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
@page "/search" | ||
@inject IPersonDataService personData | ||
|
||
<h3>Search Page</h3> | ||
<EditForm Model="@search" OnValidSubmit="HandleValidSubmit"> | ||
<DataAnnotationsValidator /> | ||
<ValidationSummary /> | ||
|
||
<div class="form-group"> | ||
<label>Search</label> | ||
<InputText @bind-Value="search.SearchTerm"/> | ||
</div> | ||
<button class="btn btn-outline-primary" type="submit"> Go</button> | ||
</EditForm> | ||
|
||
@if (people is null) | ||
{ | ||
<h2>Loading...</h2> | ||
} | ||
else | ||
{ | ||
<div class="row"> | ||
<div class="col-md-8"> | ||
<table class="table table-striped"> | ||
<thead class="table-dark"> | ||
<tr> | ||
<th>Id</th> | ||
<th>First Name</th> | ||
<th>Last Name</th> | ||
<th>Date Of Birth</th> | ||
</tr> | ||
</thead> | ||
<tbody> | ||
@foreach (var p in people) | ||
{ | ||
<tr> | ||
<td>@p.Id</td> | ||
<td>@p.FirstName</td> | ||
<td>@p.LastName</td> | ||
<td>@p.DateOfBirth</td> | ||
</tr> | ||
} | ||
</tbody> | ||
</table> | ||
</div> | ||
</div> | ||
} | ||
|
||
@code { | ||
private SearchModel search = new SearchModel(); | ||
private List<IPersonModel> people; | ||
|
||
private async Task HandleValidSubmit() | ||
{ | ||
people = await personData.SearchPeople(search.SearchTerm); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
70 changes: 70 additions & 0 deletions
70
...ojects/46_BlazorServerCourse/DataAccessDemo/SupportLibrary/Data/PersonDummyDataService.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
using SupportLibrary.Models; | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Security; | ||
using System.Text; | ||
using System.Threading.Tasks; | ||
|
||
namespace SupportLibrary.Data | ||
{ | ||
public class PersonDummyDataService : IPersonDataService | ||
{ | ||
private List<IPersonModel> people = new List<IPersonModel>(); | ||
private int currentId = 0; | ||
|
||
public Task CreatePerson(IPersonModel person) | ||
{ | ||
return Task.Run(() => | ||
{ | ||
currentId += 1; | ||
person.Id = currentId; | ||
people.Add(person); | ||
}); | ||
} | ||
|
||
public void CreatePersonD(IPersonModel person) | ||
{ | ||
currentId += 1; | ||
person.Id = currentId; | ||
people.Add(person); | ||
} | ||
|
||
public Task DeletePerson(int id) | ||
{ | ||
return Task.Run(() => | ||
{ | ||
people.Remove(people.Where(p => p.Id == id).FirstOrDefault()); | ||
}); | ||
} | ||
|
||
public Task<List<IPersonModel>> ReadPeople() | ||
{ | ||
return Task.FromResult(people); | ||
} | ||
|
||
public Task<IPersonModel> ReadPeople(int id) | ||
{ | ||
return Task.FromResult(people.Where(p => p.Id == id).FirstOrDefault()); | ||
} | ||
|
||
public Task<List<IPersonModel>> SearchPeople(string searchTerm) | ||
{ | ||
return Task.FromResult(people.Where(x => x.FirstName.Contains(searchTerm) || x.LastName.Contains(searchTerm)).ToList()); | ||
} | ||
|
||
public Task UpdatePerson(IPersonModel person) | ||
{ | ||
return Task.Run(() => | ||
{ | ||
var p = people.Where(p => p.Id == person.Id).FirstOrDefault(); | ||
if (p != null) | ||
{ | ||
p.FirstName = person.FirstName; | ||
p.LastName = person.LastName; | ||
p.DateOfBirth = person.DateOfBirth; | ||
} | ||
}); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
12 changes: 12 additions & 0 deletions
12
OwnProjects/46_BlazorServerCourse/DemoAppSection09/BlazorApp/App.razor
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
<Router AppAssembly="@typeof(App).Assembly"> | ||
<Found Context="routeData"> | ||
<RouteView RouteData="@routeData" DefaultLayout="@typeof(MainLayout)" /> | ||
<FocusOnNavigate RouteData="@routeData" Selector="h1" /> | ||
</Found> | ||
<NotFound> | ||
<PageTitle>Not found</PageTitle> | ||
<LayoutView Layout="@typeof(MainLayout)"> | ||
<p role="alert">Sorry, there's nothing at this address.</p> | ||
</LayoutView> | ||
</NotFound> | ||
</Router> |
9 changes: 9 additions & 0 deletions
9
OwnProjects/46_BlazorServerCourse/DemoAppSection09/BlazorApp/BlazorApp.csproj
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
<Project Sdk="Microsoft.NET.Sdk.Web"> | ||
|
||
<PropertyGroup> | ||
<TargetFramework>net7.0</TargetFramework> | ||
<Nullable>enable</Nullable> | ||
<ImplicitUsings>enable</ImplicitUsings> | ||
</PropertyGroup> | ||
|
||
</Project> |
13 changes: 13 additions & 0 deletions
13
OwnProjects/46_BlazorServerCourse/DemoAppSection09/BlazorApp/Data/WeatherForecast.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
namespace BlazorApp.Data | ||
{ | ||
public class WeatherForecast | ||
{ | ||
public DateOnly Date { get; set; } | ||
|
||
public int TemperatureC { get; set; } | ||
|
||
public int TemperatureF => 32 + (int)(TemperatureC / 0.5556); | ||
|
||
public string? Summary { get; set; } | ||
} | ||
} |
20 changes: 20 additions & 0 deletions
20
OwnProjects/46_BlazorServerCourse/DemoAppSection09/BlazorApp/Data/WeatherForecastService.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
namespace BlazorApp.Data | ||
{ | ||
public class WeatherForecastService | ||
{ | ||
private static readonly string[] Summaries = new[] | ||
{ | ||
"Freezing", "Bracing", "Chilly", "Cool", "Mild", "Warm", "Balmy", "Hot", "Sweltering", "Scorching" | ||
}; | ||
|
||
public Task<WeatherForecast[]> GetForecastAsync(DateOnly startDate) | ||
{ | ||
return Task.FromResult(Enumerable.Range(1, 5).Select(index => new WeatherForecast | ||
{ | ||
Date = startDate.AddDays(index), | ||
TemperatureC = Random.Shared.Next(-20, 55), | ||
Summary = Summaries[Random.Shared.Next(Summaries.Length)] | ||
}).ToArray()); | ||
} | ||
} | ||
} |
7 changes: 7 additions & 0 deletions
7
OwnProjects/46_BlazorServerCourse/DemoAppSection09/BlazorApp/Models/GuessModel.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
namespace BlazorApp.Models; | ||
|
||
public class GuessModel | ||
{ | ||
public string Name { get; set; } | ||
public int DeploymentAttemps { get; set; } | ||
} |
18 changes: 18 additions & 0 deletions
18
OwnProjects/46_BlazorServerCourse/DemoAppSection09/BlazorApp/Pages/Counter.razor
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
@page "/counter" | ||
|
||
<PageTitle>Counter</PageTitle> | ||
|
||
<h1>Counter</h1> | ||
|
||
<p role="status">Current count: @currentCount</p> | ||
|
||
<button class="btn btn-primary" @onclick="IncrementCount">Click me</button> | ||
|
||
@code { | ||
private int currentCount = 0; | ||
|
||
private void IncrementCount() | ||
{ | ||
currentCount++; | ||
} | ||
} |
19 changes: 19 additions & 0 deletions
19
OwnProjects/46_BlazorServerCourse/DemoAppSection09/BlazorApp/Pages/Demo.razor
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
@using BlazorApp.Models | ||
<h3>Demo</h3> | ||
|
||
<EditForm Model="@guest" OnInvalidSubmit="HandleValidSubmit" > | ||
<InputText @bind-Value="guest.Name"/> | ||
<InputText @bind-Value="guest.DeploymentAttemps" /> | ||
<button class="btn btn-primary" type="submit">Submit</button> | ||
</EditForm> | ||
|
||
|
||
|
||
@code { | ||
private GuessModel guest = new(); | ||
|
||
private void HandleValidSubmit() | ||
{ | ||
|
||
} | ||
} |
Oops, something went wrong.