Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
s8_ivanov_r
VPL-pizza-shop-blazor
Commits
072e32b3
Commit
072e32b3
authored
Jan 27, 2019
by
Ryan Nowak
Browse files
Code dump of starter for step 5
parent
314998d3
Changes
74
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
20 changed files
with
497 additions
and
0 deletions
+497
-0
save-points/05-add-authentication/BlazingPizza.Client/App.cshtml
...ints/05-add-authentication/BlazingPizza.Client/App.cshtml
+2
-0
save-points/05-add-authentication/BlazingPizza.Client/BlazingPizza.Client.csproj
...entication/BlazingPizza.Client/BlazingPizza.Client.csproj
+19
-0
save-points/05-add-authentication/BlazingPizza.Client/OrderState.cs
...s/05-add-authentication/BlazingPizza.Client/OrderState.cs
+78
-0
save-points/05-add-authentication/BlazingPizza.Client/Pages/Index.cshtml
...add-authentication/BlazingPizza.Client/Pages/Index.cshtml
+78
-0
save-points/05-add-authentication/BlazingPizza.Client/Pages/MyOrders.cshtml
...-authentication/BlazingPizza.Client/Pages/MyOrders.cshtml
+48
-0
save-points/05-add-authentication/BlazingPizza.Client/Pages/OrderDetails.cshtml
...hentication/BlazingPizza.Client/Pages/OrderDetails.cshtml
+102
-0
save-points/05-add-authentication/BlazingPizza.Client/Pages/_ViewImports.cshtml
...hentication/BlazingPizza.Client/Pages/_ViewImports.cshtml
+1
-0
save-points/05-add-authentication/BlazingPizza.Client/Program.cs
...ints/05-add-authentication/BlazingPizza.Client/Program.cs
+16
-0
save-points/05-add-authentication/BlazingPizza.Client/Shared/ConfigurePizzaDialog.cshtml
...on/BlazingPizza.Client/Shared/ConfigurePizzaDialog.cshtml
+80
-0
save-points/05-add-authentication/BlazingPizza.Client/Shared/ConfiguredPizzaItem.cshtml
...ion/BlazingPizza.Client/Shared/ConfiguredPizzaItem.cshtml
+18
-0
save-points/05-add-authentication/BlazingPizza.Client/Shared/MainLayout.cshtml
...thentication/BlazingPizza.Client/Shared/MainLayout.cshtml
+20
-0
save-points/05-add-authentication/BlazingPizza.Client/Startup.cs
...ints/05-add-authentication/BlazingPizza.Client/Startup.cs
+18
-0
save-points/05-add-authentication/BlazingPizza.Client/_ViewImports.cshtml
...dd-authentication/BlazingPizza.Client/_ViewImports.cshtml
+9
-0
save-points/05-add-authentication/BlazingPizza.Client/wwwroot/css/bootstrap/bootstrap.min.css
...azingPizza.Client/wwwroot/css/bootstrap/bootstrap.min.css
+7
-0
save-points/05-add-authentication/BlazingPizza.Client/wwwroot/css/bootstrap/bootstrap.min.css.map
...gPizza.Client/wwwroot/css/bootstrap/bootstrap.min.css.map
+1
-0
save-points/05-add-authentication/BlazingPizza.Client/wwwroot/css/font/quicksand-v8-latin-300.woff
...Pizza.Client/wwwroot/css/font/quicksand-v8-latin-300.woff
+0
-0
save-points/05-add-authentication/BlazingPizza.Client/wwwroot/css/font/quicksand-v8-latin-300.woff2
...izza.Client/wwwroot/css/font/quicksand-v8-latin-300.woff2
+0
-0
save-points/05-add-authentication/BlazingPizza.Client/wwwroot/css/font/quicksand-v8-latin-500.woff
...Pizza.Client/wwwroot/css/font/quicksand-v8-latin-500.woff
+0
-0
save-points/05-add-authentication/BlazingPizza.Client/wwwroot/css/font/quicksand-v8-latin-500.woff2
...izza.Client/wwwroot/css/font/quicksand-v8-latin-500.woff2
+0
-0
save-points/05-add-authentication/BlazingPizza.Client/wwwroot/css/font/quicksand-v8-latin-700.woff
...Pizza.Client/wwwroot/css/font/quicksand-v8-latin-700.woff
+0
-0
No files found.
save-points/05-add-authentication/BlazingPizza.Client/App.cshtml
0 → 100644
View file @
072e32b3
<Router
AppAssembly=
typeof(Program).Assembly
/>
save-points/05-add-authentication/BlazingPizza.Client/BlazingPizza.Client.csproj
0 → 100644
View file @
072e32b3
<Project Sdk="Microsoft.NET.Sdk.Web">
<PropertyGroup>
<TargetFramework>netstandard2.0</TargetFramework>
<OutputType>Exe</OutputType>
<LangVersion>7.3</LangVersion>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Microsoft.AspNetCore.Blazor.Browser" Version="0.7.0" />
<PackageReference Include="Microsoft.AspNetCore.Blazor.Build" Version="0.7.0" PrivateAssets="all" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\BlazingPizza.ComponentsLibrary\BlazingPizza.ComponentsLibrary.csproj" />
<ProjectReference Include="..\BlazingPizza.Shared\BlazingPizza.Shared.csproj" />
</ItemGroup>
</Project>
save-points/05-add-authentication/BlazingPizza.Client/OrderState.cs
0 → 100644
View file @
072e32b3
using
System
;
using
System.Collections.Generic
;
using
System.Threading.Tasks
;
namespace
BlazingPizza.Client
{
public
class
OrderState
{
public
event
EventHandler
StateChanged
;
public
bool
ShowingConfigureDialog
{
get
;
private
set
;
}
public
Pizza
ConfiguringPizza
{
get
;
private
set
;
}
public
Order
Order
{
get
;
private
set
;
}
=
new
Order
();
public
void
ShowConfigurePizzaDialog
(
PizzaSpecial
special
)
{
ConfiguringPizza
=
new
Pizza
()
{
Special
=
special
,
SpecialId
=
special
.
Id
,
Size
=
Pizza
.
DefaultSize
,
Toppings
=
new
List
<
PizzaTopping
>(),
};
ShowingConfigureDialog
=
true
;
}
public
void
CancelConfigurePizzaDialog
()
{
ConfiguringPizza
=
null
;
ShowingConfigureDialog
=
false
;
StateHasChanged
();
}
public
void
ConfirmConfigurePizzaDialog
()
{
Order
.
Pizzas
.
Add
(
ConfiguringPizza
);
ConfiguringPizza
=
null
;
ShowingConfigureDialog
=
false
;
StateHasChanged
();
}
public
void
AddTopping
(
Topping
topping
)
{
if
(
ConfiguringPizza
.
Toppings
.
Find
(
pt
=>
pt
.
Topping
==
topping
)
==
null
)
{
ConfiguringPizza
.
Toppings
.
Add
(
new
PizzaTopping
()
{
Topping
=
topping
});
}
StateHasChanged
();
}
public
void
RemoveTopping
(
Topping
topping
)
{
ConfiguringPizza
.
Toppings
.
RemoveAll
(
pt
=>
pt
.
Topping
==
topping
);
StateHasChanged
();
}
public
void
RemoveConfiguredPizza
(
Pizza
pizza
)
{
Order
.
Pizzas
.
Remove
(
pizza
);
StateHasChanged
();
}
public
void
ResetOrder
()
{
Order
=
new
Order
();
}
private
void
StateHasChanged
()
{
StateChanged
?.
Invoke
(
this
,
EventArgs
.
Empty
);
}
}
}
save-points/05-add-authentication/BlazingPizza.Client/Pages/Index.cshtml
0 → 100644
View file @
072e32b3
@page "/"
@inject HttpClient HttpClient
@inject OrderState OrderState
@inject IUriHelper UriHelper
@implements IDisposable
<div
class=
"main"
>
<ul
class=
"pizza-cards"
>
@if (specials != null)
{
@foreach (var special in specials)
{
<li
onclick=
"@(() => OrderState.ShowConfigurePizzaDialog(special))"
style=
"background-image: url('@special.ImageUrl')"
>
<div
class=
"pizza-info"
>
<span
class=
"title"
>
@special.Name
</span>
@special.Description
<span
class=
"price"
>
@special.GetFormattedBasePrice()
</span>
</div>
</li>
}
}
</ul>
</div>
<div
class=
"sidebar"
>
@if (OrderState.Order.Pizzas.Any())
{
<div
class=
"order-contents"
>
<h2>
Your order
</h2>
@foreach (var configuredPizza in OrderState.Order.Pizzas)
{
<ConfiguredPizzaItem
Pizza=
"configuredPizza"
OnRemoved=
"() => OrderState.RemoveConfiguredPizza(configuredPizza)"
/>
}
</div>
}
else
{
<div
class=
"empty-cart"
>
Choose a pizza
<br>
to get started
</div>
}
<div
class=
"order-total @(OrderState.Order.Pizzas.Any() ? "
"
:
"
hidden
")"
>
Total:
<span
class=
"total-price"
>
@OrderState.Order.GetFormattedTotalPrice()
</span>
<button
class=
"btn btn-warning"
disabled=
"@(OrderState.Order.Pizzas.Count == 0)"
onclick=
"@PlaceOrder"
>
Order >
</button>
</div>
</div>
@if (OrderState.ShowingConfigureDialog)
{
<ConfigurePizzaDialog
/>
}
@functions {
List
<PizzaSpecial>
specials;
protected async override Task OnInitAsync()
{
OrderState.StateChanged += OnOrderStateChanged;
specials = await HttpClient.GetJsonAsync
<List
<
PizzaSpecial
>
>("/specials");
}
void IDisposable.Dispose()
{
OrderState.StateChanged -= OnOrderStateChanged;
}
void OnOrderStateChanged(object sender, EventArgs e) => StateHasChanged();
async Task PlaceOrder()
{
await HttpClient.PostJsonAsync("/orders", OrderState.Order);
OrderState.ResetOrder();
UriHelper.NavigateTo("myorders");
}
}
save-points/05-add-authentication/BlazingPizza.Client/Pages/MyOrders.cshtml
0 → 100644
View file @
072e32b3
@page "/myorders"
@inject HttpClient HttpClient
<div
class=
"main"
>
@if (ordersWithStatus == null)
{
<text>
Loading...
</text>
}
else if (ordersWithStatus.Count == 0)
{
<h2>
No orders placed
</h2>
<a
class=
"btn btn-success"
href=
""
>
Order some pizza
</a>
}
else
{
<div
class=
"list-group orders-list"
>
@foreach (var item in ordersWithStatus)
{
<div
class=
"list-group-item"
>
<div
class=
"col"
>
<h5>
@item.Order.CreatedTime.ToLongDateString()
</h5>
Items:
<strong>
@item.Order.Pizzas.Count()
</strong>
;
Total price:
<strong>
£@item.Order.GetFormattedTotalPrice()
</strong>
</div>
<div
class=
"col"
>
Status:
<strong>
@item.StatusText
</strong>
</div>
<div
class=
"col flex-grow-0"
>
<a
href=
"myorders/@item.Order.OrderId"
class=
"btn btn-success"
>
Track
>
</a>
</div>
</div>
}
</div>
}
</div>
@functions {
List
<OrderWithStatus>
ordersWithStatus;
protected override async Task OnParametersSetAsync()
{
ordersWithStatus = await HttpClient.GetJsonAsync
<List
<
OrderWithStatus
>
>("/orders");
}
}
save-points/05-add-authentication/BlazingPizza.Client/Pages/OrderDetails.cshtml
0 → 100644
View file @
072e32b3
@page "/myorders/{orderId:int}"
@using System.Threading
@inject HttpClient HttpClient
@implements IDisposable
<div
class=
"main"
>
@if (invalidOrder)
{
<h2>
Nope
</h2>
<p>
Sorry, this order could not be loaded.
</p>
}
else if (orderWithStatus == null)
{
<text>
Loading...
</text>
}
else
{
<div
class=
"track-order"
>
<div
class=
"track-order-title"
>
<h2>
Order placed @orderWithStatus.Order.CreatedTime.ToLongDateString()
</h2>
<p
class=
"ml-auto mb-0"
>
Status:
<strong>
@orderWithStatus.StatusText
</strong>
</p>
</div>
<div
class=
"track-order-body"
>
<div
class=
"track-order-details"
>
@foreach (var pizza in orderWithStatus.Order.Pizzas)
{
<p>
<strong>
@(pizza.Size)"
@pizza.Special.Name
(£@pizza.GetFormattedTotalPrice())
</strong>
</p>
<ul>
@foreach (var topping in pizza.Toppings)
{
<li>
+ @topping.Topping.Name
</li>
}
</ul>
}
<p>
<strong>
Total price:
£@orderWithStatus.Order.GetFormattedTotalPrice()
</strong>
</p>
</div>
</div>
</div>
}
</div>
@functions {
[Parameter] int OrderId { get; set; }
OrderWithStatus orderWithStatus;
bool invalidOrder;
CancellationTokenSource pollingCancellationToken;
protected override void OnParametersSet()
{
// If we were already polling for a different order, stop doing so
pollingCancellationToken?.Cancel();
// Start a new poll loop
PollForUpdates();
}
void IDisposable.Dispose()
{
pollingCancellationToken?.Cancel();
}
private async void PollForUpdates()
{
pollingCancellationToken = new CancellationTokenSource();
while (!pollingCancellationToken.IsCancellationRequested)
{
try
{
invalidOrder = false;
orderWithStatus = await HttpClient.GetJsonAsync
<OrderWithStatus>
($"/orders/{OrderId}");
}
catch (Exception ex)
{
invalidOrder = true;
pollingCancellationToken.Cancel();
Console.Error.WriteLine(ex);
}
StateHasChanged();
await Task.Delay(4000);
}
}
}
save-points/05-add-authentication/BlazingPizza.Client/Pages/_ViewImports.cshtml
0 → 100644
View file @
072e32b3
@layout MainLayout
save-points/05-add-authentication/BlazingPizza.Client/Program.cs
0 → 100644
View file @
072e32b3
using
Microsoft.AspNetCore.Blazor.Hosting
;
namespace
BlazingPizza.Client
{
public
class
Program
{
public
static
void
Main
(
string
[]
args
)
{
CreateHostBuilder
(
args
).
Build
().
Run
();
}
public
static
IWebAssemblyHostBuilder
CreateHostBuilder
(
string
[]
args
)
=>
BlazorWebAssemblyHost
.
CreateDefaultBuilder
()
.
UseBlazorStartup
<
Startup
>();
}
}
save-points/05-add-authentication/BlazingPizza.Client/Shared/ConfigurePizzaDialog.cshtml
0 → 100644
View file @
072e32b3
@inject HttpClient HttpClient
@inject OrderState OrderState
<div
class=
"dialog-container"
>
<div
class=
"dialog"
>
<div
class=
"dialog-title"
>
<h2>
@Pizza.Special.Name
</h2>
@Pizza.Special.Description
</div>
<form
class=
"dialog-body"
>
<div>
<label>
Size:
</label>
<input
type=
"range"
min=
"@Pizza.MinimumSize"
max=
"@Pizza.MaximumSize"
step=
"1"
bind-value-oninput=
"Pizza.Size"
/>
<span
class=
"size-label"
>
@(Pizza.Size)" (£@(Pizza.GetFormattedTotalPrice()))
</span>
</div>
<div>
<label>
Extra Toppings:
</label>
@if (toppings == null)
{
<select
class=
"custom-select"
disabled
>
<option>
(loading...)
</option>
</select>
}
else if (Pizza.Toppings.Count >= 6)
{
<div>
(maximum reached)
</div>
}
else
{
<select
class=
"custom-select"
onchange=
"@ToppingSelected"
>
<option
value=
"-1"
disabled
selected
>
(select)
</option>
@for (var i = 0; i
<
toppings.Count
;
i
++)
{
<
option
value=
"@i"
>
@toppings[i].Name - (£@(toppings[i].GetFormattedPrice()))
</option>
}
</select>
}
</div>
<div
class=
"toppings"
>
@foreach (var topping in Pizza.Toppings)
{
<div
class=
"topping"
>
@topping.Topping.Name
<span
class=
"topping-price"
>
@topping.Topping.GetFormattedPrice()
</span>
<button
type=
"button"
class=
"delete-topping"
onclick=
"@(() => OrderState.RemoveTopping(topping.Topping))"
>
x
</button>
</div>
}
</div>
</form>
<div
class=
"dialog-buttons"
>
<button
class=
"btn btn-secondary mr-auto"
onclick=
"@OrderState.CancelConfigurePizzaDialog"
>
Cancel
</button>
<span
class=
"mr-center"
>
Price:
<span
class=
"price"
>
@(Pizza.GetFormattedTotalPrice())
</span>
</span>
<button
class=
"btn btn-success ml-auto"
onclick=
"@OrderState.ConfirmConfigurePizzaDialog"
>
Order >
</button>
</div>
</div>
</div>
@functions {
List
<Topping>
toppings { get; set; }
Pizza Pizza => OrderState.ConfiguringPizza;
protected async override Task OnInitAsync()
{
toppings = await HttpClient.GetJsonAsync
<List
<
Topping
>
>("/toppings");
}
void ToppingSelected(UIChangeEventArgs e)
{
if (int.TryParse((string)e.Value, out var index)
&&
index >= 0)
{
OrderState.AddTopping(toppings[index]);
}
}
}
save-points/05-add-authentication/BlazingPizza.Client/Shared/ConfiguredPizzaItem.cshtml
0 → 100644
View file @
072e32b3
<div
class=
"cart-item"
>
<a
onclick=
@OnRemoved
class=
"delete-item"
>
x
</a>
<div
class=
"title"
>
@(Pizza.Size)" @Pizza.Special.Name
</div>
<ul>
@foreach (var topping in Pizza.Toppings)
{
<li>
+ @topping.Topping.Name
</li>
}
</ul>
<div
class=
"item-price"
>
@Pizza.GetFormattedTotalPrice()
</div>
</div>
@functions {
[Parameter] Pizza Pizza { get; set; }
[Parameter] Action OnRemoved { get; set; }
}
\ No newline at end of file
save-points/05-add-authentication/BlazingPizza.Client/Shared/MainLayout.cshtml
0 → 100644
View file @
072e32b3
@inherits BlazorLayoutComponent
<div
class=
"top-bar"
>
<img
class=
"logo"
src=
"img/logo.svg"
/>
<NavLink
href=
""
class=
"nav-tab"
Match=
"NavLinkMatch.All"
>
<img
src=
"img/pizza-slice.svg"
/>
<div>
Get Pizza
</div>
</NavLink>
<NavLink
href=
"myorders"
class=
"nav-tab"
>
<img
src=
"img/bike.svg"
/>
<div>
My Orders
</div>
</NavLink>
</div>
<div
class=
"content"
>
@Body
</div>
save-points/05-add-authentication/BlazingPizza.Client/Startup.cs
0 → 100644
View file @
072e32b3
using
Microsoft.AspNetCore.Blazor.Builder
;
using
Microsoft.Extensions.DependencyInjection
;
namespace
BlazingPizza.Client
{
public
class
Startup
{
public
void
ConfigureServices
(
IServiceCollection
services
)
{
services
.
AddScoped
<
OrderState
>();
}
public
void
Configure
(
IBlazorApplicationBuilder
app
)
{
app
.
AddComponent
<
App
>(
"app"
);
}
}
}
save-points/05-add-authentication/BlazingPizza.Client/_ViewImports.cshtml
0 → 100644
View file @
072e32b3
@using System.Net.Http
@using Microsoft.AspNetCore.Blazor.Layouts
@using Microsoft.AspNetCore.Blazor.Routing
@using Microsoft.AspNetCore.Blazor.Services
@using Microsoft.JSInterop
@using BlazingPizza.Client
@using BlazingPizza.Client.Shared
@using BlazingPizza.ComponentsLibrary.Authentication
@addTagHelper "*, BlazingPizza.ComponentsLibrary"
save-points/05-add-authentication/BlazingPizza.Client/wwwroot/css/bootstrap/bootstrap.min.css
0 → 100644
View file @
072e32b3
This diff is collapsed.
Click to expand it.
save-points/05-add-authentication/BlazingPizza.Client/wwwroot/css/bootstrap/bootstrap.min.css.map
0 → 100644
View file @
072e32b3
This diff is collapsed.
Click to expand it.
save-points/05-add-authentication/BlazingPizza.Client/wwwroot/css/font/quicksand-v8-latin-300.woff
0 → 100644
View file @
072e32b3
File added
save-points/05-add-authentication/BlazingPizza.Client/wwwroot/css/font/quicksand-v8-latin-300.woff2
0 → 100644
View file @
072e32b3
File added
save-points/05-add-authentication/BlazingPizza.Client/wwwroot/css/font/quicksand-v8-latin-500.woff
0 → 100644
View file @
072e32b3
File added
save-points/05-add-authentication/BlazingPizza.Client/wwwroot/css/font/quicksand-v8-latin-500.woff2
0 → 100644
View file @
072e32b3
File added
save-points/05-add-authentication/BlazingPizza.Client/wwwroot/css/font/quicksand-v8-latin-700.woff
0 → 100644
View file @
072e32b3
File added
Prev
1
2
3
4
Next
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment