Пример #1
0
        /// <summary>
        /// Creates RolePermission
        /// </summary>
        /// <param name="createRolePermissionCommand">Model for all needed fields to create a tenant</param>
        /// <returns>ID of created RolePermission</returns>
        /// <exception cref="InvalidCreateRolePermissionDataError">If create data is not valid</exception>
        /// <exception cref="RolePermissionAlreadyExistsError">If RolePermission already exists</exception>
        public Result <int> CreateRolePermission(CreateRolePermissionCommand command)
        {
            if (!command.OrganizationId.HasValue)
            {
                return(new Result <int>(AuthorizationServiceErrors.InvalidCreateOrganizationDataError(nameof(command.OrganizationId))));
            }

            if (string.IsNullOrEmpty(command.RoleId))
            {
                return(new Result <int>(AuthorizationServiceErrors.InvalidCreateOrganizationDataError(nameof(command.RoleId))));
            }

            if (string.IsNullOrEmpty(command.RoleName))
            {
                return(new Result <int>(AuthorizationServiceErrors.InvalidCreateOrganizationDataError(nameof(command.RoleName))));
            }

            if (string.IsNullOrEmpty(command.Permissions))
            {
                return(new Result <int>(AuthorizationServiceErrors.InvalidCreateOrganizationDataError(nameof(command.Permissions))));
            }

            var exists = this.rolePermissionRepository.ExistsRolePermission(command.OrganizationId.Value, command.RoleId);

            if (exists)
            {
                return(new Result <int>(AuthorizationServiceErrors.EntityAlreadyExistsError(nameof(CreateRolePermissionCommand))));
            }

            return(new Result <int>(this.rolePermissionRepository.CreateRolePermission(command)));
        }
Пример #2
0
        public int CreateRolePermission(CreateRolePermissionCommand command)
        {
            var entity = mapper.Map <RolePermissionEntity>(command);

            entity.CreatedAt = DateTimeOffset.UtcNow.ToUnixTimeMilliseconds();
            this.context.RolePermissions.Add(entity);
            this.context.SaveChanges();

            return(entity.RolePermissionEntityId);
        }