public async Task <ActionResult <Exercise> > PostExercise([FromBody] ExerciseResource exerciseResource) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } //Check for duplicate /*Exercise duplicate = await _context.Exercises.SingleOrDefaultAsync(e => e.Name == exerciseResource.Name); * if (duplicate != null) * { * //return Conflict(duplicate); * return Conflict(); * }*/ var exercise = mapper.Map <ExerciseResource, Exercise> (exerciseResource); string userId = GetUserId(); exercise.UserId = userId; repository.Add(exercise); await unitOfWork.CompleteAsync(); return(CreatedAtAction("GetExercise", new { id = exercise.ExerciseId }, exercise)); }
public void Create(Exercise exercise) { exerciseRepository.Add(exercise); exerciseRepository.Save(); }