public ActionResult ShippingDetails(RdplForm.Models.CustDetail result) { RahmanDbEntities db = new RahmanDbEntities(); { tblCustDetail objcustdt = new tblCustDetail(); objcustdt.CustName = result.CustName; objcustdt.Address = result.Address; objcustdt.MobileNo = result.MobileNO; // For total Amount Calculation List <CartItems> cartId = (List <CartItems>)Session["cart"]; var total_Amount = 0; foreach (var item in cartId) { //tblProductDetail prodDetail = new tblProductDetail(); var Amount = db.tblProductDetails.Where(c => c.ProductId == item.ProductId).FirstOrDefault(); total_Amount = total_Amount + (Amount.Price) * (item.Quantity); } objcustdt.Total_Amount = total_Amount; db.tblCustDetails.Add(objcustdt); db.SaveChanges(); ViewBag.Success = " Order placed Successfully "; tblProductDetail prodDetails = new tblProductDetail(); List <CartItems> cartIds = (List <CartItems>)Session["cart"]; foreach (var item in cartIds) { CustOrderDetail orddt = new CustOrderDetail(); orddt.Order_Id = objcustdt.CustId; orddt.Quntity = item.Quantity; orddt.Product_Id = item.ProductId; db.CustOrderDetails.Add(orddt); } db.SaveChanges(); ModelState.Clear(); } return(View()); }
public ActionResult SaveEmpDetail(OrderMst objOrder) { RahmanDbEntities objdb = new RahmanDbEntities(); if (objOrder.CustomerName == null || objOrder.OrderDetail == null) { ViewBag.msg = "Plz Fill all the details"; return(View("EmpDetail")); } else { tblOrderMst objordmst = new tblOrderMst(); // List<tblOrderDt objordDt = new tblOrderDt(); { objordmst.OrderNo = objOrder.No; objordmst.OrdDate = objOrder.Date; objordmst.CustName = objOrder.CustomerName; } objdb.tblOrderMsts.Add(objordmst); objdb.SaveChanges(); var id = objdb.tblOrderMsts.OrderByDescending(x => x.OrderId).First().OrderId; foreach (var lstg in objOrder.OrderDetail) { tblOrderDt objdt = new tblOrderDt(); objdt.OrderId = id; objdt.Item = lstg.Item; objdt.Quantity = lstg.Quantity; objdt.Rate = lstg.Rate; objdb.tblOrderDts.Add(objdt); objdb.SaveChanges(); } } return(Json(" Data Successfuly Saved")); }