Exemplo n.º 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));
        }
Exemplo n.º 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));
        }
Exemplo n.º 3
0
        public async Task <bool> DeleteRelation(int brandCategoryId)
        {
            BrandCategoryDto brandCategory = await _brandCategoryRepository.GetBrandCategory(brandCategoryId);

            if (brandCategory == null)
            {
                throw new NullReferenceException($"No brand category relation with id: {brandCategoryId}");
            }

            await _brandCategoryRepository.DeleteBrandCategory(brandCategoryId);

            return(true);
        }
Exemplo n.º 4
0
        public async Task <BrandCategoryDto> CreateRelation(int brandId, int categoryId)
        {
            BrandCategoryDto brandCatetogyRelation = await _brandCategoryRepository.CreateBrandCategory(brandId, categoryId);

            return(brandCatetogyRelation);
        }
Exemplo n.º 5
0
        public async Task <BrandCategoryDto> GetRelationById(int id)
        {
            BrandCategoryDto brandCategory = await _brandCategoryRepository.GetBrandCategory(id);

            return(brandCategory);
        }