Esempio n. 1
0
 /// <summary>
 /// AddUserPermission is a method in the UserService class.
 /// Adds a permission to a specific user.
 /// </summary>
 /// <param name="user">The user who we will be adding a permission to</param>
 /// <param name="role">The permission we will be adding to a user</param>
 public void AddUserRole(int userId, DataAccessLayer.Enums.RoleEnum role)
 {
     _dbContext.UserRoles.Add(new UserRole()
     {
         UserId      = userId,
         RoleId      = role,
         IsEnabled   = true,
         DateCreated = DateTime.UtcNow,
     });
 }
Esempio n. 2
0
        public void RemoveUserRole(int userId, DataAccessLayer.Enums.RoleEnum role)
        {
            var userRoleEntity = _dbContext.UserRoles
                                 .Where(o => o.UserId == userId && o.RoleId == role)
                                 .FirstOrDefault();

            if (userRoleEntity != null)
            {
                _dbContext.UserRoles.Remove(userRoleEntity);
            }
        }
Esempio n. 3
0
 public bool HasUserRole(int userId, DataAccessLayer.Enums.RoleEnum role)
 {
     return(_dbContext.UserRoles.Where(o => o.UserId == userId && o.RoleId == role).Any());
 }
Esempio n. 4
0
 /// <summary>
 /// GetRole is a method in the RoleService class.
 /// This enables us to retrieve a role from the DB if necessary.
 /// </summary>
 /// <param name="role">The role we want to retrieve</param>
 /// <returns></returns>
 public Role GetRole(DataAccessLayer.Enums.RoleEnum role)
 {
     return(_dbContext.Roles.Find(role));
 }