public async Task <CreatedActionResult <MonsterTypeResponse> > PostCreateMonsterTypeAsync(
            [FromServices] NaheulbookExecutionContext executionContext,
            CreateMonsterTypeRequest request
            )
        {
            try
            {
                var monsterType = await _monsterTypeService.CreateMonsterTypeAsync(executionContext, request);

                return(_mapper.Map <MonsterTypeResponse>(monsterType));
            }
            catch (ForbiddenAccessException ex)
            {
                throw new HttpErrorException(StatusCodes.Status403Forbidden, ex);
            }
        }
Example #2
0
        public async Task <MonsterType> CreateMonsterTypeAsync(
            NaheulbookExecutionContext executionContext,
            CreateMonsterTypeRequest request
            )
        {
            await _authorizationUtil.EnsureAdminAccessAsync(executionContext);

            using (var uow = _unitOfWorkFactory.CreateUnitOfWork())
            {
                var monsterType = new MonsterType
                {
                    Name          = request.Name,
                    SubCategories = new List <MonsterSubCategory>()
                };

                uow.MonsterTypes.Add(monsterType);
                await uow.SaveChangesAsync();

                return(monsterType);
            }
        }