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)); }
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)); }
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); }
public async Task <BrandCategoryDto> CreateRelation(int brandId, int categoryId) { BrandCategoryDto brandCatetogyRelation = await _brandCategoryRepository.CreateBrandCategory(brandId, categoryId); return(brandCatetogyRelation); }
public async Task <BrandCategoryDto> GetRelationById(int id) { BrandCategoryDto brandCategory = await _brandCategoryRepository.GetBrandCategory(id); return(brandCategory); }