コード例 #1
0
        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;
            }
        }
コード例 #2
0
        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");
        }
コード例 #3
0
        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);
        }
コード例 #4
0
        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);
        }
コード例 #5
0
        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);
        }
コード例 #6
0
 public IActionResult Put(int id, [FromBody] MonthlyWorkout monthlyWorkout)
 {
     _monthlyWorkoutService.UpdateMonthlyWorkout(id, monthlyWorkout);
     return(NoContent());
 }
コード例 #7
0
        public IActionResult Post([FromBody] MonthlyWorkout monthlyWorkout)
        {
            var created = _monthlyWorkoutService.InsertMonthlyWorkout(monthlyWorkout, _user);

            return(CreatedAtAction(nameof(Get), new { created.Id }, created));
        }