Esempio n. 1
0
        /// <summary>
        /// Changes restrictions for every member in team (excluding manager)
        /// </summary>
        /// <param name="userRestrictions">New user restrictions</param>
        /// <param name="managerId">ID of manager whose team will have restrictions changed</param>
        /// <exception cref="EntityNotFoundException">When user with <paramref name="managerId"/> ID is not found</exception>
        public void ChangeTeamRestrictions(UserRestrictions userRestrictions, int managerId)
        {
            User teamManager = usersDao.SelectByID(managerId);

            if (teamManager == null)
            {
                throw new EntityNotFoundException($"User with ID {managerId} was not found", typeof(User));
            }

            usersDao.UpdateTeamRestrictions(userRestrictions, managerId);
        }
 public void UpdateGlobalRestrictions(UserRestrictions restrictions)
 {
     using (var db = new DbContext())
     {
         db.Connection.Execute("UPDATE Users SET " +
                               "ConsecLimit = @Consec, " +
                               "MonthlyLimit = @Monthly, " +
                               "YearlyLimit = @Yearly, " +
                               "QuarterLimit = @Quarter",
                               new { Consec  = restrictions.ConsecLimit,
                                     Monthly = restrictions.MonthlyLimit,
                                     Yearly  = restrictions.YearlyLimit,
                                     Quarter = restrictions.QuarterLimit });
     }
 }
 public void UpdateTeamRestrictions(UserRestrictions restrictions, int managerId)
 {
     using (var db = new DbContext())
     {
         db.Connection.Execute("UPDATE Users SET " +
                               "ConsecLimit = @Consec, " +
                               "MonthlyLimit = @Monthly, " +
                               "YearlyLimit = @Yearly, " +
                               "QuarterLimit = @Quarter " +
                               "WHERE ManagerId = @ManagerId",
                               new { Consec    = restrictions.ConsecLimit,
                                     Monthly   = restrictions.MonthlyLimit,
                                     Yearly    = restrictions.YearlyLimit,
                                     Quarter   = restrictions.QuarterLimit,
                                     ManagerId = managerId });
     }
 }
Esempio n. 4
0
        /// <summary>
        /// Calls data access to update user's restrictions
        /// </summary>
        /// <param name="userRestrictions">Modified user restrictions</param>
        /// <param name="userId">ID to lookup a user and modify</param>
        /// <returns>User instance with updated restrictions</returns>
        /// <exception cref="EntityNotFoundException">When user with ID <paramref name="userId"/> is not found</exception>
        public User ChangeRestrictions(UserRestrictions userRestrictions, int userId)
        {
            User userToUpdate = usersDao.SelectByID(userId);

            if (userToUpdate == null)
            {
                throw new EntityNotFoundException($"User with ID {userId} was not found", typeof(User));
            }

            userToUpdate.ConsecLimit  = userRestrictions.ConsecLimit;
            userToUpdate.MonthlyLimit = userRestrictions.MonthlyLimit;
            userToUpdate.YearlyLimit  = userRestrictions.YearlyLimit;
            userToUpdate.QuarterLimit = userRestrictions.QuarterLimit;

            usersDao.UpdateUser(userToUpdate);
            return(userToUpdate);
        }
        public void ChangeRestrictions_ShouldReturnUpdatedUser(int userId, int consecLimit, int monthlyLimit, int yearlyLimit)
        {
            var expectedUser = GetUserById(userId);

            expectedUser.ConsecLimit  = consecLimit;
            expectedUser.MonthlyLimit = monthlyLimit;
            expectedUser.YearlyLimit  = yearlyLimit;
            var daoMock             = new Mock <IUsersDao>(MockBehavior.Strict);
            var newUserRestrictions = new UserRestrictions {
                ConsecLimit = consecLimit, MonthlyLimit = monthlyLimit, YearlyLimit = yearlyLimit
            };

            daoMock.Setup(x => x.UpdateUser(expectedUser))
            .Verifiable("UpdateUserAsync method was not called with expected arguments");
            daoMock.Setup(x => x.SelectByID(It.IsAny <int>()))
            .Returns <int>(id => GetUserById(id));
            var sut    = new UserLogic(daoMock.Object, null, null);
            var actual = sut.ChangeRestrictions(newUserRestrictions, userId);

            Assert.IsTrue(UsersAreEqual(expectedUser, actual));
            daoMock.Verify(x => x.UpdateUser(expectedUser), Times.Once);
        }
 public async Task SaveUserRestriction(UserRestrictions user)
 {
     await _userRestrictionRepository.Add(user);
 }
 public async Task Add(UserRestrictions userRestriction)
 {
     _context.UserRestrictions.Add(userRestriction);
 }
 public async Task SaveUserRestriction(UserRestrictions user)
 {
     var userWithLessOffer = new UserWithLessOffer();
     await _userRestrictionRepository.Add(userWithLessOffer);
 }
Esempio n. 9
0
 /// <summary>
 /// Changes restrictions for every user
 /// </summary>
 /// <param name="userRestrictions">New user restrictions</param>
 public void ChangeGlobalRestrictions(UserRestrictions userRestrictions)
 {
     usersDao.UpdateGlobalRestrictions(userRestrictions);
 }
Esempio n. 10
0
 public IHttpActionResult ChangeTeamRestrictions([FromBody] UserRestrictions userRestrictions, int managerId)
 {
     userLogic.ChangeTeamRestrictions(userRestrictions, managerId);
     return(ResponseMessage(Request.CreateResponse(HttpStatusCode.NoContent)));
 }
Esempio n. 11
0
 public IHttpActionResult ChangeGlobalRestrictions([FromBody] UserRestrictions userRestrictions)
 {
     userLogic.ChangeGlobalRestrictions(userRestrictions);
     return(ResponseMessage(Request.CreateResponse(HttpStatusCode.NoContent)));
 }
Esempio n. 12
0
 public IHttpActionResult ChangeRestrictions([FromBody] UserRestrictions userRestrictions, int userId)
 {
     return(Ok(userLogic.ChangeRestrictions(userRestrictions, userId)));
 }