public async Task <bool> Add(TrainingForAddDto trainingForAddDto, int userId) { var user = await _repoUser.GetUser(userId); var trainingToCreate = Training.Create(trainingForAddDto.Name.Trim(), trainingForAddDto.Date, user); foreach (var trainingExerciseDto in trainingForAddDto.Exercises) { var exercise = await _repoExercise.GetByName(trainingExerciseDto.Exercise.Name, user.Id); if (exercise == null) { _repoExercise.Add(Exercise.Create(trainingExerciseDto.Exercise.Name, user)); await _repoExercise.SaveAll(); exercise = await _repoExercise.GetByName(trainingExerciseDto.Exercise.Name, user.Id); } var exerciseToCreate = TrainingExercise.Create(exercise, user); foreach (var set in trainingExerciseDto.Sets) { var unit = await _repoUnit.GetByCode(set.Unit); var setToCreate = TrainingExerciseSet.Create(set.Reps, set.Weight, unit, user); exerciseToCreate.Sets.Add(setToCreate); } trainingToCreate.Exercises.Add(exerciseToCreate); } _repoTraining.Add(trainingToCreate); return(await _repoTraining.SaveAll()); }
//[Authorize] public async Task <IActionResult> AddExercise(ExerciseForCreationDto exerciseForCreationDto) { var exerciseToReturn = _mapper.Map <Exercise>(exerciseForCreationDto); exerciseToReturn.Subject = await _subjectRepository.GetSubjectByIdAsync(exerciseForCreationDto.SubjectId); _exerciseRepository.Add <Exercise>(exerciseToReturn); await _exerciseCategoriesRepository.SaveAll(); // Add categories to exercise var id = exerciseToReturn.Id; foreach (var categoryId in exerciseForCreationDto.CategoriesIds) { var exerciseCategory = new ExerciseCategory { ExerciseId = id, CategoryId = categoryId }; _exerciseCategoriesRepository.Add <ExerciseCategory>(exerciseCategory); } if (await _exerciseCategoriesRepository.SaveAll()) { var exerciseToReturnDto = _mapper.Map <ExerciseDto>(exerciseToReturn); return(CreatedAtRoute("GetExercise", new { exerciseToReturn.Id }, exerciseToReturnDto)); } throw new Exception("Nie udało się dodać zadania"); }
private Exercise CreateNewExercise() { var exercise = new Exercise(); _exerciseRepository.Add(exercise); return(exercise); }
private async Task AddExercise(string exerciseName, IExerciseRepository repo, DataContext context) { var exercise = Exercise.Create(exerciseName, await GetUser(context)); repo.Add(exercise); await repo.SaveAll(); }
public void Handle(AddExerciseCommand command) { var dataModel = new ExerciseDocument { Description = command.Description, ExerciseType = command.Type }; _exerciseRepository.Add(new Exercise(dataModel)); }
public async Task <IActionResult> Post( Guid groupId, [FromBody] ExerciseUpdateApi exerciseUpdate) { var exercise = new Exercise() { Id = Guid.NewGuid(), Name = exerciseUpdate.Name, Note = exerciseUpdate.Note }; await _exerciseRepository.Add(exercise, groupId); return(CreatedAtRoute("GetExercise", new { Controller = "Exercise", groupId, id = exercise.Id }, new ExerciseApi { Id = exercise.Id, Name = exercise.Name, Note = exercise.Note })); }
public async Task <NewExerciseResponse> AddExerciseAsync(NewExerciseRequest request) { var exercise = exerciseRepository.Add(new Entities.Exercise { UserId = request.UserId, Date = request.Date, Duration = TimeSpan.FromMinutes(request.Duration), Description = request.Description }); await exerciseRepository.UnitOfWork.SaveChangesAsync(); return(new NewExerciseResponse { _id = exercise.UserId, Username = (await userRepository.GetUserAsync(exercise.UserId)).UserName, Date = exercise.Date.ToUniversalTime().ToString("D"), Duration = exercise.Duration.TotalMinutes, Description = exercise.Description }); }
public JsonResult Create(Exercise exercise) { _repository.Add(exercise); return(Json("success", JsonRequestBehavior.AllowGet)); }
public ActionResult Create(ExerciseModel exerciseModel) { _exerciseRepository.Add(exerciseModel); return(RedirectToAction(nameof(Create))); }
public Exercise Add(Exercise newExercise) { return(_exerciseRepository.Add(newExercise)); }
public ActionResult <Exercise> Create([FromBody] Exercise exercise) { ExerciseRepository.Add(exercise); return(CreatedAtAction(nameof(Create), new { exercise.ID }, exercise)); }