public WorkoutTest() { //sample models addWorkout = new AddWorkoutBindingModel { WorkoutId = 1, Type = "Legs", Difficulty = Difficulty.Intermediate, Time = 20 }; addExercise = new AddExerciseBindingModel { ExerciseId = 1, Name = "Squats", Picture = "https://cdn.thespaces.com/wp-content/uploads/2020/01/Gymshark-hero-crop.jpg", Sets = 20, Weight = 20, Status = Status.Completed }; mockRepo = new Mock <IRepositoryWrapper>(); WorkoutController = new WorkoutController(mockRepo.Object); ExerciseController = new ExerciseController(mockRepo.Object); }
public IActionResult CreateWorkout(AddWorkoutBindingModel bindingModel) { var workoutToCreate = new Workout { workoutTitle = bindingModel.workoutTitle, workoutDate = bindingModel.workoutDate, workoutThumbnail = bindingModel.workoutThumbnail, Client = dbContext.Clients.FirstOrDefault(c => c.ID == bindingModel.ClientID) }; dbContext.Workouts.Add(workoutToCreate); dbContext.SaveChanges(); return(RedirectToAction("Details", new { id = workoutToCreate.ID })); }
[HttpPost("create")] //sending data public IActionResult Create(AddWorkoutBindingModel bindingModel) { var workoutToCreate = new Workout { Type = bindingModel.Type, Difficulty = (Models.Difficulty)bindingModel.Difficulty, Time = bindingModel.Time, CreatedAt = DateTime.Now }; repository.Workouts.Create(workoutToCreate); //dbContext.Workouts.Add(workoutToCreate); //save changes repository.Save(); //return to action return(RedirectToAction("Index")); }