| | | 1 | | using System; |
| | | 2 | | using System.Collections.Generic; |
| | | 3 | | using System.Linq; |
| | | 4 | | using System.Threading.Tasks; |
| | | 5 | | using SVETA.Api.Data.DTO.Showcase; |
| | | 6 | | using SVETA.Api.Services.Interfaces; |
| | | 7 | | using WinSolutions.Sveta.Server.Services.Interfaces; |
| | | 8 | | using Microsoft.Extensions.Logging; |
| | | 9 | | using AutoMapper; |
| | | 10 | | using WinSolutions.Sveta.Server.Data.DataModel.Entities; |
| | | 11 | | using WinSolutions.Sveta.Server.Data.DataModel.Kinds; |
| | | 12 | | using SVETA.Api.Data.DTO; |
| | | 13 | | using WinSolutions.Sveta.Server.Data.DataModel.Extensions; |
| | | 14 | | |
| | | 15 | | namespace SVETA.Api.Services.Implements |
| | | 16 | | { |
| | | 17 | | public class CategoryWorker : ICategoryWorker |
| | | 18 | | { |
| | | 19 | | private readonly ICategoryService _categoryService; |
| | | 20 | | private readonly IGoodService _goodService; |
| | | 21 | | |
| | 0 | 22 | | public CategoryWorker(ICategoryService categoryService, IGoodService goodService) |
| | 0 | 23 | | { |
| | 0 | 24 | | _categoryService = categoryService; |
| | 0 | 25 | | _goodService = goodService; |
| | 0 | 26 | | } |
| | | 27 | | |
| | | 28 | | public async Task Delete(long id) |
| | 0 | 29 | | { |
| | 0 | 30 | | if((await _categoryService.GetChildCategoriesCount(id)) > 0) |
| | 0 | 31 | | { |
| | 0 | 32 | | throw new ArgumentException("Невозможно удалить категорию с подкатегориями"); |
| | | 33 | | } |
| | | 34 | | |
| | 0 | 35 | | if((await _goodService.GetGoodsCount(null, id, false)) > 0) |
| | 0 | 36 | | { |
| | 0 | 37 | | throw new ArgumentException("Невозможно удалить категорию с товарами"); |
| | | 38 | | } |
| | | 39 | | |
| | 0 | 40 | | await _categoryService.DeleteCategory(id); |
| | 0 | 41 | | } |
| | | 42 | | } |
| | | 43 | | } |