public async Task <StoreCategory> AddAsync(int storeId, CategoryRequest request) { if (await _repository.Find(storeId, request.CategoryName) != null) { throw new ApiException("Category with given name is already added in this store"); } var category = _mapper.Map <StoreCategory>(request); category.StoreId = storeId; var addedCategory = await _repository.Add(category); await _repository.SaveChangesAsync(); return(addedCategory); }
private async Task <List <StoreCategory> > FindCategoriesInStoreAsync(int storeId, IEnumerable <int> categoriesIds) { List <StoreCategory> categories = new(); foreach (int categoryId in categoriesIds) { var category = await _categoryRepository.Find(storeId, categoryId); if (category == null) { throw new ApiException("This store does not contains category with given id: " + categoryId); } categories.Add(category); } return(categories); }