public ActionResult Create(BangSanPham model) { CheckBangSanPham(model); if (ModelState.IsValid) { using (var scope = new TransactionScope()) { db.BangSanPhams.Add(model); db.SaveChanges(); var path = Server.MapPath("~/App_Data"); path = path + "/" + model.id; if (Request.Files["HinhAnh"] != null && Request.Files["HinhAnh"].ContentLength > 0) { Request.Files["HinhAnh"].SaveAs(path); scope.Complete(); return(RedirectToAction("Index")); } else { ModelState.AddModelError("HinhAnh", "Chưa có hình sản phẩm!"); } } } ViewBag.Loai_id = new SelectList(db.LoaiSanPhams, "id", "TenLoai", model.Loai_id); return(View(model)); }
public ActionResult Create(BubleTea model) { if (ModelState.IsValid) { db.BubleTeas.Add(model); db.SaveChanges(); return(RedirectToAction("Index")); } return(View(model)); }
public ActionResult Create([Bind(Include = "id,Name")] Category category) { if (ModelState.IsValid) { db.Categories.Add(category); db.SaveChanges(); return(RedirectToAction("Index")); } return(View(category)); }
public ActionResult Create([Bind(Include = "id,Name,Price,Description,idCategory")] Product product) { if (ModelState.IsValid) { db.Products.Add(product); db.SaveChanges(); return(RedirectToAction("Index")); } ViewBag.idCategory = new SelectList(db.Categories, "id", "Name", product.idCategory); return(View(product)); }
public ActionResult Create([Bind(Include = "id,Name,Price,Topping")] BubleTea model) { ValidateProduct(model); if (ModelState.IsValid) { model.Expire = DateTime.Today; db.BubleTeas.Add(model); db.SaveChanges(); return(RedirectToAction("Index")); } return(View(model)); }