public IActionResult Post([FromBody] ExerciseCreateDto exerciseCreateDto) { var userIdString = User.FindFirst(ClaimTypes.Name)?.Value; var userId = int.Parse(userIdString); exerciseCreateDto.UserId = userId; var validationResult = _exerciseCreateDtoValidator.Validate(exerciseCreateDto); if (!validationResult.IsValid) return BadRequest(ValidationHelpers.ConvertValidationResult(validationResult)); var exercise = _exerciseRepository.CreateExercise(exerciseCreateDto); return Created($"api/exercise/{exercise.Id}", exercise); }
public async Task <IActionResult> AddNewExercise(ExercisesViewModel model) { Exercise exercise = new Exercise { Name = model.Name, CalorieBySet = model.CalorieBySet, //GifPicture = model.GifPicture, Category = model.Category }; if (model.GifPicture != null && model.GifPicture.Length > 0) { using (var memoryStream = new MemoryStream()) { await model.GifPicture.CopyToAsync(memoryStream); exercise.GifPicture = memoryStream.ToArray(); } } _exerciseRepository.CreateExercise(exercise); return(RedirectToAction("Exercises", "Home")); }
public Task <Exercise> Handle(CreateExercise request, CancellationToken cancellationToken) { return(_exerciseRepo.CreateExercise(request.Exercise, request.Definition)); }