Exemple #1
0
 public async Task <IWrappedResponse> Create(UserGroupCreateRequest request)
 {
     if (request.OrganizationId != null)
     {
         var group = Mapper.Map <Olma.OrganizationUserGroup>(request);
         _organizationUserGroupRepo.Create(group);
         _organizationUserGroupRepo.Save();
         return(Ok(Mapper.Map <UserGroupListItem>(group)));
     }
     if (request.CustomerId != null)
     {
         var group = Mapper.Map <Olma.CustomerUserGroup>(request);
         _customerUserGroupRepo.Create(group);
         _customerUserGroupRepo.Save();
         return(Ok(Mapper.Map <UserGroupListItem>(group)));
     }
     if (request.DivisionId != null)
     {
         var group = Mapper.Map <Olma.CustomerDivisionUserGroup>(request);
         _divisionUserGroupRepo.Create(group);
         _divisionUserGroupRepo.Save();
         return(Ok(Mapper.Map <UserGroupListItem>(group)));
     }
     return(Failed <UserGroupListItem>());
 }
        //[HasPermission(typeof(AttributeRequirement<CanAdminUserRequirement>))]
        public Task <ActionResult <UserGroupListItem> > Post([FromForm] string values)
        {
            var request = new UserGroupCreateRequest();

            JsonConvert.PopulateObject(values, request);
            return(this._userGroupService.Create(request).Convert <UserGroupListItem>(this));
        }
        public MongoUserGroup(UserGroupCreateRequest userGroup, MongoUserGroupMemberUser mongoUserGroupMemberUser)
        {
            Name    = userGroup.Name;
            Members = new List <MongoUserGroupMember>()
            {
                new MongoUserGroupMember(mongoUserGroupMemberUser)
            };

            CreatedAt = DateTime.UtcNow;
            UpdatedAt = DateTime.UtcNow;
        }
Exemple #4
0
        public async Task <IActionResult> Create([FromBody] UserGroupCreateRequest model, CancellationToken cancellationToken)
        {
            if (model == null)
            {
                throw new ArgumentNullException(nameof(model));
            }

            if (model.Name == null)
            {
                return(BadRequest(new ErrorMessageResponse(ErrorCode.ModelValidationFailure)));
            }

            var totalGroups = await DatabaseContext
                              .Groups
                              .AsQueryable()
                              .CountAsync(cancellationToken)
                              .ConfigureAwait(false);

            if (totalGroups >= generalConfiguration.UserGroupLimit)
            {
                return(Conflict(new ErrorMessageResponse(ErrorCode.UserGroupLimitReached)));
            }

            var permissionSet = new Models.PermissionSet
            {
                AdministrationRights  = model.PermissionSet?.AdministrationRights ?? AdministrationRights.None,
                InstanceManagerRights = model.PermissionSet?.InstanceManagerRights ?? InstanceManagerRights.None,
            };

            var dbGroup = new UserGroup
            {
                Name          = model.Name,
                PermissionSet = permissionSet,
            };

            DatabaseContext.Groups.Add(dbGroup);
            await DatabaseContext.Save(cancellationToken).ConfigureAwait(false);

            Logger.LogInformation("Created new user group {0} ({1})", dbGroup.Name, dbGroup.Id);

            return(Created(dbGroup.ToApi(true)));
        }
Exemple #5
0
        public async Task <IActionResult> CreateUserGroupAsync([FromBody] UserGroupCreateRequest request)
        {
            await _userGroupsService.CreateUserGroupAsync(request.UserGroupName);

            return(new StatusCodeResult((int)HttpStatusCode.Created));
        }
Exemple #6
0
 /// <inheritdoc />
 public Task <UserGroupResponse> Create(UserGroupCreateRequest group, CancellationToken cancellationToken) => ApiClient.Create <UserGroupCreateRequest, UserGroupResponse>(Routes.UserGroup, group ?? throw new ArgumentNullException(nameof(group)), cancellationToken);