public ActionResult OrderProcessing(string toName, string toAddress, string toPhone, string userPay) { if (Session["userLogin"] != null) { string uName = Session["userLogin"].ToString(); Models.BookShopEntities4 db = new Models.BookShopEntities4(); Models.orderInfo oi = new Models.orderInfo() { submitTime = System.DateTime.Now.ToString(), toAddress = toAddress, toName = toName, toPhone = toPhone, buyUser = uName, orderState = "等待系统处理", payType = userPay }; db.orderInfo.Add(oi); db.SaveChanges(); var deleteQuery = db.buyCar.Where(e => e.buyUser == uName); // var orderId = db.buyCar.Where(e => e.buyUser == uName); //Models. bCar = db.buyCar.Where(b => b.booksID == id && b.buyUser == uname).FirstOrDefault(); foreach (var item in deleteQuery) { Models.bookInfo binfo = db.bookInfo.Where(b => b.bookID == item.booksID).FirstOrDefault(); Models.orderDetails od = new Models.orderDetails() { orderId = oi.orderId, bookId = item.booksID, bookPrice = binfo.bookPrice, buyNum = item.buyNum }; db.orderDetails.Add(od); db.buyCar.Remove(item); } db.SaveChanges(); Response.Write("<script language='javaScript' type='text/javaScript'>window.onload=function(){layer.alert('订单提交成功',function (){location='/My/MyOrder'});}</script>"); return(View()); } else { return(RedirectToAction("otherLogin", "Login", new { m = "My", a = "Settlement" })); } }
public ActionResult OrderProcessing(string toName, string toAddress, string toPhone, string userPay) { if (Session["userLogin"] != null) { string uName = Session["userLogin"].ToString(); Models.BookShopEntities4 db = new Models.BookShopEntities4(); Models.orderInfo oi=new Models.orderInfo () { submitTime=System.DateTime.Now.ToString(), toAddress=toAddress, toName=toName, toPhone=toPhone, buyUser=uName, orderState="等待系统处理", payType = userPay }; db.orderInfo.Add(oi); db.SaveChanges(); var deleteQuery = db.buyCar.Where(e => e.buyUser == uName); // var orderId = db.buyCar.Where(e => e.buyUser == uName); //Models. bCar = db.buyCar.Where(b => b.booksID == id && b.buyUser == uname).FirstOrDefault(); foreach (var item in deleteQuery) { Models.bookInfo binfo = db.bookInfo.Where(b => b.bookID == item.booksID).FirstOrDefault(); Models.orderDetails od = new Models.orderDetails() { orderId = oi.orderId, bookId=item.booksID, bookPrice=binfo.bookPrice, buyNum=item.buyNum }; db.orderDetails.Add(od); db.buyCar.Remove(item); } db.SaveChanges(); Response.Write("<script language='javaScript' type='text/javaScript'>window.onload=function(){layer.alert('订单提交成功',function (){location='/My/MyOrder'});}</script>"); return View(); } else { return RedirectToAction("otherLogin", "Login", new { m = "My", a = "Settlement" }); } }