public async Task <int> Add(AddUserGroupDto groupDto, int userId) { var userGroupRepository = DataContextManager.CreateRepository <IUserGroupRepository>(); var group = await userGroupRepository.GetByName(groupDto.Name, userId); if (group != null) { throw new FoundSameObjectException("Group", groupDto.Name); } var users = await _userService.GetByIds(groupDto.UserIds); var newGroup = new Group { OwnerId = userId, Name = groupDto.Name, UsersInGroup = users.Select(us => new UserInGroup { UserId = us.Id }) .ToList(), IsActive = true }; await userGroupRepository.Add(newGroup); return(newGroup.Id); }
public int Add(AddUserGroupDto dto) { AssertAccessRights(dto.client_id); AssertIsSubsetOfAvailableRoles(dto.userRoles); Dom.UserGroup model = Dom.UserGroup.Create(ApplicationUser, dto.client_id); model.Update(ApplicationUser, dto); uow.UserGroupDom.Add(model); uow.SaveChanges(); return(model.id); }
public AddUserGroupDto GetAdd(int clientId) { AssertAccessRights(clientId); var dto = new AddUserGroupDto() { client_id = clientId }; return(dto); }
public async Task <ActionResult> AddGroup([FromBody] AddUserGroupDto groupDto) { if (!IsAvailableOperation()) { return(BadRequest()); } var newGroupId = await _userGroupService.Add(groupDto, UserId); return(Ok(newGroupId)); }