public ActionResult Create2() { using (var scope = new TransactionScope()) try { var cashBill = Session["CashBill"] as CashBill; var ctcashBill = Session["ctcashBill"] as List <CashBillDetail>; db.CashBills.Add(cashBill); db.SaveChanges(); foreach (var chiTiet in ctcashBill) { chiTiet.BillID = cashBill.ID; chiTiet.Product = null; db.CashBillDetails.Add(chiTiet); cashBill.GrandTotal += (chiTiet.Quantity * chiTiet.SalePrice); } db.SaveChanges(); scope.Complete(); Session["CashBill"] = null; Session["ctcashBill"] = null; return(RedirectToAction("Index")); } catch (Exception e) { ModelState.AddModelError("", e.Message); } return(View("Create")); }
public ActionResult CreateEdit(CashBillDetail cashbilldetail) { var a = (Int32)Session["id"]; if (ModelState.IsValid) { db.CashBillDetails.Add(cashbilldetail); db.SaveChanges(); return(RedirectToAction("Edit", "CashBills", new { id = a })); } ViewBag.BillID = new SelectList(db.CashBills, "ID", "BillCode", cashbilldetail.BillID); ViewBag.ProductID = new SelectList(db.Products, "ID", "ProductCode", cashbilldetail.ProductID); return(View(cashbilldetail)); }
public ActionResult Create(Product p) { CheckBangSanPham(p); if (ModelState.IsValid) { using (var scope = new TransactionScope()) { var pro = new Product(); pro.ProductCode = p.ProductCode; pro.ProductName = p.ProductName; pro.ProductType = p.ProductType; pro.ProductTypeID = p.ProductTypeID; pro.OriginPrice = p.OriginPrice; pro.SalePrice = p.SalePrice; pro.Status = p.Status; pro.Quantity = p.Quantity; pro.InstallmentPrice = p.InstallmentPrice; pro.Avatar = p.Avatar; db.Products.Add(pro); db.SaveChanges(); var path = Server.MapPath("~/App_Data"); path = path + "/" + pro.ID; if (Request.Files["Avatar"] != null && Request.Files["Avatar"].ContentLength > 0) { Request.Files["Avatar"].SaveAs(path); scope.Complete(); return(RedirectToAction("Index")); } else { ModelState.AddModelError("Avatar", "Chưa có hình ảnh"); } } } ViewBag.ProductTypeID = new SelectList(db.ProductTypes, "ID", "ProductTypeName", p.ProductTypeID); return(View()); }