Revert "Added shopping cart example"

This reverts commit fcc9084c4f.
This commit is contained in:
Jon Hilton 2020-07-13 21:13:02 +01:00
parent fcc9084c4f
commit 3d6d075dd9
10 changed files with 3 additions and 193 deletions

17
.vscode/launch.json vendored
View file

@ -1,17 +0,0 @@
{
// Use IntelliSense to find out which attributes exist for C# debugging
// Use hover for the description of the existing attributes
// For further information visit https://github.com/OmniSharp/omnisharp-vscode/blob/master/debugger-launchjson.md
"version": "0.2.0",
"configurations": [
{
"name": "Launch and Debug Hosted Blazor WebAssembly App",
"type": "blazorwasm",
"request": "launch",
"hosted": true,
// If you have changed target frameworks, make sure to update the program path.
"program": "${workspaceFolder}/Server/bin/Debug/netcoreapp3.1/ShoppingCartStarter.Server.dll",
"cwd": "${workspaceFolder}/Server"
}
]
}

42
.vscode/tasks.json vendored
View file

@ -1,42 +0,0 @@
{
"version": "2.0.0",
"tasks": [
{
"label": "build",
"command": "dotnet",
"type": "process",
"args": [
"build",
"${workspaceFolder}/Server/ShoppingCartStarter.Server.csproj",
"/property:GenerateFullPaths=true",
"/consoleloggerparameters:NoSummary"
],
"problemMatcher": "$msCompile"
},
{
"label": "publish",
"command": "dotnet",
"type": "process",
"args": [
"publish",
"${workspaceFolder}/Server/ShoppingCartStarter.Server.csproj",
"/property:GenerateFullPaths=true",
"/consoleloggerparameters:NoSummary"
],
"problemMatcher": "$msCompile"
},
{
"label": "watch",
"command": "dotnet",
"type": "process",
"args": [
"watch",
"run",
"${workspaceFolder}/Server/ShoppingCartStarter.Server.csproj",
"/property:GenerateFullPaths=true",
"/consoleloggerparameters:NoSummary"
],
"problemMatcher": "$msCompile"
}
]
}

View file

@ -1,11 +0,0 @@
@inherits CartBase
@page "/cart"
<h3>Your Shopping Cart</h3>
@if(Model != null){
@foreach (var line in Model.Items)
{
<Item details="@line" OnDeleted="ReloadCart" OnQuantityChanged="ReloadCart"/>
}
}

View file

@ -1,30 +0,0 @@
using System.Net.Http;
using System.Net.Http.Json;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Components;
using ShoppingCartStarter.Shared.Cart;
namespace ShoppingCartStarter.Client.Pages.Cart
{
public class CartBase : ComponentBase
{
[Inject] private HttpClient Http { get; set; }
protected Details.Model Model { get; set; }
protected override async Task OnInitializedAsync()
{
await ReloadCart();
}
protected void RemoveItem(Details.Model.LineItem item)
{
Model.Items.Remove(item);
}
protected async Task ReloadCart()
{
Model = await Http.GetFromJsonAsync<Details.Model>("api/cart");
}
}
}

View file

@ -1,20 +0,0 @@
@inherits ItemBase
<div class="row border-bottom py-4">
<div class="col-sm">
<div class="media">
<img src="/images/@Details.Image" altText="@Details.Name" class="mr-3" />
<div class="media-body">
<h3>@Details.Name</h3>
<div class="form-inline">
<label for="qty" class="mr-2">Qty</label>
<Quantity Value="Details.Quantity" ValueChanged="QuantityChanged" />
<button class="btn btn-danger" @onclick="OnDeleteClicked">Delete</button>
</div>
</div>
</div>
</div>
<div class="col-sm-2">
£@Details.Price
</div>
</div>

View file

@ -1,42 +0,0 @@
using Microsoft.AspNetCore.Components;
using ShoppingCartStarter.Shared.Cart;
using ShoppingCartStarter.Shared.Cart.LineItem;
using System;
using System.Net.Http;
using System.Net.Http.Json;
using System.Threading.Tasks;
namespace ShoppingCartStarter.Client.Pages.Cart
{
public class ItemBase : ComponentBase
{
[Parameter]
public Details.Model.LineItem Details { get; set; }
[Inject]
public HttpClient Http { get; set; }
[Parameter]
public EventCallback<Details.Model.LineItem> OnDeleted { get; set; }
[Parameter]
public EventCallback OnQuantityChanged { get; set; }
protected async Task OnDeleteClicked()
{
await Http.DeleteAsync($"api/cart/lines/{Details.Id}");
await OnDeleted.InvokeAsync(Details);
}
protected async Task QuantityChanged(int value)
{
await Http.PutAsJsonAsync("api/cart/lines", new Update.Command
{
Id = Details.Id,
Quantity = value
});
await OnQuantityChanged.InvokeAsync(EventArgs.Empty);
}
}
}

View file

@ -1,9 +0,0 @@
@inherits QuantityBase
<select class="form-control mr-2" id="qty" value="@Value" @onchange="OnChange">
<option value="1">1</option>
<option value="2">2</option>
<option value="3">3</option>
<option value="4">4</option>
<option value="5">5</option>
</select>

View file

@ -1,19 +0,0 @@
using Microsoft.AspNetCore.Components;
using System;
using System.Threading.Tasks;
namespace ShoppingCartStarter.Client.Pages.Cart
{
public class QuantityBase : ComponentBase
{
[Parameter] public EventCallback<int> ValueChanged { get; set; }
[Parameter] public int Value { get; set; }
protected Task OnChange(ChangeEventArgs e)
{
Value = Convert.ToInt32(e.Value);
return ValueChanged.InvokeAsync(Value);
}
}
}

View file

@ -17,14 +17,14 @@ namespace ShoppingCartStarter.Server.Data
{
using var serviceScope = app.ApplicationServices.GetService<IServiceScopeFactory>().CreateScope();
using var context = serviceScope.ServiceProvider.GetRequiredService<StoreContext>();
context.Database.Migrate();
ShoppingCart cart;
if (context.Carts.Any())
{
cart = context.Carts
.Include(x => x.LineItems)
.Include(x=>x.LineItems)
.FirstOrDefault();
}
else

View file

@ -20,7 +20,7 @@
"commandName": "Project",
"launchBrowser": true,
"inspectUri": "{wsProtocol}://{url.hostname}:{url.port}/_framework/debug/ws-proxy?browser={browserInspectUri}",
"applicationUrl": "https://localhost:5004;http://localhost:5005",
"applicationUrl": "https://localhost:5001;http://localhost:5000",
"environmentVariables": {
"ASPNETCORE_ENVIRONMENT": "Development"
}