public ActionResult DeleteConfirmed(int id, audit_trail audit) { var check = db.bookings.Where(s => s.Booking_Type_ID == id).FirstOrDefault(); if (check == null) { booking_type booking_type = db.booking_type.Find(id); var userId = System.Web.HttpContext.Current.Session["UserID"] as String; int IntID = Convert.ToInt32(userId); audit.Employee_ID = IntID; audit.Trail_DateTime = DateTime.Now.Date; audit.Deleted_Record = booking_type.Booking_Type_ID.ToString() + " " + booking_type.Booking_Type_Name + " " + booking_type.Booking_Type_Description; audit.Trail_Description = "Deleted a Booking Type"; db.audit_trail.Add(audit); db.booking_type.Remove(booking_type); db.SaveChanges(); return(RedirectToAction("Index")); } else { booking_type booking_type = db.booking_type.Find(id); ViewBag.Error = "Can't delete a type that is in-use please add a new type instead, or delete all bookings related to this type first."; return(View(booking_type)); } }
public ActionResult DeleteConfirmed(int id) { booking_type booking_type = db.booking_type.Find(id); db.booking_type.Remove(booking_type); db.SaveChanges(); return(RedirectToAction("Index")); }
public ActionResult Edit([Bind(Include = "Booking_Type_ID,Booking_Type_Name,Booking_Type_Description")] booking_type booking_type) { if (ModelState.IsValid) { db.Entry(booking_type).State = EntityState.Modified; db.SaveChanges(); return(RedirectToAction("Index")); } return(View(booking_type)); }
public ActionResult Create([Bind(Include = "Booking_Type_ID,Booking_Type_Name,Booking_Type_Description")] booking_type booking_type) { if (ModelState.IsValid) { db.booking_type.Add(booking_type); db.SaveChanges(); return(RedirectToAction("Index")); } return(View(booking_type)); }
// GET: booking_type/Delete/5 public ActionResult Delete(int?id) { if (id == null) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } booking_type booking_type = db.booking_type.Find(id); if (booking_type == null) { return(HttpNotFound()); } return(View(booking_type)); }
public ActionResult Edit([Bind(Include = "Booking_Type_ID,Booking_Type_Name,Booking_Type_Description")] booking_type booking_type) { bool val = db.booking_type.Any(s => s.Booking_Type_Name == booking_type.Booking_Type_Name && s.Booking_Type_ID != booking_type.Booking_Type_ID); if (ModelState.IsValid && val == false) { db.Entry(booking_type).State = EntityState.Modified; db.SaveChanges(); return(RedirectToAction("Index")); } else if (val == true) { ViewBag.StatusMessage = "There is already an: " + booking_type.Booking_Type_Name + " type in the database."; return(View()); } return(View(booking_type)); }
public ActionResult Create([Bind(Include = "Booking_Type_ID,Booking_Type_Name,Booking_Type_Description")] booking_type booking_type) { bool val = Validate(booking_type.Booking_Type_Name); if (ModelState.IsValid && val == false) { db.booking_type.Add(booking_type); db.SaveChanges(); return(RedirectToAction("Index")); } else if (val == true) { ViewBag.StatusMessage = "There is already an: " + booking_type.Booking_Type_Name + " type in the database."; return(View()); } return(View(booking_type)); }