public async Task <IActionResult> Edit(int?id, EditGymClassViewModel viewModel) { if (id != viewModel.Id) { return(NotFound()); } if (ModelState.IsValid) { var gymClass = mapper.Map <GymClass>(viewModel); try { db.Update(gymClass); await db.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!GymClassExists(viewModel.Id)) { return(NotFound()); } else { throw; } } return(RedirectToAction(nameof(Index))); } return(View(viewModel)); }
public async Task <IActionResult> Edit(int id, EditGymClassViewModel viewModel) { if (id != viewModel.Id) { return(NotFound()); } if (ModelState.IsValid) { var gymClass = Mapper.Map <GymClass>(viewModel); try { UnitOfWork.GymClassRepository.Update(gymClass); await UnitOfWork.CompleteAsync(); } catch (DbUpdateConcurrencyException) { if (!GymClassExists(viewModel.Id)) { return(NotFound()); } else { throw; } } return(RedirectToAction(nameof(Index))); } return(View(viewModel)); }
public async Task <IActionResult> Edit(int?id) { var gymClass = await unitOfWork.GymClassRepository.GetAsync(id); if (gymClass == null) { return(NotFound()); } var viewModel = new EditGymClassViewModel { Id = gymClass.Id, Name = gymClass.Name, StartDate = gymClass.StartDate, Duration = gymClass.Duration, Description = gymClass.Description }; return(View(viewModel)); }