public async Task <IHttpActionResult> Post(CreateShopProductSuggestionCommand command) { command.UserId = UserId; var commandResponse = await Bus.Send <CreateShopProductSuggestionCommand, CreateShopProductSuggestionCommandResponse>(command); var response = new ResponseModel { Message = "ثبت کالای پیشنهادی با موفقیت انجام شد", Success = true, ResponseData = commandResponse }; return(Ok(response)); }
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()); }