public async Task <CreatedActionResult <ItemTemplateSubCategoryResponse> > PostCreateItemTemplateSubCategoryAsync(
            [FromServices] NaheulbookExecutionContext executionContext,
            CreateItemTemplateSubCategoryRequest request
            )
        {
            try
            {
                var itemTemplateSubCategory = await _itemTemplateSubSubCategoryService.CreateItemTemplateSubCategoryAsync(executionContext, request);

                return(_mapper.Map <ItemTemplateSubCategoryResponse>(itemTemplateSubCategory));
            }
            catch (ForbiddenAccessException ex)
            {
                throw new HttpErrorException(StatusCodes.Status403Forbidden, ex);
            }
        }
        public async Task PostCreateItemTemplateSubCategoryAsync_CallItemSubCategoryService()
        {
            var createItemTemplateSubCategoryRequest = new CreateItemTemplateSubCategoryRequest();
            var itemTemplateSubCategory         = new ItemTemplateSubCategory();
            var itemTemplateSubCategoryResponse = new ItemTemplateSubCategoryResponse();

            _itemTemplateSubCategoryService.CreateItemTemplateSubCategoryAsync(_executionContext, createItemTemplateSubCategoryRequest)
            .Returns(itemTemplateSubCategory);
            _mapper.Map <ItemTemplateSubCategoryResponse>(itemTemplateSubCategory)
            .Returns(itemTemplateSubCategoryResponse);

            var result = await _itemTemplateSubCategoriesController.PostCreateItemTemplateSubCategoryAsync(_executionContext, createItemTemplateSubCategoryRequest);

            result.StatusCode.Should().Be(201);
            result.Value.Should().Be(itemTemplateSubCategoryResponse);
        }
Beispiel #3
0
        public async Task <ItemTemplateSubCategory> CreateItemTemplateSubCategoryAsync(NaheulbookExecutionContext executionContext, CreateItemTemplateSubCategoryRequest request)
        {
            await _authorizationUtil.EnsureAdminAccessAsync(executionContext);

            var itemTemplateSubCategory = new ItemTemplateSubCategory()
            {
                SectionId   = request.SectionId,
                Name        = request.Name,
                Note        = request.Note,
                Description = request.Description,
                TechName    = request.TechName
            };

            using (var uow = _unitOfWorkFactory.CreateUnitOfWork())
            {
                uow.ItemTemplateSubCategories.Add(itemTemplateSubCategory);
                await uow.SaveChangesAsync();
            }

            return(itemTemplateSubCategory);
        }