Skip to content

Commit

Permalink
Section 12 - Remove From Session
Browse files Browse the repository at this point in the history
  • Loading branch information
bhrugen committed Sep 27, 2021
1 parent db2f275 commit 0e55e66
Showing 1 changed file with 5 additions and 0 deletions.
5 changes: 5 additions & 0 deletions BulkyBookWeb/Areas/Customer/Controllers/CartController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
using BulkyBook.Models.ViewModels;
using BulkyBook.Utility;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Identity.UI.Services;
using Microsoft.AspNetCore.Mvc;
using Stripe.Checkout;
Expand Down Expand Up @@ -215,6 +216,8 @@ public IActionResult Minus(int cartId)
if (cart.Count <= 1)
{
_unitOfWork.ShoppingCart.Remove(cart);
var count = _unitOfWork.ShoppingCart.GetAll(u => u.ApplicationUserId == cart.ApplicationUserId).ToList().Count-1;
HttpContext.Session.SetInt32(SD.SessionCart, count);
}
else
{
Expand All @@ -229,6 +232,8 @@ public IActionResult Remove(int cartId)
var cart = _unitOfWork.ShoppingCart.GetFirstOrDefault(u => u.Id == cartId);
_unitOfWork.ShoppingCart.Remove(cart);
_unitOfWork.Save();
var count = _unitOfWork.ShoppingCart.GetAll(u => u.ApplicationUserId == cart.ApplicationUserId).ToList().Count;
HttpContext.Session.SetInt32(SD.SessionCart, count);
return RedirectToAction(nameof(Index));
}

Expand Down

0 comments on commit 0e55e66

Please sign in to comment.