Compare commits

...

3 Commits

4 changed files with 68 additions and 1 deletions

View File

@ -5,6 +5,7 @@ using System.Collections.Generic;
using System.Linq; using System.Linq;
using System.Web; using System.Web;
using System.Web.Mvc; using System.Web.Mvc;
using SportsStore.WebUI.Models;
namespace SportsStore.WebUI.Controllers namespace SportsStore.WebUI.Controllers
{ {
@ -17,6 +18,15 @@ namespace SportsStore.WebUI.Controllers
repository = repo; repository = repo;
} }
public ViewResult Index(string returnUrl)
{
return View(new CartIndexViewModel
{
Cart = GetCart(),
ReturnUrl = returnUrl
});
}
// GET: Cart // GET: Cart
public RedirectToRouteResult AddToCart(int productId, string returnUrl) public RedirectToRouteResult AddToCart(int productId, string returnUrl)
{ {

View File

@ -0,0 +1,14 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using SportsStore.Domain.Entities;
namespace SportsStore.WebUI.Models
{
public class CartIndexViewModel
{
public Cart Cart { get; set; }
public string ReturnUrl { get; set; }
}
}

View File

@ -138,6 +138,7 @@
</Compile> </Compile>
<Compile Include="HtmlHelpers\PagingHelpers.cs" /> <Compile Include="HtmlHelpers\PagingHelpers.cs" />
<Compile Include="Infrastructure\NinjectDependencyResolver.cs" /> <Compile Include="Infrastructure\NinjectDependencyResolver.cs" />
<Compile Include="Models\CartIndexViewModel.cs" />
<Compile Include="Models\PagingInfo.cs" /> <Compile Include="Models\PagingInfo.cs" />
<Compile Include="Models\ProductsListViewModel.cs" /> <Compile Include="Models\ProductsListViewModel.cs" />
<Compile Include="Properties\AssemblyInfo.cs" /> <Compile Include="Properties\AssemblyInfo.cs" />
@ -151,6 +152,7 @@
<Content Include="Scripts\jquery-1.9.0.min.map" /> <Content Include="Scripts\jquery-1.9.0.min.map" />
<Content Include="Views\Shared\ProductSummary.cshtml" /> <Content Include="Views\Shared\ProductSummary.cshtml" />
<Content Include="Views\Nav\Menu.cshtml" /> <Content Include="Views\Nav\Menu.cshtml" />
<Content Include="Views\Cart\Index.cshtml" />
<None Include="Web.Debug.config"> <None Include="Web.Debug.config">
<DependentUpon>Web.config</DependentUpon> <DependentUpon>Web.config</DependentUpon>
</None> </None>
@ -160,7 +162,6 @@
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<Folder Include="App_Data\" /> <Folder Include="App_Data\" />
<Folder Include="Views\Cart\" />
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<ProjectReference Include="..\SportsStore.Domain\SportsStore.Domain.csproj"> <ProjectReference Include="..\SportsStore.Domain\SportsStore.Domain.csproj">

View File

@ -0,0 +1,42 @@
@model SportsStore.WebUI.Models.CartIndexViewModel
@{
ViewBag.Title = "Sports Store: Your Cart";
}
<h2>Your cart</h2>
<table class="table">
<thead>
<tr>
<th>Quantity</th>
<th>Item</th>
<th class="text-right">Price</th>
<th class="text-right">Subtotal</th>
</tr>
</thead>
<tbody>
@foreach (var line in Model.Cart.Lines) {
<tr>
<td class="text-center">@line.Quantity</td>
<td class="text-left">@line.Product.Name</td>
<td class="text-right">@line.Product.Price.ToString("c")</td>
<td class="text-right">
@((line.Quantity * line.Product.Price).ToString("c"))
</td>
</tr>
}
</tbody>
<tfoot>
<tr>
<td colspan="3" class="text-right">Total:</td>
<td class="text-right">
@Model.Cart.ComputeTotalValue().ToString("c")
</td>
</tr>
</tfoot>
</table>
<div class="text-center">
<a class="btn btn-primary" href="@Model.ReturnUrl">Continue shopping</a>
</div>