public ActionResult DeleteMemberOrderDetail(int productDetailID, int memberOrderID) { MemberOrder memberOrder = _entities.MemberOrders.Single(a => a.ID == memberOrderID); MemberOrderDetail memberOrderDetail = _entities.MemberOrderDetails.Single(a => a.ProductDetailID == productDetailID && a.MemberOrderID == memberOrderID && a.MemberOrder.OrderStatusID == 1); decimal realPrice = GetProductPriceAfterDiscount(memberOrderDetail.ProductDetail.Product, memberOrderDetail.Quantity); memberOrder.Price -= realPrice; //float discount = 0; //if (memberOrderDetail.ProductDetail.Product.ProductDiscounts.Any(a => a.DateTo >= DateTime.Today)) //{ // discount = memberOrderDetail.ProductDetail.Product.ProductDiscounts.Where(a => a.DateTo >= DateTime.Today).FirstOrDefault().Discount; //} //memberOrder.Price -= memberOrderDetail.Quantity * memberOrderDetail.ProductDetail.Product.UnitPrice * (1 - (decimal)discount); _entities.DeleteObject(memberOrderDetail); _entities.SaveChanges(); bool exist = _entities.MemberOrderDetails.Any(a => a.MemberOrderID == memberOrderID); int productOrderID = memberOrder.ProductOrderID; if (exist) { return(RedirectToAction("Details", new { memberOrderID = memberOrderID, orderStatusID = memberOrder.OrderStatusID })); } else { _entities.DeleteObject(memberOrder); _entities.SaveChanges(); return(RedirectToAction("ProductList", new { productOrderID = productOrderID })); } }
public void AddToMemberOrderDetailForProduct(FormCollection collection, MemberOrder memberOrder, int productID) { string[] productQuantitys = collection.Get("Quantity").Split(','); int j = 0; decimal totalPrice = 0; List <ProductDetail> productDetails = _entities.ProductDetails.Where(a => a.ProductID == productID && a.UpdateDate > SMCHSGManager.Controllers.ProductController.updateTime).ToList(); foreach (ProductDetail pd in productDetails) { if (!string.IsNullOrEmpty(productQuantitys[j]) && IsDigitString(productQuantitys[j]) && int.Parse(productQuantitys[j]) > 0) { MemberOrderDetail memberOrderDetail = new MemberOrderDetail(); memberOrderDetail.ProductDetail = pd; memberOrderDetail.Quantity = short.Parse(productQuantitys[j]); memberOrder.MemberOrderDetails.Add(memberOrderDetail); float discount = 0; if (pd.Product.ProductDiscounts.Any(a => a.DateTo >= DateTime.Today)) { discount = pd.Product.ProductDiscounts.Where(a => a.DateTo >= DateTime.Today).FirstOrDefault().Discount; } if (discount != 0.3333f) { totalPrice += memberOrderDetail.ProductDetail.Product.UnitPrice * (1 - (decimal)discount) * memberOrderDetail.Quantity; } else { int backNos = memberOrderDetail.Quantity / 3; totalPrice += memberOrderDetail.ProductDetail.Product.UnitPrice * (memberOrderDetail.Quantity - backNos); } } j++; } if (totalPrice == 0) { ModelState.AddModelError("", "please input the quantity of product."); } else { memberOrder.Price += totalPrice; memberOrder.CurrencyCode = memberOrder.MemberOrderDetails.FirstOrDefault().ProductDetail.Product.CurrencyCode; } }