// GET: Staff/Delete/5 public ActionResult Delete(int?id) { BookingsModel.Staff staff = db.Staffs.Find(id); if (staff == null) // if its not hthere { return(HttpNotFound()); //throw error } return(View(staff));//oftherwise through the view. }
// GET: Staff/Edit/5 public ActionResult Edit(int id) { if (id == 0) //if ID is equal to null. { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); //reutnr with error } BookingsModel.Staff staff = db.Staffs.Find(id); //find the specified Staff. if (staff == null) // if its not hthere { return(HttpNotFound()); //throw error } return(View(staff));//oftherwise through the view. }
public ActionResult Edit(BookingsModel.Staff staff) { try { if (ModelState.IsValid) { staff.Active = true; } db.Entry(staff).State = System.Data.Entity.EntityState.Modified; db.SaveChanges(); return(RedirectToAction("Index")); } catch { return(View(staff)); } }
public ActionResult Create(BookingsModel.Staff staff) { try { if (ModelState.IsValid) //if model state is active/. { staff.Active = true; //I have set active so what sstaff are created its shows in the view . } db.Staffs.Add(staff); //create the bu in the database db.SaveChanges(); //save the changes. return(RedirectToAction("Index")); //retur nto index } catch { return(View(staff)); } }
public ActionResult Delete(int id, FormCollection collection) { if (id == 0) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); // displays error message is not existant } try { BookingsModel.Staff staff = db.Staffs.Find(id); staff.Active = false; db.Entry(staff).State = System.Data.Entity.EntityState.Modified; db.SaveChanges(); return(RedirectToAction("Index")); } catch { return(View()); } }