public ActionResult Create(SANPHAM model, HttpPostedFileBase picture) { ValidateProduct(model); if (ModelState.IsValid) { if (picture != null) { using (var scope = new TransactionScope()) { db.SANPHAMs.Add(model); db.SaveChanges(); // store picture var path = Server.MapPath(PICTURE_PATH); picture.SaveAs(path + model.MASP); scope.Complete(); return(RedirectToAction("Index")); } } else { ModelState.AddModelError("", "Picture not found!"); } } ViewBag.MAKM = new SelectList(db.KHUYENMAIs, "MAKHUYENMAI", "TENKHUYENMAI", model.MAKM); ViewBag.LOAISP = new SelectList(db.LOAISANPHAMs, "MALOAISP", "TENLOAISP", model.LOAISP); ViewBag.MANCC = new SelectList(db.NHACUNGCAPs, "MANHACUNGCAP", "TENNHACUNGCAP", model.MANCC); return(View(model)); }
public ActionResult Create(DONHANG model) { ValidateBill(model); if (ModelState.IsValid) { using (var scope = new TransactionScope()) { model.NGAYTAODONHANG = DateTime.Now; db.DONHANGs.Add(model); db.SaveChanges(); foreach (var item in ShoppingCart) { db.CHITIETDONHANGs.Add(new CHITIETDONHANG { MADONHANG = model.MADONHANG, MASANPHAM = item.SANPHAM.MASP, GIATIENBAN = item.SANPHAM.GIABAN, SOLUONG = item.SOLUONG }); } db.SaveChanges(); scope.Complete(); Session["ShoppingCart"] = null; return(RedirectToAction("Index2", "SANPHAMs")); } } GetShoppingCart(); ViewBag.Cart = ShoppingCart; return(View(model)); }
public ActionResult Create(string roleId, string userId) { var role = db.AspNetRoles.Find(roleId); var user = db.AspNetUsers.Find(userId); role.AspNetUsers.Add(user); db.Entry(role).State = EntityState.Modified; db.SaveChanges(); return(RedirectToAction("Index", "AspNetRoles")); }
public ActionResult Create([Bind(Include = "ID,MASANPHAM,MATAIKHOAN,HOTEN,NOIDUNG,THOIGIANDANG,SOSAODANHGIA")] REVIEWRATING rEVIEWRATING) { if (ModelState.IsValid) { db.REVIEWRATINGs.Add(rEVIEWRATING); db.SaveChanges(); return RedirectToAction("Index"); } ViewBag.MASANPHAM = new SelectList(db.SANPHAMs, "MASP", "TENSP", rEVIEWRATING.MASANPHAM); return View(rEVIEWRATING); }
public ActionResult Create(AspNetRole aspNetRole) { if (ModelState.IsValid) { aspNetRole.Id = Guid.NewGuid().ToString(); db.AspNetRoles.Add(aspNetRole); db.SaveChanges(); return(RedirectToAction("Index")); } return(View(aspNetRole)); }
public ActionResult C(string HOTEN, string NOIDUNG, int MaSP, string Rating) { if (ModelState.IsValid) { var db = new CsK24T25Entities(); var rate = new REVIEWRATING(); rate.HOTEN = HOTEN; rate.NOIDUNG = NOIDUNG; rate.MASANPHAM = MaSP; rate.SOSAODANHGIA = Double.Parse(Rating); rate.THOIGIANDANG = DateTime.Now; db.REVIEWRATINGs.Add(rate); db.SaveChanges(); return RedirectToAction("Details", "SANPHAMs", new { id = MaSP }); } return View(); }