public int Duplicate(UpdateUserGroupDto dto)
 {
     Dom.UserGroup srcModel = AssertAccessRights(uow.UserGroupDom.Get(dto.id));
     AssertIsSubsetOfAvailableRoles(dto.userRoles);
     Dom.UserGroup model = Dom.UserGroup.Create(ApplicationUser, srcModel.client_id.Value);
     model.Update(ApplicationUser, dto);
     uow.UserGroupDom.Add(model);
     uow.SaveChanges();
     return(model.id);
 }
Esempio n. 2
0
        public async Task <ActionResult> UpdateGroup([FromBody] UpdateUserGroupDto groupDto)
        {
            if (!IsAvailableOperation())
            {
                return(BadRequest());
            }

            await _userGroupService.Update(groupDto, UserId);

            return(Ok());
        }
        public void Update(UpdateUserGroupDto dto)
        {
            Dom.UserGroup userGroup = AssertAccessRights(uow.UserGroupDom.Get(dto.id));
            AssertIsSubsetOfAvailableRoles(dto.userRoles);
            var usersOfUserGroup = UserManager.Users.ToList().Where(u => u.userGroupIds.data.Contains(userGroup.id));

            userGroup.Update(ApplicationUser, dto);
            userGroup.UpdateUsers <IdentityResult>(
                ApplicationUser,
                usersOfUserGroup,
                UserManager.GetRoles, UserManager.RemoveFromRoles, UserManager.AddToRoles);
            uow.SaveChanges();
        }
Esempio n. 4
0
        public async Task Update(UpdateUserGroupDto groupDto, int userId)
        {
            var userGroupRepository = DataContextManager.CreateRepository <IUserGroupRepository>();

            var group = await userGroupRepository.GetById(groupDto.Id, userId);

            if (group == null)
            {
                throw new NotFoundException("Group", groupDto.Id);
            }

            var otherGroup = await userGroupRepository.GetByName(groupDto.Name, userId);

            if (otherGroup != null && otherGroup.Id != group.Id)
            {
                throw new FoundSameObjectException("Group", groupDto.Name);
            }

            var users = await _userService.GetByIds(groupDto.UserIds);

            users.Where(x => !group.UsersInGroup.Any(y => y.UserId == x.Id))
            .ToList()
            .ForEach(us =>
            {
                group.UsersInGroup.Add(new UserInGroup
                {
                    UserId = us.Id
                });
            });

            group.UsersInGroup = group.UsersInGroup.Where(x => users.Any(y => y.Id == x.UserId)).ToList();

            group.Name = groupDto.Name;

            await userGroupRepository.Update(group);
        }