public ActionResult Edit([Bind(Include = "admin_ID,staff_ID,userName,userPassword,superAdmin")] Admin admin) { if (Session["isSuperAdmin"]?.ToString() != null) { if (ModelState.IsValid) { db.Entry(admin).State = EntityState.Modified; db.SaveChanges(); if (Session["isSuperAdmin"]?.ToString() == "True") { return(RedirectToAction("Index")); } else { return(RedirectToAction("Edit", "Home")); } } ViewBag.staff_ID = new SelectList(db.Staffs, "staff_ID", "firstName", admin.staff_ID); return(View(admin)); } else { return(RedirectToAction("Index", "Home")); } }
public ActionResult Save([Bind(Include = "page_ID,pageName,pageDesc,content")] Page page) { if (Session["userName"]?.ToString() != null) { //Remove new lines from the html page.content = page.content.Replace("\n", ""); //Split the data at > characters so we can trim out all of the unnecessary spacing. //Using Regular expressions so we can keep the > characters, and because it is very fast. string[] splitData = Regex.Split(page.content, @"(?<=[>])"); page.content = ""; foreach (string part in splitData) { page.content += part.Trim(' '); } if (ModelState.IsValid) { db.Entry(page).State = EntityState.Modified; db.SaveChanges(); } return(RedirectToAction("Edit", "Program")); } else { return(RedirectToAction("Program", "Program")); } }
public ActionResult Edit([Bind(Include = "staff_ID,firstName,lastName,jobTitle,position,foundation,email,active,imageName")] Staff staff) { if (Session["isSuperAdmin"]?.ToString() != null) { if (ModelState.IsValid) { db.Entry(staff).State = EntityState.Modified; db.SaveChanges(); Admin admin = db.Admins.Find(Int32.Parse(Session["adminID"]?.ToString())); Staff currentStaff = admin.Staff; if (currentStaff.staff_ID == staff.staff_ID) { Session["imageSrc"] = staff.imageName; } return(RedirectToAction("Index")); } return(View(staff)); } else { return(RedirectToAction("Index", "Home")); } }
public ActionResult Edit([Bind(Include = "page_ID,pageName,pageDesc,content")] Page page) { if (ModelState.IsValid) { db.Entry(page).State = EntityState.Modified; db.SaveChanges(); return(RedirectToAction("Index")); } return(View(page)); }
public ActionResult Edit([Bind(Include = "donor_ID,donorName,donorLevel,donorYear,phone,email,active")] Donor donor) { if (Session["isSuperAdmin"]?.ToString() != null) { if (ModelState.IsValid) { db.Entry(donor).State = EntityState.Modified; db.SaveChanges(); return(RedirectToAction("Index")); } return(View(donor)); } else { return(RedirectToAction("Index", "Home")); } }
public ActionResult Edit([Bind(Include = "event_ID,eventName,eventDate,eventTime,eventLocation,eventDetails,active")] Event @event) { if (Session["isSuperAdmin"]?.ToString() != null) { if (ModelState.IsValid) { db.Entry(@event).State = EntityState.Modified; db.SaveChanges(); return(RedirectToAction("Index")); } return(View(@event)); } else { return(RedirectToAction("Index", "Home")); } }
public ActionResult Edit([Bind(Include = "story_ID,storyTitle,storyName,storyContent,active")] Story story) { if (Session["isSuperAdmin"]?.ToString() != null) { if (ModelState.IsValid) { db.Entry(story).State = EntityState.Modified; db.SaveChanges(); return(RedirectToAction("Index")); } return(View(story)); } else { return(RedirectToAction("Index", "Home")); } }
protected void Application_Error(Object sender, EventArgs e) { var raisedException = Server.GetLastError(); // Process exception YFUTEntities db = new YFUTEntities(); Error error = new Error(); if (Session["userName"]?.ToString() != null) { string userName = Session["userName"]?.ToString(); error.admin_ID = db.Admins.Where(a => a.userName == userName).ToList()[0].admin_ID; } error.errorDate = DateTime.Now; error.errorDesc = raisedException.Message; db.Errors.Add(error); db.Entry(error).State = EntityState.Added; db.SaveChanges(); //Disabled so that custom error pages will run //Server.ClearError(); }
public ActionResult DeleteConfirmed(string file) { if (Session["isSuperAdmin"]?.ToString() == "True") { if (System.IO.File.Exists(Path.Combine(Server.MapPath("~/Content/profileImages"), file))) { System.IO.File.Delete(Path.Combine(Server.MapPath("~/Content/profileImages"), file)); //find the currently logged in staff member Admin admin = db.Admins.Find(Int32.Parse(Session["adminID"]?.ToString())); Staff staff = admin.Staff; List <Staff> staffMembers = db.Staffs.Where(s => s.imageName == file).ToList(); foreach (Staff curStaff in staffMembers) { curStaff.imageName = "default.png"; //Change their profile image if (curStaff == staff) { Session["imageSrc"] = ""; } if (ModelState.IsValid) { db.Entry(curStaff).State = EntityState.Modified; db.SaveChanges(); } } } return(RedirectToAction("Index")); } else if (Session["isSuperAdmin"]?.ToString() == "False") { Admin admin = db.Admins.Find(Int32.Parse(Session["adminID"]?.ToString())); Staff staff = admin.Staff; if (file == staff.imageName) { if (System.IO.File.Exists(Path.Combine(Server.MapPath("~/Content/profileImages"), file))) { System.IO.File.Delete(Path.Combine(Server.MapPath("~/Content/profileImages"), file)); staff.imageName = "default.png"; Session["imageSrc"] = ""; if (ModelState.IsValid) { db.Entry(staff).State = EntityState.Modified; db.SaveChanges(); } } } return(RedirectToAction("Index")); } else { return(RedirectToAction("Index", "Home")); } }