public ActionResult ConfirmCart(vOListVM vm) { if (ModelState.IsValid) { vm.cId = (int)Session[CDictionary.SK_LOGINED_USER_ID]; vm.priceWithTax = (decimal)Session[CDictionary.TK_Cart_TOTALPRICE]; var user = db.Customer.FirstOrDefault(c => c.cId == vm.cId); var currentCart = db.OrderList .Where(m => m.cId == vm.cId); foreach (var item in currentCart) { item.oRDate = vm.serverDate; item.oStatus = orderStatus.afterCheckOut.GetHashCode(); } user.cPoint -= vm.priceWithTax; transaction ts = new transaction(); ts.cId = vm.cId; ts.companyIncome = vm.priceWithTax * (decimal)0.9; ts.tDate = DateTime.Now; db.transaction.Add(ts); db.SaveChanges(); return(RedirectToAction("CCenterList", "Acc")); } return(View(vm)); }
public ActionResult ConfirmCart() { var userId = (int)Session[CDictionary.SK_LOGINED_USER_ID]; var currentCart = db.OrderList.Where(o => o.cId == userId); var orderList = new List <olist>(); foreach (var item in currentCart) { orderList.Add(new olist { cId = userId, oId = item.oId, productName = item.Product.pName, productPrice = (decimal)item.Product.pPrice, orderQty = item.oQty, totalPrice = (decimal)item.Product.pPrice * item.oQty }); } var vm = new vOListVM { olist = orderList, cartPrice = (decimal)orderList.Sum(x => x.totalPrice), tax = orderList.Sum(x => x.totalPrice) * (decimal)0.12, priceWithTax = orderList.Sum(x => x.totalPrice) * (decimal)1.12 }; Session[CDictionary.TK_Cart_TOTALPRICE] = vm.priceWithTax; return(View(vm)); }