コード例 #1
0
        public async Task <Character> CreateCustomCharacterAsync(NaheulbookExecutionContext executionContext, CreateCustomCharacterRequest request)
        {
            using var uow = _unitOfWorkFactory.CreateUnitOfWork();

            var character = _characterFactory.CreateCustomCharacter(request);

            if (request.GroupId.HasValue)
            {
                var group = await uow.Groups.GetAsync(request.GroupId.Value);

                if (group == null)
                {
                    throw new GroupNotFoundException(request.GroupId.Value);
                }
                _authorizationUtil.EnsureIsGroupOwner(executionContext, @group);
                character.Group = @group;
            }

            character.OwnerId = executionContext.UserId;
            uow.Characters.Add(character);

            await uow.SaveChangesAsync();

            return(character);
        }