Пример #1
0
        public void AddRoleToUserForAllUtility(User user)
        {
            var allUtilities = _utilityService.GetAllUtilities();
            var userRole     = _roleService.GetRoleByRoleName("User");

            foreach (var utility in allUtilities)
            {
                _commonDBContext.Add(new UtilityUserRoles {
                    UtilityId = utility.Id, UserId = user.ID, RoleId = userRole.ID
                });
            }
        }
Пример #2
0
        public void SaveUtilityRole(UtilityRoleViewModel newUtilityRole)
        {
            var existingUtilityRoles = GetAllRolesForAnUtility(newUtilityRole.UtilityId);
            var newRolesForUtility   = new List <UtilityRole>();


            foreach (var item in newUtilityRole.RoleIds)
            {
                if (existingUtilityRoles.Find(x => x.RoleID == item) == null)
                {
                    _commmonDBContext.Add(new UtilityRole {
                        UtilityID = newUtilityRole.UtilityId, RoleID = item
                    });
                }
            }
            RemoveRolesFromUtility(newUtilityRole);
        }
Пример #3
0
        public void AddRolesToUserForAUtility(UtilityUserRoleViewModel newUserRole)
        {
            var myNewUserRole = new UtilityUserRoles();

            foreach (var item in newUserRole.UserId)
            {
                var userRole = _commonDBContext.Query <UtilityUserRoles>().Where(x => x.UserId == item && x.UtilityId == newUserRole.UtilityId).FirstOrDefault();
                if (userRole != null)
                {
                    _commonDBContext.Delete(userRole);
                }

                myNewUserRole.UtilityId = newUserRole.UtilityId;
                myNewUserRole.RoleId    = newUserRole.RoleId;
                myNewUserRole.UserId    = item;
                _commonDBContext.Add(myNewUserRole);
            }
        }