public void DeleteShopping(User user, Item item) { T_Shopping tsh = GetT_Shopping(item, user); if (tsh != null) { Delete(tsh); } }
public T_Shopping DeleteShopping(User user, Item item, int count) { T_Shopping tsh = GetT_Shopping(item, user); if (tsh != null) { if (tsh.Count <= count) { Delete(tsh); } else { tsh.Count -= count; return(tsh); } } return(null); }
public ActionResult Details(int id, FormCollection collection) { if (!CurrentUser.IsAuthenticated) { return(RedirectToAction("LogIn", "Account")); } int num = 0; if (!string.IsNullOrEmpty(Request.Form["BuyNumber"])) { try { num = Convert.ToInt32(Request.Form["BuyNumber"]); } catch { return(RedirectToAction("Error", "Item", new { Id = id, Errorm = "请输入正确的购买数量" })); } } else { return(RedirectToAction("Error", "Item", new { Id = id, Errorm = "请输入购买数量" })); } Item item = yikuData.GetItem(id); T_Shopping tsh = new T_Shopping(); if (item != null) { if (item.PublisherID == yikuData.UserCurrent.UID) { return(RedirectToAction("Error", "Item", new { Id = id, Errorm = "不能购买自己的商品" })); } tsh = yikuData.AddShopping(yikuData.UserCurrent, item); yikuData.Save(); tsh.Count += (num - 1); yikuData.Save(); return(RedirectToAction("Index", "Cart")); } return(RedirectToAction("Details", "Item", new { Id = id })); }
public ActionResult cart(FormCollection collection) { string cosignee = yikuData.UserCurrent.Consignee; if (!string.IsNullOrEmpty(Request.Form["CurrentUser.Consignee"])) { cosignee = Request.Form["CurrentUser.Consignee"]; } string Address = yikuData.UserCurrent.Address; if (!string.IsNullOrEmpty(Request.Form["CurrentUser.Consignee"])) { cosignee = Request.Form["CurrentUser.Consignee"]; } CartModels cm = new CartModels(); IQueryable <T_Shopping> TSHS = cm.TSHs; foreach (T_Shopping tsh in TSHS) { Order order = new Order(); order.IID = tsh.IID; order.UID = cm.CurrentUser.UID; order.Count = tsh.Count; order.Cut = tsh.Cut; order.Time = DateTime.Now; order.Cost = tsh.Item.Price * tsh.Count; order.State = "pay"; order.Address = Address; yikuData.Add(order); T_Shopping sss = yikuData.GetT_Shopping(tsh.T_Sh_ID); Item item = yikuData.GetItem(order.IID); item.Volume += order.Count; //商品卖出量增加N份 yikuData.Delete(sss); } yikuData.Save(); return(RedirectToAction("trade", "MyYiku")); }
public T_Shopping AddShopping(User user, Item item, int Count, string Cut = null) { T_Shopping tsh = GetT_Shopping(item, user); if (tsh == null) { tsh = new T_Shopping(); tsh.UID = user.UID; tsh.IID = item.IID; tsh.Count = Count; tsh.Cut = Cut; Add(tsh); } else { tsh.Count += Count; if (Cut != null) { tsh.Cut = Cut; } } return(tsh); }
public ActionResult DeclineShopping(int?id) { if (!CurrentUser.IsAuthenticated) { return(RedirectToAction("LogIn", "Account")); } if (id != null) { Item item = yikuData.GetItem(id.Value); T_Shopping tsh = new T_Shopping(); if (item != null) { if (item.PublisherID == yikuData.UserCurrent.UID) { return(RedirectToAction("Details", "Item", new { ID = id.Value })); } tsh = yikuData.DeleteShopping(yikuData.UserCurrent, item, 1); yikuData.Save(); return(RedirectToAction("Index", "Cart")); } } return(RedirectToAction("Index", "Item")); }
public void Add(T_Shopping tsh) { yikuData.T_Shopping.AddObject(tsh); }
public void Delete(T_Shopping tsh) { yikuData.T_Shopping.DeleteObject(tsh); }