public ActionResult DeleteFromCartList(int productid) { var currentUserId = Convert.ToInt32(GlobalUser.getGlobalUser().UserId); if (currentUserId > 0) { var cartProduct = _AddToCartBusiness.GetList(c => c.UserId == currentUserId && c.ProductId == productid).FirstOrDefault(); if (cartProduct != null) { _AddToCartBusiness.Delete(cartProduct); _unitOfWork.SaveChanges(); } } else { CookieStore mycookie = new CookieStore(); var products = mycookie.GetCookie(Enumerator.CustomerAction.AddToCart.ToString()); var productId = productid.ToString(); var value = mycookie.FormatCartCookieValueAfterDelete(products, productId); var expireCookieTimeHr = Convert.ToInt32(ReadConfigData.GetAppSettingsValue("ExpireCookieTimeHr")); mycookie.SetCookie(Enumerator.CustomerAction.AddToCart.ToString(), value, expireCookieTimeHr); } return(new EmptyResult()); }
public void clearCart() { var currentUserId = Convert.ToInt32(GlobalUser.getGlobalUser().UserId); if (currentUserId > 0) { var cartData = _AddToCartBusiness.GetList(c => c.UserId == currentUserId); foreach (var product in cartData) { _AddToCartBusiness.Delete(product); _unitOfWork.SaveChanges(); } } else { CookieStore mycookie = new CookieStore(); var expireCookieTimeHr = Convert.ToInt32(ReadConfigData.GetAppSettingsValue("ExpireCookieTimeHr")); mycookie.SetCookie(Enumerator.CustomerAction.AddToCart.ToString(), "", expireCookieTimeHr); } }