public IHttpActionResult PutInvigilator(int id, Invigilator invigilator) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } if (id != invigilator.InvigilatorId) { return(BadRequest()); } db.Entry(invigilator).State = EntityState.Modified; try { db.SaveChanges(); } catch (DbUpdateConcurrencyException) { if (!InvigilatorExists(id)) { return(NotFound()); } else { throw; } } return(StatusCode(HttpStatusCode.NoContent)); }
public ActionResult Edit([Bind(Include = "InvigilatorId,Username,FirstName,LastName,EmailAddress,PhoneNumber")] Invigilator invigilator) { if (ModelState.IsValid) { db.Entry(invigilator).State = EntityState.Modified; db.SaveChanges(); return(RedirectToAction("Index")); } return(View(invigilator)); }
public IHttpActionResult GetInvigilator(int id) { Invigilator invigilator = db.Invigilators.Find(id); if (invigilator == null) { return(NotFound()); } return(Ok(invigilator)); }
public ActionResult Create([Bind(Include = "InvigilatorId,Username,FirstName,LastName,EmailAddress,PhoneNumber")] Invigilator invigilator) { if (ModelState.IsValid) { db.Invigilators.Add(invigilator); db.SaveChanges(); return(RedirectToAction("Index")); } return(View(invigilator)); }
public IHttpActionResult PostInvigilator(Invigilator invigilator) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } db.Invigilators.Add(invigilator); db.SaveChanges(); return(CreatedAtRoute("DefaultApi", new { id = invigilator.InvigilatorId }, invigilator)); }
public IHttpActionResult DeleteInvigilator(int id) { Invigilator invigilator = db.Invigilators.Find(id); if (invigilator == null) { return(NotFound()); } db.Invigilators.Remove(invigilator); db.SaveChanges(); return(Ok(invigilator)); }
// GET: Invigilators/Details/5 public ActionResult Details(int?id) { if (id == null) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } Invigilator invigilator = db.Invigilators.Find(id); if (invigilator == null) { return(HttpNotFound()); } return(View(invigilator)); }
public ActionResult DeleteConfirmed(int id) { Invigilator invigilator = db.Invigilators.Find(id); List <InvigilatorSession> invigSessions = db.InvigilatorSessions.Where(invigSess => invigSess.InvigilatorId == id).ToList(); foreach (var invig in invigSessions) { db.InvigilatorSessions.Remove(invig); } db.SaveChanges(); db.Invigilators.Remove(invigilator); db.SaveChanges(); return(RedirectToAction("Dashboard", "Home", null)); }
public ActionResult CreateWithSession([Bind(Include = "InvigilatorId,Username,FirstName,LastName,EmailAddress,PhoneNumber")] Invigilator invigilator) { if (ModelState.IsValid) { db.Invigilators.Add(invigilator); db.SaveChanges(); var sessionId = Convert.ToInt32(Request["SessionId"]); InvigilatorSession invigSess = new InvigilatorSession(); { invigSess.InvigilatorId = invigilator.InvigilatorId; invigSess.SessionId = sessionId; } db.InvigilatorSessions.Add(invigSess); db.SaveChanges(); var examStudents = db.ExamStudents.ToList <ExamStudent>(); var matchedId = -1; foreach (ExamStudent es in examStudents) { if (db.Exams.Find(es.ExamId).SessionId == sessionId) { matchedId = es.ExamStudentId; break; } } if (matchedId > 0) { Everything everything = new Everything(); { everything.ExamStudentId = matchedId; everything.InvigilatorSessionId = invigSess.InvigilatorSessionId; } db.Everything.Add(everything); db.SaveChanges(); } return(RedirectToAction("Index")); } return(View(invigilator)); }