public async Task <CreateShopProductSuggestionCommandResponse> Handle(CreateShopProductSuggestionCommand command) { var person = await _personRepository.AsQuery().OfType <Shop>().SingleOrDefaultAsync(p => p.UserId == command.UserId); if (person == null) { throw new DomainException("شخص یافت نشد"); } var categoryRoot = await _categoryRootRepository.FindAsync(command.CategoryRootId); if (categoryRoot == null) { throw new DomainException("دسته بندی ریشه یافت نشد"); } Guid categoryId = Guid.Empty; string categoryName = ""; var category = await _categoryRepository.FindAsync(command.CategoryId); if (category != null) { categoryId = category.Id; categoryName = category.Name; } Guid brandId = Guid.Empty; string brandName = ""; var brand = await _brandRepository.FindAsync(command.BrandId); if (brand != null) { brandName = brand.Name; brandId = brand.Id; } var productSuggestionGroup = new ProductSuggestionGroup(categoryRoot.Id, categoryRoot.Name, categoryId, categoryName, brandId, brandName); var productSuggestion = new ShopProductSuggestion(Guid.NewGuid(), command.Title, command.ProductImage, command.Description, person.Id, productSuggestionGroup); _repository.Add(productSuggestion); return(new CreateShopProductSuggestionCommandResponse()); }
public static IShopProductSuggestionDto ToDto(this ShopProductSuggestion src) { return(Mapper.Map <IShopProductSuggestionDto>(src)); }