예제 #1
0
        public async Task <IActionResult> Post([FromBody] BrandCategoryCreateModel brandCategoryCreateModel)
        {
            CategoryDto categoryDto = await _brandCategoryService.GetCategory(brandCategoryCreateModel.Category);

            if (categoryDto == null)
            {
                return(NotFound("No such category"));
            }

            BrandDto brandDto = await _brandCategoryService.GetBrand(brandCategoryCreateModel.Brand);

            if (brandDto == null)
            {
                return(NotFound("No such brand"));
            }

            if (await _brandCategoryService.BrandCategoryExists(brandDto.BrandId, categoryDto.CategoryId))
            {
                return(Conflict($"This relation already exists"));
            }

            BrandCategoryDto newBrandCategoryDto = await _brandCategoryService.CreateRelation(brandDto.BrandId, categoryDto.CategoryId);

            BrandCategoryWebModel newBrandCategoryModel = _mapper.Map <BrandCategoryWebModel>(newBrandCategoryDto);

            return(CreatedAtAction(nameof(Get), new { id = newBrandCategoryModel.BrandCategoryId }, newBrandCategoryModel));
        }
예제 #2
0
        public async Task <IActionResult> Get(int id)
        {
            BrandCategoryDto brandCategoryDto = await _brandCategoryService.GetRelationById(id);

            if (brandCategoryDto == null)
            {
                return(NotFound());
            }
            BrandCategoryWebModel brandCategoryModel = _mapper.Map <BrandCategoryWebModel>(brandCategoryDto);

            return(Ok(brandCategoryModel));
        }