public ActionResult AddOrEditProductVariation(Guid?id) { try { var model = new ProVarationViewModel(); model.DropDownProduct = DropDownListDomain.DropDownList_Product(_productService.SelectAll()); model.DropDownVolume = DropDownListDomain.DropDownList_Volume(); if (id.HasValue) { var productVariation = _productVariationService.GetById(id.Value); model = ConvertDomainToModel.ConvertModelFromDomainToProVa(productVariation); model.DropDownProduct = DropDownListDomain.DropDownList_Product(_productService.SelectAll()); model.DropDownVolume = DropDownListDomain.DropDownList_Volume(); model.Image = _productImageService.GetProductImage(model.Id) == null ? null : ConvertDomainToModel.GetProductImage(_productImageService.GetProductImage(model.Id)); return(View(model)); } else { return(View(model)); } } catch { return(RedirectToAction("Erorr500", "HomdeAdmin")); } }
/// <summary> /// Sum Product Price In Order /// </summary> /// <param name="models"></param> /// <returns>sum price</returns> private decimal SumProductPriceInOrder(IList <ShoppingCartDetailModel> models) { decimal sum = 0; foreach (var item in models) { var pro = _productVariationService.GetById(item.ProductVariation_Id); sum += GetPrice.GetProductPrice(pro); } return(sum); }
public ActionResult AddProductToCart(string proVaId, int quantity) { try { var shoppingCart = GetOrSetShoppingCart(); var id = Guid.Parse(proVaId); var shoppingCartDetail = _shoppingCartDetailService.GetByProductIdAndCartShoppingCartId(id, shoppingCart.Id); var productVa = _productVariationService.GetById(id); if (shoppingCartDetail != null) { // update quantity and update day shoppingCartDetail.Quantity = shoppingCartDetail.Quantity + quantity; shoppingCartDetail.UpdatedDate = DateTime.Now; _shoppingCartDetailService.Update(shoppingCartDetail); } else { // Add new shopping cart detail var cartDetail = new ShoppingCartDetail { Id = Guid.NewGuid(), ShoppingCart_Id = shoppingCart.Id, ProductVariation_Id = id, Quantity = quantity, CreatedDate = DateTime.Now, IsActive = true, }; _shoppingCartDetailService.Insert(cartDetail); } return(RedirectToAction("Index", "Shop")); } catch { return(RedirectToAction("Erorr", "Home")); } }