public ActionResult Edit([Bind(Include = "ID,FirstName,LastName")] AppointmentPerson appointmentPerson) { if (ModelState.IsValid) { db.Entry(appointmentPerson).State = EntityState.Modified; db.SaveChanges(); return(RedirectToAction("Index")); } return(View(appointmentPerson)); }
// GET: AppointmentPersons/Edit/5 public ActionResult Edit(int?id) { if (id == null) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } AppointmentPerson appointmentPerson = db.AppointmentPersons.Find(id); if (appointmentPerson == null) { return(HttpNotFound()); } return(View(appointmentPerson)); }
public ActionResult DeleteConfirmed(int id) { try { AppointmentPerson appointmentPerson = db.AppointmentPersons.Find(id); db.AppointmentPersons.Remove(appointmentPerson); db.SaveChanges(); } catch (DataException) { return(RedirectToAction("Delete", new { id = id, saveChangesError = true })); } return(RedirectToAction("Index")); }
public ActionResult Create([Bind(Include = "FirstName,LastName")] AppointmentPerson appointmentPerson) { try { if (ModelState.IsValid) { db.AppointmentPersons.Add(appointmentPerson); db.SaveChanges(); return(RedirectToAction("Index")); } } catch (DataException) { ModelState.AddModelError("", "We were unable to save changes. Please try again or contact the administrator."); } return(View(appointmentPerson)); }
// GET: AppointmentPersons/Delete/5 public ActionResult Delete(int?id, bool?saveChangesError = false) { if (id == null) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } if (saveChangesError.GetValueOrDefault()) { ViewBag.ErrorMessage = "Cannot delete. Try again or contact the administrator."; } AppointmentPerson appointmentPerson = db.AppointmentPersons.Find(id); if (appointmentPerson == null) { return(HttpNotFound()); } return(View(appointmentPerson)); }
protected override void Seed(AppointmentContext context) { var appointmentpersons = new AppointmentPerson[] { new AppointmentPerson { FirstName = "John", LastName = "Smith" }, new AppointmentPerson { FirstName = "Ann", LastName = "Willson" }, new AppointmentPerson { FirstName = "Jane", LastName = "Air" }, new AppointmentPerson { FirstName = "Ariya", LastName = "Stark" }, new AppointmentPerson { FirstName = "Dan", LastName = "Black" } }; foreach (AppointmentPerson a in appointmentpersons) { context.AppointmentPersons.Add(a); } context.SaveChanges(); var rooms = new Room[] { new Room { RoomName = "B123" }, new Room { RoomName = "G12" }, new Room { RoomName = "L41" }, new Room { RoomName = "1212" } }; foreach (Room r in rooms) { context.Rooms.Add(r); } context.SaveChanges(); var users = new User[] { new User { FirstName = "Mike", LastName = "Taranti", email = "*****@*****.**", Gender = "m", DOB = DateTime.Parse("1991-11-11") }, new User { FirstName = "Nil", LastName = "Argento", email = "*****@*****.**", Gender = "m", DOB = DateTime.Parse("1987-10-10") }, new User { FirstName = "Michael", LastName = "Basmati", email = "*****@*****.**", Gender = "m", DOB = DateTime.Parse("1977-09-09") }, new User { FirstName = "Jessika", LastName = "Alp", email = "*****@*****.**", Gender = "f", DOB = DateTime.Parse("1967-08-08") }, new User { FirstName = "Amanda", LastName = "Wane", email = "*****@*****.**", Gender = "f", DOB = DateTime.Parse("1955-07-07") } }; foreach (User u in users) { context.Users.Add(u); } context.SaveChanges(); var appointments = new List <Appointment> { new Appointment { AppointmentPersonID = appointmentpersons.Single(i => i.LastName == "Smith").ID, RoomID = rooms.Single(i => i.RoomName == "B123").ID, AppointmentDate = DateTime.Parse("2017-01-12"), AppointmentReason = "bla", UserID = users.Single(i => i.LastName == "Taranti").ID }, new Appointment { AppointmentPersonID = appointmentpersons.Single(i => i.LastName == "Willson").ID, RoomID = rooms.Single(i => i.RoomName == "G12").ID, AppointmentDate = DateTime.Parse("2017-01-01"), AppointmentReason = "got sick", UserID = users.Single(i => i.LastName == "Argento").ID }, new Appointment { AppointmentPersonID = appointmentpersons.Single(i => i.LastName == "Air").ID, RoomID = rooms.Single(i => i.RoomName == "B123").ID, AppointmentDate = DateTime.Parse("2017-12-07"), AppointmentReason = "yoyo", UserID = users.Single(i => i.LastName == "Basmati").ID }, new Appointment { AppointmentPersonID = appointmentpersons.Single(i => i.LastName == "Stark").ID, RoomID = rooms.Single(i => i.RoomName == "L41").ID, AppointmentDate = DateTime.Parse("2017-05-11"), AppointmentReason = "bla", UserID = users.Single(i => i.LastName == "Alp").ID }, new Appointment { AppointmentPersonID = appointmentpersons.Single(i => i.LastName == "Black").ID, RoomID = rooms.Single(i => i.RoomName == "1212").ID, AppointmentDate = DateTime.Parse("2017-08-01"), AppointmentReason = "12313123", UserID = users.Single(i => i.LastName == "Wane").ID } }; foreach (Appointment ap in appointments) { var appointmentDataBase = context.Appointments.Where( a => a.AppointmentPerson.ID == ap.AppointmentPersonID && a.User.ID == ap.UserID && a.Room.ID == ap.RoomID).SingleOrDefault(); if (appointmentDataBase == null) { context.Appointments.Add(ap); } } appointments.ForEach(s => context.Appointments.Add(s)); context.SaveChanges(); }