public ActionResult AddStar() { string userId = User.Identity.GetUserId(); string bookId = HttpContext.Request["bookId"]; using (var context = new OnionContext()) { STAR item = new STAR() { CUSTOMERID = userId, BOOKID = bookId, TIME = DateTime.Now.ToString(), }; context.stars.Add(item); int res = context.SaveChanges(); } return(Content("添加成功")); }
public void save() { context.SaveChanges(); }
//[HttpPost] //[ValidateAntiForgeryToken] public ActionResult Checkout() { return(View()); double total = 0; string userId = User.Identity.GetUserId(); CheckoutViewModel ckVM = new CheckoutViewModel(); OORDER order = new OORDER() { CUSTOMERID = userId, ORDERID = DateTime.Now.ToFileTime().ToString(), RECIPIENTID = "01", TIME = DateTime.Now.ToString(), REMARK = "", STATUS = "未完成", SCORE = 5, FEEDBACK = "", }; using (var context = new OnionContext()) { var query = from p in context.preorders where p.CUSTOMERID == userId select p; var preOrderlist = query.ToList(); ckVM.Contains = new List <CONTAIN>(); for (int i = 0; i < preOrderlist.Count; ++i) { ckVM.Contains.Add(new CONTAIN() { ORDERID = order.ORDERID, BOOKID = preOrderlist[i].BOOKID, AMOUNT = preOrderlist[i].AMOUNT, }); var tmpId = preOrderlist[i].BOOKID; var pr = from b in context.books where b.BOOKID == tmpId select b.PRICE; double price = pr.FirstOrDefault(); ckVM.Contains[i].SUM = price * preOrderlist[i].AMOUNT; } for (int i = 0; i < ckVM.Contains.Count; ++i) { total += ckVM.Contains[i].SUM; } order.TOTAL = total; context.oorders.Add(order); for (int index = 0; index < ckVM.Contains.Count; ++index) { var tmpId = ckVM.Contains[index].BOOKID; context.preorders.Remove(context.preorders.Where( pre => pre.CUSTOMERID == userId && pre.BOOKID == tmpId).FirstOrDefault()); context.contains.Add(ckVM.Contains[index]); } ckVM.NewOrder = order; context.SaveChanges(); } return(View(ckVM)); }