diff --git a/README.md b/README.md
index 60591b0..d10d35b 100644
--- a/README.md
+++ b/README.md
@@ -43,13 +43,14 @@ The goal for this sample is to demonstrate some of the principles and patterns d
## Running the sample
-After cloning or downloading the sample you should be able to run it using an In Memory database immediately. The store's home page should look like this:
+The store's home page should look like this:

Most of the site's functionality works with just the web application running. However, the site's Admin page relies on Blazor WebAssembly running in the browser, and it must communicate with the server using the site's PublicApi web application. You'll need to also run this project. You can configure Visual Studio to start multiple projects, or just go to the PublicApi folder in a terminal window and run `dotnet run` from there. After that from the Web folder you should run `dotnet run --launch-profile Web`. Now you should be able to browse to `https://localhost:5001/`. Note that if you use this approach, you'll need to stop the application manually in order to build the solution (otherwise you'll get file locking errors).
-If you wish to use the sample with a persistent database, you will need to run its Entity Framework Core migrations before you will be able to run the app, and update the `ConfigureServices` method in `Startup.cs` (see below).
+After cloning or downloading the sample you must setup your database.
+To use the sample with a persistent database, you will need to run its Entity Framework Core migrations before you will be able to run the app.
You can also run the samples in Docker (see below).
@@ -68,7 +69,7 @@ You can also run the samples in Docker (see below).
1. Ensure the tool EF was already installed. You can find some help [here](https://docs.microsoft.com/ef/core/miscellaneous/cli/dotnet)
```
- dotnet tool install --global dotnet-ef
+ dotnet tool update --global dotnet-ef
```
1. Open a command prompt in the Web folder and execute the following commands:
diff --git a/src/ApplicationCore/ApplicationCore.csproj b/src/ApplicationCore/ApplicationCore.csproj
index e5017fd..e42acd4 100644
--- a/src/ApplicationCore/ApplicationCore.csproj
+++ b/src/ApplicationCore/ApplicationCore.csproj
@@ -10,7 +10,7 @@
-
+
diff --git a/src/BlazorAdmin/BlazorAdmin.csproj b/src/BlazorAdmin/BlazorAdmin.csproj
index d30ffce..c982e86 100644
--- a/src/BlazorAdmin/BlazorAdmin.csproj
+++ b/src/BlazorAdmin/BlazorAdmin.csproj
@@ -7,11 +7,11 @@
-
-
-
-
-
+
+
+
+
+
diff --git a/src/Infrastructure/Infrastructure.csproj b/src/Infrastructure/Infrastructure.csproj
index 9499371..98d8082 100644
--- a/src/Infrastructure/Infrastructure.csproj
+++ b/src/Infrastructure/Infrastructure.csproj
@@ -7,9 +7,9 @@
-
-
-
+
+
+
diff --git a/src/PublicApi/PublicApi.csproj b/src/PublicApi/PublicApi.csproj
index f4e16b6..ab657ed 100644
--- a/src/PublicApi/PublicApi.csproj
+++ b/src/PublicApi/PublicApi.csproj
@@ -17,18 +17,18 @@
-
-
-
-
-
-
-
+
+
+
+
+
+
+
all
runtime; build; native; contentfiles; analyzers; buildtransitive
-
+
diff --git a/src/Web/.config/dotnet-tools.json b/src/Web/.config/dotnet-tools.json
index c735fef..5060fd6 100644
--- a/src/Web/.config/dotnet-tools.json
+++ b/src/Web/.config/dotnet-tools.json
@@ -3,7 +3,7 @@
"isRoot": true,
"tools": {
"dotnet-ef": {
- "version": "5.0.0",
+ "version": "6.0.4",
"commands": [
"dotnet-ef"
]
diff --git a/src/Web/Pages/Basket/BasketViewModel.cs b/src/Web/Pages/Basket/BasketViewModel.cs
index 7b76e40..07b1028 100644
--- a/src/Web/Pages/Basket/BasketViewModel.cs
+++ b/src/Web/Pages/Basket/BasketViewModel.cs
@@ -1,8 +1,4 @@
-using System;
-using System.Collections.Generic;
-using System.Linq;
-
-namespace Microsoft.eShopWeb.Web.Pages.Basket;
+namespace Microsoft.eShopWeb.Web.Pages.Basket;
public class BasketViewModel
{
diff --git a/src/Web/Pages/Basket/Index.cshtml.cs b/src/Web/Pages/Basket/Index.cshtml.cs
index ad42bf7..b8b7024 100644
--- a/src/Web/Pages/Basket/Index.cshtml.cs
+++ b/src/Web/Pages/Basket/Index.cshtml.cs
@@ -1,10 +1,6 @@
-using System;
-using System.Collections.Generic;
-using System.Linq;
-using System.Threading.Tasks;
-using Microsoft.AspNetCore.Http;
-using Microsoft.AspNetCore.Mvc;
+using Microsoft.AspNetCore.Mvc;
using Microsoft.AspNetCore.Mvc.RazorPages;
+using Microsoft.eShopWeb.ApplicationCore.Entities;
using Microsoft.eShopWeb.ApplicationCore.Interfaces;
using Microsoft.eShopWeb.Web.Interfaces;
using Microsoft.eShopWeb.Web.ViewModels;
@@ -15,12 +11,15 @@ public class IndexModel : PageModel
{
private readonly IBasketService _basketService;
private readonly IBasketViewModelService _basketViewModelService;
+ private readonly IRepository _itemRepository;
public IndexModel(IBasketService basketService,
- IBasketViewModelService basketViewModelService)
+ IBasketViewModelService basketViewModelService,
+ IRepository itemRepository)
{
_basketService = basketService;
_basketViewModelService = basketViewModelService;
+ _itemRepository = itemRepository;
}
public BasketViewModel BasketModel { get; set; } = new BasketViewModel();
@@ -37,9 +36,15 @@ public class IndexModel : PageModel
return RedirectToPage("/Index");
}
+ var item = await _itemRepository.GetByIdAsync(productDetails.Id);
+ if (item == null)
+ {
+ return RedirectToPage("/Index");
+ }
+
var username = GetOrSetBasketCookieAndUserName();
var basket = await _basketService.AddItemToBasket(username,
- productDetails.Id, productDetails.Price);
+ productDetails.Id, item.Price);
BasketModel = await _basketViewModelService.Map(basket);
diff --git a/src/Web/Pages/Index.cshtml.cs b/src/Web/Pages/Index.cshtml.cs
index d70c613..f2dd2cf 100644
--- a/src/Web/Pages/Index.cshtml.cs
+++ b/src/Web/Pages/Index.cshtml.cs
@@ -1,5 +1,4 @@
-using System.Threading.Tasks;
-using Microsoft.AspNetCore.Mvc.RazorPages;
+using Microsoft.AspNetCore.Mvc.RazorPages;
using Microsoft.eShopWeb.Web.Services;
using Microsoft.eShopWeb.Web.ViewModels;
diff --git a/src/Web/Web.csproj b/src/Web/Web.csproj
index 0c130a5..8852b54 100644
--- a/src/Web/Web.csproj
+++ b/src/Web/Web.csproj
@@ -20,16 +20,16 @@
-
-
-
+
+
+
-
-
-
-
-
-
+
+
+
+
+
+
all
runtime; build; native; contentfiles; analyzers; buildtransitive
diff --git a/tests/FunctionalTests/FunctionalTests.csproj b/tests/FunctionalTests/FunctionalTests.csproj
index 4a3072a..a280418 100644
--- a/tests/FunctionalTests/FunctionalTests.csproj
+++ b/tests/FunctionalTests/FunctionalTests.csproj
@@ -15,14 +15,14 @@
-
+
all
runtime; build; native; contentfiles; analyzers
-
+
diff --git a/tests/FunctionalTests/Web/Pages/Basket/IndexTest.cs b/tests/FunctionalTests/Web/Pages/Basket/IndexTest.cs
index 88ef743..cd36458 100644
--- a/tests/FunctionalTests/Web/Pages/Basket/IndexTest.cs
+++ b/tests/FunctionalTests/Web/Pages/Basket/IndexTest.cs
@@ -32,7 +32,6 @@ public class IndexTest : IClassFixture
{
new KeyValuePair("id", "2"),
new KeyValuePair("name", "shirt"),
- new KeyValuePair("price", "19.49"),
new KeyValuePair("__RequestVerificationToken", token)
};
var formContent = new FormUrlEncodedContent(keyValues);
@@ -45,7 +44,7 @@ public class IndexTest : IClassFixture
var updateKeyValues = new List>
{
new KeyValuePair("Items[0].Id", WebPageHelpers.GetId(stringResponse)),
- new KeyValuePair("Items[0].Quantity", "50"),
+ new KeyValuePair("Items[0].Quantity", "49"),
new KeyValuePair(WebPageHelpers.TokenTag, WebPageHelpers.GetRequestVerificationToken(stringResponse))
};
var updateContent = new FormUrlEncodedContent(updateKeyValues);
@@ -54,7 +53,8 @@ public class IndexTest : IClassFixture
var stringUpdateResponse = await updateResponse.Content.ReadAsStringAsync();
Assert.Contains("/basket/update", updateResponse.RequestMessage.RequestUri.ToString());
- Assert.Contains("974.50", stringUpdateResponse);
+ decimal expectedTotalAmount = 416.50M;
+ Assert.Contains(expectedTotalAmount.ToString("N2"), stringUpdateResponse);
}
[Fact]
@@ -72,7 +72,6 @@ public class IndexTest : IClassFixture
{
new KeyValuePair("id", "2"),
new KeyValuePair("name", "shirt"),
- new KeyValuePair("price", "19.49"),
new KeyValuePair("__RequestVerificationToken", token)
};
var formContent = new FormUrlEncodedContent(keyValues);
@@ -95,6 +94,5 @@ public class IndexTest : IClassFixture
Assert.Contains("/basket/update", updateResponse.RequestMessage.RequestUri.ToString());
Assert.Contains("Basket is empty", stringUpdateResponse);
-
}
}
diff --git a/tests/IntegrationTests/IntegrationTests.csproj b/tests/IntegrationTests/IntegrationTests.csproj
index 3f9c0ba..45a2b4f 100644
--- a/tests/IntegrationTests/IntegrationTests.csproj
+++ b/tests/IntegrationTests/IntegrationTests.csproj
@@ -7,7 +7,7 @@
-
+
diff --git a/tests/PublicApiIntegrationTests/PublicApiIntegrationTests.csproj b/tests/PublicApiIntegrationTests/PublicApiIntegrationTests.csproj
index e73f5f3..be6f560 100644
--- a/tests/PublicApiIntegrationTests/PublicApiIntegrationTests.csproj
+++ b/tests/PublicApiIntegrationTests/PublicApiIntegrationTests.csproj
@@ -20,10 +20,10 @@
-
+
-
-
+
+