public async Task <IActionResult> Edit(int id, AppoiinmentDetailsViewModel objAppointmentVM) { if (ModelState.IsValid) { objAppointmentVM.Appointment.AppointmentDate = objAppointmentVM.Appointment.AppointmentDate .AddHours(objAppointmentVM.Appointment.AppointmentTime.Hour) .AddMinutes(objAppointmentVM.Appointment.AppointmentTime.Minute); var appointmentFromDB = _db.Appointments.Where(a => a.Id == objAppointmentVM.Appointment.Id).FirstOrDefault(); appointmentFromDB.CustomerName = objAppointmentVM.Appointment.CustomerName; appointmentFromDB.CustomerEmail = objAppointmentVM.Appointment.CustomerEmail; appointmentFromDB.CustomerPhoneNumber = objAppointmentVM.Appointment.CustomerPhoneNumber; appointmentFromDB.AppointmentDate = objAppointmentVM.Appointment.AppointmentDate; appointmentFromDB.isConfirmed = objAppointmentVM.Appointment.isConfirmed; if (User.IsInRole(SD.SuperAdminEndUser)) { appointmentFromDB.SalesPersonId = objAppointmentVM.Appointment.SalesPersonId; } _db.SaveChanges(); return(RedirectToAction(nameof(Index))); } return(View(objAppointmentVM)); }
public async Task <IActionResult> Edit(int?id) { if (id == null) { return(NotFound()); } var productList = (IEnumerable <Products>)(from p in _db.Products join a in _db.ProductsSelectedForAppointments on p.Id equals a.ProductId where a.AppointmentId == id select p).Include("ProductTypes"); AppoiinmentDetailsViewModel objAppointmentVM = new AppoiinmentDetailsViewModel() { Appointment = _db.Appointments.Include(a => a.SalesPerson).Where(a => a.Id == id).FirstOrDefault(), SalesPerson = _db.ApplicationUser.ToList(), Products = productList.ToList() }; return(View(objAppointmentVM)); }