public ActionResult NewsAndUpdated(tbl_NewsAndUpdatedss model, HttpPostedFileBase files) { try { if (model.pkid == 0) { tbl_NewsAndUpdated abc = new tbl_NewsAndUpdated(); abc.Title = model.Title; abc.Description = model.Description; abc.status = model.status; abc.ProfilePic = model.ProfilePic; abc.Addate = DateTime.Now; abc.lastModified = DateTime.Now; if (files != null) { string path = System.Web.HttpContext.Current.Server.MapPath(model.ProfilePic); if (System.IO.File.Exists(path)) { System.IO.File.Delete(path); } WebFunction web = new WebFunction(); abc.ProfilePic = web.Storefile(files, 6); } _news.Add(abc); } else { int _id = Convert.ToInt32(model.pkid); tbl_NewsAndUpdated abc = _news.Get(_id); abc.Title = model.Title; abc.status = model.status; abc.Description = model.Description; abc.ProfilePic = model.ProfilePic; abc.lastModified = DateTime.Now; if (files != null) { string path = System.Web.HttpContext.Current.Server.MapPath(model.ProfilePic); if (System.IO.File.Exists(path)) { System.IO.File.Delete(path); } WebFunction web = new WebFunction(); abc.ProfilePic = web.Storefile(files, 6); } _news.Update(abc); } return(RedirectToAction("NewsAndUpdated", "Administration")); } catch (Exception e) { Commonfunction.LogError(e, Server.MapPath("~/Log.txt")); ViewBag.Exception = e.Message; return(View()); } }
public ActionResult NewsAndUpdated(string id) { if (!String.IsNullOrWhiteSpace(id)) { int _id = Convert.ToInt32(id); tbl_NewsAndUpdated model = _news.Get(_id); tbl_NewsAndUpdatedss abc = new tbl_NewsAndUpdatedss(); abc.pkid = model.pkid; abc.Title = model.Title; abc.status = model.status; abc.Description = model.Description; abc.ProfilePic = model.ProfilePic; return(View(abc)); } return(View()); }