// GET: RaoVat //public ActionResult Index() //{ // return View(db.RAOVATs.ToList()); //} public ActionResult Create() { if (Session["TENDANGNHAP"] == null) { return(RedirectToAction("Index", "Admin")); } else { RAOVAT raovat = new RAOVAT(); return(View(raovat)); } }
public ActionResult Delete(int id, RAOVAT x) { try { x = db.RAOVATs.Where(s => s.MATIN == id).FirstOrDefault(); db.RAOVATs.Remove(x); db.SaveChanges(); return(RedirectToAction("Index")); } catch { return(Content("This data is using in other table, Error Delete!")); } }
public ActionResult Create(RAOVAT raovat) { try { raovat.MATRANGTHAI = 1; raovat.NGAYGIODANG = DateTime.Now; raovat.NGAYHETHAN = DateTime.Now.AddDays(30); string filename = Path.GetFileNameWithoutExtension(raovat.UploadImage.FileName); string extent = Path.GetExtension(raovat.UploadImage.FileName); filename = filename + extent; raovat.HINHANH1 = "~/Content/img/" + filename; raovat.UploadImage.SaveAs(Path.Combine(Server.MapPath("~/Content/img/"), filename)); db.RAOVATs.Add(raovat); db.SaveChanges(); return(RedirectToAction("Index", "RaoVat")); } catch { return(View()); } }
public ActionResult Edit(int id, RAOVAT x) { db.Entry(x).State = System.Data.Entity.EntityState.Modified; db.SaveChanges(); return(RedirectToAction("Index")); }