public bool Delete(int productSizeId, out string strResult) { strResult = string.Empty; bool result = false; var si = ProductSizeRepository.GetQueryable().FirstOrDefault(s => s.ID == productSizeId); if (si != null) { try { ProductSizeRepository.Delete(si); ProductSizeRepository.SaveChanges(); result = true; } catch (Exception) { strResult = "原因:已在使用"; } } else { strResult = "原因:未找到当前需要删除的数据!"; } return(result); }
public bool Delete(int productSizeId) { var si = ProductSizeRepository.GetQueryable().FirstOrDefault(s => s.ID == productSizeId); if (si != null) { ProductSizeRepository.Delete(si); ProductSizeRepository.SaveChanges(); } else { return(false); } return(true); }
public IHttpActionResult Get(int id, string paymentmethod) { var x = ProductController.cartviewlist; List <CartViewModel> cartlist = ProductController.cartviewlist; var date = DateTime.Now; foreach (var item in cartlist) { if (item.product.SizeCategory == "other") { Product p1 = new Product(); p1 = productrepo.Get(item.product.ProductId); p1.OnHand -= item.count; productrepo.Update(p1); } else { ProductSize psize = new ProductSize(); psize = productsizeModel.Get(item.size.ProductSizeID); psize.Count = (psize.Count - item.count); if (psize.Count == 0) { productsizeModel.Delete(psize.ProductSizeID); } else { productsizeModel.Update(psize); } } TempOrder order = new TempOrder(); order.date = date; order.Quantity = item.count; if (item.product.Sale != null) { var p = (double)item.product.UnitPrice; var v = Convert.ToDouble(item.product.Sale.Amount) / 100; var c1 = (p - (p * v)); order.totalAmount = (decimal)(item.count * c1); } else { order.totalAmount = (item.count * item.product.UnitPrice); } if (item.product.SizeCategory != "other") { order.Size = item.size.SizeName; } order.PayMentMethod = paymentmethod; temporderrepo.Insert(order); TempOrderProduct orderproduct = new TempOrderProduct(); orderproduct.CustomerID = id; orderproduct.TempOrderId = order.TempOrderId; orderproduct.ProductID = item.product.ProductId; temporderproductrepo.Insert(orderproduct); /* Profit profit = new Profit(); * profit.ProductOrderID = orderproduct.ProductOrderID; * if (item.product.Sale != null) * { * var p = (double)item.product.UnitPrice; * var v = Convert.ToDouble(item.product.Sale.Amount) / 100; * var c1 = (p - (p * v)); * profit.ProfitAmount = ((decimal)c1 - item.product.Cost) * item.count; * } * else * { * profit.ProfitAmount = (item.product.UnitPrice - item.product.Cost) * item.count; * } * * * profitrepo.Insert(profit);*/ } ProductController.cartviewlist.Clear(); return(Ok("SuccessView")); }
public void Delete(long?id) { _ProductSizesRepository.Delete(id); }
public ActionResult UpdateOrderInformation() { List <CartViewModel> cartlist = new List <CartViewModel>(); cartlist = (List <CartViewModel>)Session["cart"]; var date = DateTime.Now; foreach (var item in cartlist) { if (item.product.SizeCategory == "other") { Product p1 = new Product(); p1 = productrepo.Get(item.product.Product_id); p1.OnHand -= item.count; productrepo.Update(p1); } else { ProductSize psize = new ProductSize(); psize = productsizeModel.Get(item.size.ProductSizeID); psize.Count = (psize.Count - item.count); if (psize.Count == 0) { productsizeModel.Delete(psize.ProductSizeID); } else { productsizeModel.Update(psize); } } TempOrder order = new TempOrder(); order.date = date; order.Quantity = item.count; if (item.product.Sale != null) { var p = (double)item.product.UnitPrice; var v = Convert.ToDouble(item.product.Sale.Amount) / 100; var c1 = (p - (p * v)); order.totalAmount = (decimal)(item.count * c1); } else { order.totalAmount = (item.count * item.product.UnitPrice); } if (item.product.SizeCategory != "other") { order.Size = item.size.SizeName; } order.PayMentMethod = (string)Session["paymentmethod"]; temporderrepo.Insert(order); TempOrderProduct orderproduct = new TempOrderProduct(); orderproduct.CustomerID = (int)Session["LoginID"]; orderproduct.OrderID = order.OrderID; orderproduct.ProductID = productHistory.GetByProductNameCategory(item.product.Product_name, item.product.CategoryID).Product_id; temporderproductrepo.Insert(orderproduct); /* Profit profit = new Profit(); * profit.ProductOrderID = orderproduct.ProductOrderID; * if (item.product.Sale != null) * { * var p = (double)item.product.UnitPrice; * var v = Convert.ToDouble(item.product.Sale.Amount) / 100; * var c1 = (p - (p * v)); * profit.ProfitAmount = ((decimal)c1 - item.product.Cost) * item.count; * } * else * { * profit.ProfitAmount = (item.product.UnitPrice - item.product.Cost) * item.count; * } * * * profitrepo.Insert(profit);*/ } Session["cart"] = null; return(RedirectToAction("SuccessView")); }