// GET-Update public IActionResult Update(int?id) { if (id == null || id == 0) { return(NotFound()); } var appointment = _db.Appointments.Find(id); if (appointment == null) { return(NotFound()); } AppointmentDropDownVM newAppointmentVM = new AppointmentDropDownVM() { Appointment = appointment, BrokerDropDown = _db.Brokers.Select(broker => new SelectListItem { Text = broker.Lastname + " " + broker.Firstname, Value = broker.Id.ToString() }), CustomerDropDown = _db.Customers.Select(customer => new SelectListItem { Text = customer.Lastname + " " + customer.Firstname, Value = customer.Id.ToString() }) }; return(View(newAppointmentVM)); }
public IActionResult Create(AppointmentDropDownVM appointmentVM) { if (ModelState.IsValid) { _db.Appointments.Add(appointmentVM.Appointment); _db.SaveChanges(); TempData["modifiedId"] = appointmentVM.Appointment.Id; TempData["modification"] = "create"; Customer customer = _db.Customers.FirstOrDefault(c => c.Id == appointmentVM.Appointment.IdCustomer); TempData["customerName"] = customer.Firstname + " " + customer.Lastname; TempData["dateTime"] = appointmentVM.Appointment.DateHour; return(RedirectToAction("Index")); } return(View(appointmentVM.Appointment)); }