public async Task <IActionResult> Edit(int id, [Bind("WorkoutTypeId,WorkoutTypeName,WorkoutTypeDescription")] WorkoutTypeViewModel model) { var workoutType = _mapper.Map <WorkoutTypeViewModel, WorkoutType>(model); if (id != workoutType.WorkoutTypeId) { return(NotFound()); } if (ModelState.IsValid) { try { _unitOfWork.WorkoutTypeRepository.Update(workoutType); await _unitOfWork.WorkoutTypeRepository.SaveAsync(); } catch (DbUpdateConcurrencyException) { if (!_unitOfWork.WorkoutTypeRepository.Exists(workoutType.WorkoutTypeId)) { return(NotFound()); } else { throw; } } return(RedirectToAction(nameof(Index))); } var workoutTypeVm = _mapper.Map <WorkoutType, WorkoutTypeViewModel>(workoutType); return(View(workoutTypeVm)); }
public async Task <IActionResult> Create([Bind("WorkoutTypeId,WorkoutTypeName,WorkoutTypeDescription")] WorkoutTypeViewModel model) { var workoutType = _mapper.Map <WorkoutTypeViewModel, WorkoutType>(model); if (ModelState.IsValid) { await _unitOfWork.WorkoutTypeRepository.AddAsync(workoutType); await _unitOfWork.WorkoutTypeRepository.SaveAsync(); return(RedirectToAction(nameof(Index))); } var workoutTypeVm = _mapper.Map <WorkoutType, WorkoutTypeViewModel>(workoutType); return(View(workoutTypeVm)); }