public void UpdateMonthlyWorkout(int id, MonthlyWorkout updatedMonthlyWorkout) { updatedMonthlyWorkout.Id = id; _context.Entry(updatedMonthlyWorkout).State = EntityState.Modified; updatedMonthlyWorkout.WeekOne = _context.WeeklyWorkouts .Where(w => w.Id == updatedMonthlyWorkout.WeekOne.Id).SingleOrDefault(); updatedMonthlyWorkout.WeekTwo = _context.WeeklyWorkouts .Where(w => w.Id == updatedMonthlyWorkout.WeekTwo.Id).SingleOrDefault(); updatedMonthlyWorkout.WeekThree = _context.WeeklyWorkouts .Where(w => w.Id == updatedMonthlyWorkout.WeekThree.Id).SingleOrDefault(); updatedMonthlyWorkout.WeekFour = _context.WeeklyWorkouts .Where(w => w.Id == updatedMonthlyWorkout.WeekFour.Id).SingleOrDefault(); try { _context.SaveChanges(); } catch (DbUpdateConcurrencyException e) { // Létezett-e egyáltalán var _ = _context.MonthlyWorkouts.AsNoTracking().SingleOrDefault(p => p.Id == id) ?? throw new EntityNotFoundException("Nem található az edzés"); throw; } }
public void UpdateMonthlyWorkout() { //Arrange _testWorkout = _monthWorkoutService.GetMonthlyWorkouts(_testUser).FirstOrDefault(); //Act _testWorkout.Name = "Ultra kemény királyság"; _monthWorkoutService.UpdateMonthlyWorkout(_testWorkout.Id, _testWorkout); //Assert Assert.AreEqual(_monthWorkoutService .GetMonthlyWorkout(_testWorkout.Id, _testUser).Name, "Ultra kemény királyság"); }
public void InsertMotnhlyWorkout() { //Arrange var saveInstance = new MonthlyWorkout() { Name = "TestMonthly", WeekFour = _testWeeklyWorkout, WeekOne = _testWeeklyWorkout, WeekThree = _testWeeklyWorkout, WeekTwo = _testWeeklyWorkout }; //Act _testWorkout = _monthWorkoutService.InsertMonthlyWorkout(saveInstance, _testUser); //Asser Assert.IsFalse(_monthWorkoutService.GetMonthlyWorkouts(_testUser).Count() != 1); }
public MonthlyWorkout InsertMonthlyWorkout(MonthlyWorkout newMonthlyWorkout, ApplicationUser user) { var saveInstance = new MonthlyWorkout() { Name = newMonthlyWorkout.Name }; saveInstance.WeekOne = _context.WeeklyWorkouts .Where(w => w.Id == newMonthlyWorkout.WeekOne.Id).SingleOrDefault(); saveInstance.WeekTwo = _context.WeeklyWorkouts .Where(w => w.Id == newMonthlyWorkout.WeekTwo.Id).SingleOrDefault(); saveInstance.WeekThree = _context.WeeklyWorkouts .Where(w => w.Id == newMonthlyWorkout.WeekThree.Id).SingleOrDefault(); saveInstance.WeekFour = _context.WeeklyWorkouts .Where(w => w.Id == newMonthlyWorkout.WeekFour.Id).SingleOrDefault(); saveInstance.UserID = user.Id; user.MonthlyWorkouts.Add(saveInstance); _context.MonthlyWorkouts.Add(saveInstance); _context.SaveChanges(); return(saveInstance); }
public void DeleteMonthlyWorkout() { //Arrange var saveInstance = new MonthlyWorkout() { Name = "TestMonthly", WeekFour = _testWeeklyWorkout, WeekOne = _testWeeklyWorkout, WeekThree = _testWeeklyWorkout, WeekTwo = _testWeeklyWorkout }; _testWorkout = _monthWorkoutService.InsertMonthlyWorkout(saveInstance, _testUser); //Act var countBefore = _monthWorkoutService.GetMonthlyWorkouts(_testUser).Count(); _monthWorkoutService .DeleteMonthlyWorkout(_testWorkout.Id, _testUser); var countAfter = _monthWorkoutService.GetMonthlyWorkouts(_testUser).Count(); //Assert Assert.AreNotEqual(countAfter, countBefore); }
public IActionResult Put(int id, [FromBody] MonthlyWorkout monthlyWorkout) { _monthlyWorkoutService.UpdateMonthlyWorkout(id, monthlyWorkout); return(NoContent()); }
public IActionResult Post([FromBody] MonthlyWorkout monthlyWorkout) { var created = _monthlyWorkoutService.InsertMonthlyWorkout(monthlyWorkout, _user); return(CreatedAtAction(nameof(Get), new { created.Id }, created)); }