public ActionResult DeleteSaved(int?id) { SavedPosting saved = db.SavedPostings.Find(id); db.SavedPostings.Remove(saved); db.SaveChanges(); return(RedirectToAction("Index")); }
//create controller public ActionResult SavePosting(int id) { if (id == null) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } Posting posting = db.Postings .Where(p => p.ID == id) .SingleOrDefault(); Applicant q = db.Applicants .Where(p => p.EMail == User.Identity.Name) .SingleOrDefault(); if (posting == null) { ModelState.AddModelError("", "Something went wrong"); return(RedirectToAction("Index", "Home")); } if (q == null) { ModelState.AddModelError("", "You need to login First"); return(RedirectToAction("Login", "Account")); } var savePost = new SavedPosting() { PostingID = posting.ID, Applicant = q, Postings = posting, ApplicantID = q.ID }; return(View("SavePosting", savePost)); }
public ActionResult SavePosting([Bind(Include = "ID,ApplicantID,PostingID")] SavedPosting savePosting) { try { if (ModelState.IsValid) { db.SavedPostings.Add(savePosting); db.SaveChanges(); return(RedirectToAction("Index", "Portfolio")); } } catch (RetryLimitExceededException /* dex */) { ModelState.AddModelError("", "Unable to save changes after multiple attempts. Try again, and if the problem persists, see your system administrator."); } catch (DataException) { ModelState.AddModelError("", "Unable to save changes. Try again, and if the problem persists see your system administrator."); } return(View(savePosting)); }