public string ValidateProductSearchInputModel(ProductSearchInputModel model) { var validationResult = string.Empty; if (model.Id != null) { validationResult += ValidateProductId((long)model.Id); } if (model.PriceStart != null) { validationResult += ValidatePrice((decimal)model.PriceStart); } if (model.PriceEnd != null) { validationResult += ValidatePrice((decimal)model.PriceEnd); } if (model.ManufacturingYearStart != null) { validationResult += ValidateYear((int)model.ManufacturingYearStart); } if (model.ManufacturingYearEnd != null) { validationResult += ValidateYear((int)model.ManufacturingYearEnd); } if (model.Depth != null) { validationResult += ValidateValueNotZeroOrNegative((decimal)model.Depth); } if (model.Width != null) { validationResult += ValidateValueNotZeroOrNegative((decimal)model.Width); } if (model.Height != null) { validationResult += ValidateValueNotZeroOrNegative((decimal)model.Height); } if (model.Weight != null) { validationResult += ValidateValueNotZeroOrNegative((decimal)model.Weight); } if (model.WattageStart != null) { validationResult += ValidateValueNotZeroOrNegative((int)model.WattageStart); } if (model.WattageEnd != null) { validationResult += ValidateValueNotZeroOrNegative((int)model.WattageEnd); } if (model.VoltageStart != null) { validationResult += ValidateValueNotZeroOrNegative((int)model.VoltageStart); } if (model.VoltageEnd != null) { validationResult += ValidateValueNotZeroOrNegative((int)model.VoltageEnd); } return(validationResult); }
public IActionResult Search(ProductSearchInputModel inputModel, [FromServices] IProductService productService) { var result = new ProductSearchResultViewModel { Results = productService.Search(inputModel) }; return(View("ProductSearchResults", result)); }
public ActionResult <List <ProductOutputModel> > FindProducts([FromBody] ProductSearchInputModel productInputModel) { var validationResult = _productValidator.ValidateProductSearchInputModel(productInputModel); if (!string.IsNullOrEmpty(validationResult)) { return(UnprocessableEntity(validationResult)); } var result = _productManager.FindProducts(productInputModel); return(MakeResponse <List <ProductOutputModel>, List <ProductOutputModel> >(result)); }
public async Task <ProductSearchOutputModel> SearchProductsAsync(ProductSearchInputModel input) { var model = await this.PostWithResultAsync <ProductSearchOutputModel>(ApiUrls.ProductSearchUrl, input); if (model == null) { return new ProductSearchOutputModel() { TotalResults = -1, Products = Enumerable.Empty <ProductSearchItemOutputModel>() } } ; return(model); }
public IEnumerable <ProductViewModel> Search(ProductSearchInputModel inputModel) { IEnumerable <ProductViewModel> results = products; //Filtro per categoria, se è stata indicata if (!string.IsNullOrEmpty(inputModel.Category)) { results = results.Where(p => p.Category == inputModel.Category); } //Filtro per parola, se è stata indicata if (!string.IsNullOrEmpty(inputModel.Search)) { results = results.Where(p => p.Description.Contains(inputModel.Search, StringComparison.InvariantCultureIgnoreCase)); } return(results); }
public DataAgent <List <ProductOutputModel> > FindProducts(ProductSearchInputModel productSearchInputModel) { var dto = _mapper.Map <ProductSearchDto>(productSearchInputModel); var searchResult = _productRepo.FindProducts(dto); var result = new List <ProductOutputModel>(); if (searchResult.ContainsData) { foreach (ProductDto product in searchResult.Data) { result.Add(_mapper.Map <ProductOutputModel>(product)); } } return(new DataAgent <List <ProductOutputModel> > { Data = result, ResponseMessage = searchResult.ResponseMessage }); }
public List <ProductOutputModel> FindProduct(ProductSearchInputModel model) { var searchDto = _mapper.Map <ProductSearchDto>(model); var products = _productRepository.SearchProduct(searchDto); List <ProductOutputModel> output; if (model.CategoryId != null) { var filtredProducts = FilterProductsByCategoryId((int)model.CategoryId, products); output = _mapper.Map <List <ProductOutputModel> >(filtredProducts); } else { output = _mapper.Map <List <ProductOutputModel> >(products); } return(output); }
public async Task <IDataResult <ProductDto> > Get(ProductSearchInputModel productSearchInputModel) { try { ProductEntity product = await UnitOfWork.Product.GetAsync(p => p.ProductName == productSearchInputModel.ProductName && p.ProductDescription == productSearchInputModel.ProductDescription); ProductDto productDto = Mapper.Map <ProductEntity, ProductDto>(product); if (productDto != null) { return(new DataResult <ProductDto>(ResultStatus.Success, productDto)); } return(new DataResult <ProductDto>(ResultStatus.Error, "Böyle bir ürün bulunamadı", data: null)); } catch (Exception ex) { //Logger.Log(LogLevel.Error, ex, ex.Message); throw; } }
public async Task <ProductSearchOutputModel> SearchProductsAsyncV2(ProductSearchInputModel input) { using (var dclient = this.CreateClient()) { var client = dclient.Client; var url = ApiUrls.ProductSearchUrlV2; var content = this.GetContent(input); var response = await client.PostAsync(this.GetUri(url), content).ConfigureAwait(false); if (!response.IsSuccessStatusCode) { await this.AddErrorsAsync(response).ConfigureAwait(false); return(new ProductSearchOutputModel() { TotalResults = -1, Products = Enumerable.Empty <ProductSearchItemOutputModel>() }); } return(await this.GetObjectAsync <ProductSearchOutputModel>(response.Content).ConfigureAwait(false)); } }
public async Task <IDataResult <ProductDto> > GetWithName(ProductSearchInputModel productSearchInputModel) { IDataResult <ProductDto> result = await productOperationManager.Get(productSearchInputModel); return(result); }
public async ValueTask <ActionResult <List <ProductOutputModel> > > ProductSearch(ProductSearchInputModel inputModel) { var result = await _productRepository.ProductSearch(_mapper.Map <ProductSearch>(inputModel)); if (result.IsOkay) { if (result.RequestData == null) { return(NotFound("Products not found")); } return(Ok(_mapper.Map <List <ProductOutputModel> >(result.RequestData))); } return(Problem($"Transaction failed {result.ExMessage}", statusCode: 520)); }
public ActionResult <List <ProductOutputModel> > GetSearchResult(ProductSearchInputModel model) { var results = _productManager.FindProduct(model); return(Ok(results)); }