public ActionResult Edit(SanaatanResource model) { TimeZoneInfo INDIAN_ZONE = TimeZoneInfo.FindSystemTimeZoneById("India Standard Time"); DateTime indianTime = TimeZoneInfo.ConvertTimeFromUtc(DateTime.UtcNow, INDIAN_ZONE); if (ModelState.IsValid) { string fdel = ""; string Fname = ""; string path = ""; HttpPostedFileBase pb = Request.Files["image"]; if (pb != null && pb.ContentLength > 0) { path = Server.MapPath("~/Content/UploadedImages/Sanaatan"); fdel = System.IO.Path.Combine(path, model.Image); System.IO.File.Delete(fdel); Fname = DateTime.Now.Date.ToString("yyyyMMddHHmmssfff") + System.IO.Path.GetFileName(pb.FileName); pb.SaveAs(System.IO.Path.Combine(path, Fname)); model.Image = Fname; } db._SanaatanResource.Add(model); db.Entry(model).State = EntityState.Modified; db.SaveChanges(); return(RedirectToAction("List")); } return(View()); }
public ActionResult View(int?id) { if (id == null) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } SanaatanResource m = db._SanaatanResource.Find(id); if (m == null) { return(HttpNotFound()); } return(View(m)); }
public ActionResult DeleteConfirmed(int id) { SanaatanResource m = db._SanaatanResource.Find(id); string fdel = m.Image; string path = ""; path = Server.MapPath("~/Content/UploadedImages/Sanaatan"); fdel = System.IO.Path.Combine(path, fdel); System.IO.File.Delete(fdel); db._SanaatanResource.Remove(m); db.SaveChanges(); return(RedirectToAction("List")); }
public ActionResult Create(SanaatanResource js) { if (ModelState.IsValid) { string Fname = ""; string path = ""; HttpPostedFileBase pb = Request.Files["image"]; if (pb != null && pb.ContentLength > 0) { Fname = DateTime.Now.ToString("yyyyMMddHHmmssfff") + System.IO.Path.GetFileName(pb.FileName); path = Server.MapPath("~/Content/UploadedImages/Sanaatan"); pb.SaveAs(System.IO.Path.Combine(path, Fname)); js.Image = Fname; } db._SanaatanResource.Add(js); db.SaveChanges(); return(RedirectToAction("List")); } return(RedirectToAction("Index", "Home")); }