Пример #1
0
        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));
        }
Пример #2
0
 public void Create(Exercise exercise)
 {
     exerciseRepository.Add(exercise);
     exerciseRepository.Save();
 }