public IActionResult Delete(int?id) { if (id == null) { return(NotFound()); } // List<Products> productsList = (from p in _db.Products // join pa in _db.ProductsAppointments on p.Id equals pa.ProductId // where pa.AppointmentId == id // select p).Include(p => p.ProductTypes).ToList(); List <Products> productsList = (from pa in _db.ProductsAppointments where pa.AppointmentId == id select pa.Products).Include(p => p.ProductTypes).ToList(); AppointmentsDetailViewModel appointmentsDetailDv = new AppointmentsDetailViewModel() { Appointments = _db.Appointments.Find(id), ApplicationUserList = _db.ApplicationUsers.ToList(), ProductsList = productsList }; return(View(appointmentsDetailDv)); }
public IActionResult Edit(int id, AppointmentsDetailViewModel appointmentsDetailDv) { if (id != appointmentsDetailDv.Appointments.Id) { return(NotFound()); } if (!ModelState.IsValid) { return(View(appointmentsDetailDv)); } Appointments appointments = _db.Appointments.Find(id); if (appointments == null) { return(NotFound()); } appointments.CustomerName = appointmentsDetailDv.Appointments.CustomerName; appointments.AppointmentDate = appointmentsDetailDv.Appointments.AppointmentDate .AddHours(appointmentsDetailDv.Appointments.AppointmentTime.Hour) .AddMinutes(appointmentsDetailDv.Appointments.AppointmentTime.Minute) .AddSeconds(appointmentsDetailDv.Appointments.AppointmentTime.Second); appointments.CustomerPhoneNumber = appointmentsDetailDv.Appointments.CustomerPhoneNumber; appointments.CustomerEmail = appointmentsDetailDv.Appointments.CustomerEmail; appointments.IsConfirmed = appointmentsDetailDv.Appointments.IsConfirmed; if (User.IsInRole(SD.SuperAdminEndUser)) { appointments.ApplicationUserId = appointmentsDetailDv.Appointments.ApplicationUserId; } _db.Appointments.Update(appointments); _db.SaveChanges(); return(RedirectToAction(nameof(Index))); }