Skip to content

Commit

Permalink
Module 2
Browse files Browse the repository at this point in the history
  • Loading branch information
gavilanch committed Oct 24, 2019
0 parents commit 6424c07
Show file tree
Hide file tree
Showing 36 changed files with 1,885 additions and 0 deletions.
436 changes: 436 additions & 0 deletions .gitignore

Large diffs are not rendered by default.

37 changes: 37 additions & 0 deletions Module2/BlazorMovies.sln
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio Version 16
VisualStudioVersion = 16.0.29411.138
MinimumVisualStudioVersion = 10.0.40219.1
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "BlazorMovies.Server", "BlazorMovies\Server\BlazorMovies.Server.csproj", "{F062FE80-2058-4B93-951D-4AB7DBD2433A}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "BlazorMovies.Client", "BlazorMovies\Client\BlazorMovies.Client.csproj", "{3D88005C-4782-4D96-9455-B8E1058E979F}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "BlazorMovies.Shared", "BlazorMovies\Shared\BlazorMovies.Shared.csproj", "{059D92BC-D342-4024-B56D-B277F96C399B}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Release|Any CPU = Release|Any CPU
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{F062FE80-2058-4B93-951D-4AB7DBD2433A}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{F062FE80-2058-4B93-951D-4AB7DBD2433A}.Debug|Any CPU.Build.0 = Debug|Any CPU
{F062FE80-2058-4B93-951D-4AB7DBD2433A}.Release|Any CPU.ActiveCfg = Release|Any CPU
{F062FE80-2058-4B93-951D-4AB7DBD2433A}.Release|Any CPU.Build.0 = Release|Any CPU
{3D88005C-4782-4D96-9455-B8E1058E979F}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{3D88005C-4782-4D96-9455-B8E1058E979F}.Debug|Any CPU.Build.0 = Debug|Any CPU
{3D88005C-4782-4D96-9455-B8E1058E979F}.Release|Any CPU.ActiveCfg = Release|Any CPU
{3D88005C-4782-4D96-9455-B8E1058E979F}.Release|Any CPU.Build.0 = Release|Any CPU
{059D92BC-D342-4024-B56D-B277F96C399B}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{059D92BC-D342-4024-B56D-B277F96C399B}.Debug|Any CPU.Build.0 = Debug|Any CPU
{059D92BC-D342-4024-B56D-B277F96C399B}.Release|Any CPU.ActiveCfg = Release|Any CPU
{059D92BC-D342-4024-B56D-B277F96C399B}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {C02675A3-D4AD-4C32-B1DC-4218255FD823}
EndGlobalSection
EndGlobal
10 changes: 10 additions & 0 deletions Module2/BlazorMovies/Client/App.razor
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<Router AppAssembly="@typeof(Program).Assembly">
<Found Context="routeData">
<RouteView RouteData="@routeData" DefaultLayout="@typeof(MainLayout)" />
</Found>
<NotFound>
<LayoutView Layout="@typeof(MainLayout)">
<p>Sorry, there's nothing at this address.</p>
</LayoutView>
</NotFound>
</Router>
18 changes: 18 additions & 0 deletions Module2/BlazorMovies/Client/BlazorMovies.Client.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
<Project Sdk="Microsoft.NET.Sdk.Web">

<PropertyGroup>
<TargetFramework>netstandard2.0</TargetFramework>
<RazorLangVersion>3.0</RazorLangVersion>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Microsoft.AspNetCore.Blazor" Version="3.1.0-preview1.19508.20" />
<PackageReference Include="Microsoft.AspNetCore.Blazor.Build" Version="3.1.0-preview1.19508.20" PrivateAssets="all" />
<PackageReference Include="Microsoft.AspNetCore.Blazor.HttpClient" Version="3.1.0-preview1.19508.20" />
<PackageReference Include="Microsoft.AspNetCore.Blazor.DevServer" Version="3.1.0-preview1.19508.20" PrivateAssets="all" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\Shared\BlazorMovies.Shared.csproj" />
</ItemGroup>

</Project>
12 changes: 12 additions & 0 deletions Module2/BlazorMovies/Client/Helpers/StringUtilities.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;

namespace BlazorMovies.Client.Helpers
{
public class StringUtilities
{
public static string CustomToUpper(string value) => value.ToUpper();
}
}
16 changes: 16 additions & 0 deletions Module2/BlazorMovies/Client/Pages/Counter.razor
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
@page "/counter"

<h1>Counter</h1>

<p>Current count: @currentCount</p>

<button class="btn btn-primary" @onclick="IncrementCount">Click me</button>

@code {
private int currentCount = 0;

private void IncrementCount()
{
currentCount++;
}
}
46 changes: 46 additions & 0 deletions Module2/BlazorMovies/Client/Pages/FetchData.razor
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
@page "/fetchdata"
@using BlazorMovies.Shared
@inject HttpClient Http

<h1>Weather forecast</h1>

<p>This component demonstrates fetching data from the server.</p>

@if (forecasts == null)
{
<p><em>Loading...</em></p>
}
else
{
<table class="table">
<thead>
<tr>
<th>Date</th>
<th>Temp. (C)</th>
<th>Temp. (F)</th>
<th>Summary</th>
</tr>
</thead>
<tbody>
@foreach (var forecast in forecasts)
{
<tr>
<td>@forecast.Date.ToShortDateString()</td>
<td>@forecast.TemperatureC</td>
<td>@forecast.TemperatureF</td>
<td>@forecast.Summary</td>
</tr>
}
</tbody>
</table>
}

@code {
private WeatherForecast[] forecasts;

protected override async Task OnInitializedAsync()
{
forecasts = await Http.GetJsonAsync<WeatherForecast[]>("WeatherForecast");
}

}
59 changes: 59 additions & 0 deletions Module2/BlazorMovies/Client/Pages/Index.razor
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
@page "/"

<p>Hello, @StringUtilities.CustomToUpper(name)</p>

<p>Let's add 2 + 2 = @(2 + 2)</p>

<button @onclick="@WriteInLog">Click me</button>

<div>
<h3>Movie</h3>
@if (movies == null)
{
<text>Loading...</text>
}
else
{
@foreach (var movie in movies)
{
<p>Title: @((MarkupString)movie.Title)</p>
<p>Release Date: <b>@movie.ReleaseDate.ToString("dd MMM yyyy")</b></p>
}

@for (var i = 0; i < movies.Count; i++)
{
<div style="background-color: @(i % 2 == 0 ? "blue" : "red")">
<p>@(i + 1)) Title: <b>@movies[i].Title</b></p>
<p>Release Date: <b>@movies[i].ReleaseDate.ToString("dd MMM yyyy")</b></p>
</div>
}
}
</div>

@code{
string name = "Julia";

List<Movie> movies;

protected async override Task OnInitializedAsync()
{
await Task.Delay(3000);
movies = new List<Movie>()
{
new Movie(){Title = "<b>Spider-Man: Far From Home</b>", ReleaseDate = new DateTime(2019, 7, 2)},
new Movie(){Title = "<i>Moana</i>", ReleaseDate = new DateTime(2016, 11, 23)},
new Movie(){Title = "Inception", ReleaseDate = new DateTime(2010, 7, 16)}
};
}

Movie spiderman = new Movie()
{
Title = "Spider-Man: Far From Home",
ReleaseDate = new DateTime(2019, 7, 2)
};

void WriteInLog()
{
Console.WriteLine("I've been clicked! (from method)");
}
}
16 changes: 16 additions & 0 deletions Module2/BlazorMovies/Client/Program.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
using Microsoft.AspNetCore.Blazor.Hosting;

namespace BlazorMovies.Client
{
public class Program
{
public static void Main(string[] args)
{
CreateHostBuilder(args).Build().Run();
}

public static IWebAssemblyHostBuilder CreateHostBuilder(string[] args) =>
BlazorWebAssemblyHost.CreateDefaultBuilder()
.UseBlazorStartup<Startup>();
}
}
27 changes: 27 additions & 0 deletions Module2/BlazorMovies/Client/Properties/launchSettings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
{
"iisSettings": {
"windowsAuthentication": false,
"anonymousAuthentication": true,
"iisExpress": {
"applicationUrl": "http://localhost:50272/",
"sslPort": 0
}
},
"profiles": {
"IIS Express": {
"commandName": "IISExpress",
"launchBrowser": true,
"environmentVariables": {
"ASPNETCORE_ENVIRONMENT": "Development"
}
},
"BlazorMovies.Client": {
"commandName": "Project",
"launchBrowser": true,
"environmentVariables": {
"ASPNETCORE_ENVIRONMENT": "Development"
},
"applicationUrl": "http://localhost:50273/"
}
}
}
15 changes: 15 additions & 0 deletions Module2/BlazorMovies/Client/Shared/MainLayout.razor
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
@inherits LayoutComponentBase

<div class="sidebar">
<NavMenu />
</div>

<div class="main">
<div class="top-row px-4">
<a href="http://blazor.net" target="_blank" class="ml-md-auto">About</a>
</div>

<div class="content px-4">
@Body
</div>
</div>
37 changes: 37 additions & 0 deletions Module2/BlazorMovies/Client/Shared/NavMenu.razor
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
<div class="top-row pl-4 navbar navbar-dark">
<a class="navbar-brand" href="">BlazorMovies</a>
<button class="navbar-toggler" @onclick="ToggleNavMenu">
<span class="navbar-toggler-icon"></span>
</button>
</div>

<div class="@NavMenuCssClass" @onclick="ToggleNavMenu">
<ul class="nav flex-column">
<li class="nav-item px-3">
<NavLink class="nav-link" href="" Match="NavLinkMatch.All">
<span class="oi oi-home" aria-hidden="true"></span> Home
</NavLink>
</li>
<li class="nav-item px-3">
<NavLink class="nav-link" href="counter">
<span class="oi oi-plus" aria-hidden="true"></span> Counter
</NavLink>
</li>
<li class="nav-item px-3">
<NavLink class="nav-link" href="fetchdata">
<span class="oi oi-list-rich" aria-hidden="true"></span> Fetch data
</NavLink>
</li>
</ul>
</div>

@code {
private bool collapseNavMenu = true;

private string NavMenuCssClass => collapseNavMenu ? "collapse" : null;

private void ToggleNavMenu()
{
collapseNavMenu = !collapseNavMenu;
}
}
16 changes: 16 additions & 0 deletions Module2/BlazorMovies/Client/Shared/SurveyPrompt.razor
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<div class="alert alert-secondary mt-4" role="alert">
<span class="oi oi-pencil mr-2" aria-hidden="true"></span>
<strong>@Title</strong>

<span class="text-nowrap">
Please take our
<a target="_blank" class="font-weight-bold" href="https://go.microsoft.com/fwlink/?linkid=2100553">brief survey</a>
</span>
and tell us what you think.
</div>

@code {
// Demonstrates how a parent component can supply parameters
[Parameter]
public string Title { get; set; }
}
17 changes: 17 additions & 0 deletions Module2/BlazorMovies/Client/Startup.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
using Microsoft.AspNetCore.Components.Builder;
using Microsoft.Extensions.DependencyInjection;

namespace BlazorMovies.Client
{
public class Startup
{
public void ConfigureServices(IServiceCollection services)
{
}

public void Configure(IComponentsApplicationBuilder app)
{
app.AddComponent<App>("app");
}
}
}
9 changes: 9 additions & 0 deletions Module2/BlazorMovies/Client/_Imports.razor
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
@using System.Net.Http
@using Microsoft.AspNetCore.Components.Forms
@using Microsoft.AspNetCore.Components.Routing
@using Microsoft.AspNetCore.Components.Web
@using Microsoft.JSInterop
@using BlazorMovies.Client
@using BlazorMovies.Client.Shared
@using BlazorMovies.Client.Helpers
@using BlazorMovies.Shared.Entities

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Loading

0 comments on commit 6424c07

Please sign in to comment.