public ActionResult CreateNews(PublicRelation publicRelation) { if (ModelState.IsValid) { if (publicRelation.image2 != null) { string fileName = Path.GetFileNameWithoutExtension(publicRelation.image2.FileName); string extension = Path.GetExtension(publicRelation.image2.FileName); fileName = fileName + "_" + DateTime.Now.ToString("ddMMyy_HHmmss") + extension; publicRelation.image = "/ImagePublicRelation/" + fileName; fileName = Path.Combine(Server.MapPath("~/ImagePublicRelation/"), fileName); publicRelation.image2.SaveAs(fileName); } if (publicRelation.docUpload2 != null) { var fileNameDoc = Path.GetFileNameWithoutExtension(publicRelation.docUpload2.FileName); string extension2 = Path.GetExtension(publicRelation.docUpload2.FileName); fileNameDoc = fileNameDoc + "_" + DateTime.Now.ToString("ddMMyy_HHmmss") + extension2; publicRelation.docUpload = "/docUploadPublicRelation/" + fileNameDoc; var path = Path.Combine(Server.MapPath("~/docUploadPublicRelation/"), fileNameDoc); publicRelation.docUpload2.SaveAs(path); } publicRelation.views = 0; db.PublicRelation.Add(publicRelation); db.SaveChanges(); ModelState.Clear(); return(RedirectToAction("CreateSuccessMessage")); } return(View(publicRelation)); }
public ActionResult DeleteNewsConfirm(int id) { PublicRelation publicRelation = db.PublicRelation.Find(id); db.PublicRelation.Remove(publicRelation); db.SaveChanges(); return(RedirectToAction("AllNews")); }
public ActionResult News(int id) { PublicRelation publicRelation = db.PublicRelation.Find(id); if (publicRelation == null) { return(RedirectToAction("AllNews")); } //--Page Visitor publicRelation.views = publicRelation.views + 1; db.Entry(publicRelation).State = EntityState.Modified; db.SaveChanges(); return(View(publicRelation)); }
public ActionResult CreateNews(PublicRelation publicRelation) { if (ModelState.IsValid) { publicRelation.Creator = Session["Name"].ToString(); publicRelation.Date = DateTime.Today; publicRelation.DataIsActive = true; db.PublicRelation.Add(publicRelation); db.SaveChanges(); ModelState.Clear(); return(RedirectToAction("Index", "Home")); } return(View(publicRelation)); }
public ActionResult EditNews(int id) { if (Session["Role"] != null) { if (Session["Role"].Equals("Admin")) { PublicRelation publicRelation = db.PublicRelation.Find(id); if (publicRelation == null) { return(RedirectToAction("AllNews")); } return(View(publicRelation)); } return(RedirectToAction("Index", "Home")); } else { return(RedirectToAction("Index", "Home")); } }