public async Task CreateExerciseAsync(ExerciseCreateBindingModel model, string username) { CoreValidator.ThrowIfNull(model); var user = await this.GetUserByNamedAsync(username); var exercise = this.Mapper.Map <Exercise>(model); user.Exercises.Add(exercise); await this.DbContext.SaveChangesAsync(); }
public async Task CreateExerciseAsync_WithValidModel_ShouldCreateExercise() { var model = new ExerciseCreateBindingModel() { Name = exerciseName }; await this.service.CreateExerciseAsync(model, MockUserManager.testUsername); Assert.AreEqual(1, this.dbContext.Exercises.Count()); }
public async Task <IActionResult> Create(ExerciseCreateBindingModel model, string redirectUrl = null) { if (!this.ModelState.IsValid) { return(this.View()); } await this.exercisesService.CreateExerciseAsync(model, this.User.Identity.Name); if (!string.IsNullOrWhiteSpace(redirectUrl)) { return(Redirect(redirectUrl)); } return(this.RedirectToAction(ActionConstants.Index, ControllerConstants.Exercises)); }