Exemplo n.º 1
0
        private void RemoveRolesFromUtility(UtilityRoleViewModel newUtilityRole)
        {
            var existingUtilityrRoles = GetAllRolesForAnUtility(newUtilityRole.UtilityId);

            foreach (var existingUtilityrRole in existingUtilityrRoles)
            {
                var result = newUtilityRole.RoleIds.Find(x => x.Equals(existingUtilityrRole.RoleID));

                if (result == 0)
                {
                    var recordToDelete = _commmonDBContext.Query <UtilityRole>().Where(x => x.UtilityID == existingUtilityrRole.UtilityID &&
                                                                                       x.RoleID == existingUtilityrRole.RoleID).FirstOrDefault();
                    _commmonDBContext.Delete(recordToDelete);
                }
            }
        }
Exemplo n.º 2
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);
            }
        }