public IEnumerable <ApiProductUserDto> GetUserQueriedProductList(ProductFiltersViewModel searchModel) { var products = _productRepository.SearchResultFromSqlStoredProcedure(searchModel.Name, searchModel.PriceFrom, searchModel.PriceTo, searchModel.DateTimeTo, searchModel.DateTimeFrom, searchModel.ProductCategoryId); var requestContext = HttpContext.Current.Request.RequestContext; var apiproducts = products.Select(p => new ApiProductUserDto() { Name = p.Name, Id = p.Id, AmountInStock = p.AmountInStock, Price = p.Price, Description = p.Description, BuyLink = new UrlHelper(requestContext).Action("Buy", "Cart", new { id = p.Id, Area = "" }), DetailsLink = new UrlHelper(requestContext).Action("Details", "Product", new { id = p.Id, Area = "" }), Thumbnail = new UrlHelper(requestContext).Content("~/Images/" + p.ThumbnailName ?? "no-image.jpg"), }); return(apiproducts); }
public IEnumerable <ApiProductDto> GetAdminQueriedProductList(ProductFiltersViewModel searchModel) { var products = _productRepository.SearchResultFromSqlStoredProcedure(searchModel.Name, searchModel.PriceFrom, searchModel.PriceTo, searchModel.DateTimeTo, searchModel.DateTimeFrom, searchModel.ProductCategoryId); var requestContext = HttpContext.Current.Request.RequestContext; var apiproducts = products.Select(p => new ApiProductDto() { Name = p.Name, CategoryName = p.CategoryName, AmountInStock = p.AmountInStock, DateOfAdding = p.DateOfAdding?.ToString("dd/MM/yyyy"), Price = p.Price, Description = p.Description, EditLink = new UrlHelper(requestContext).Action("Edit", "Product", new { id = p.Id, Area = "Admin" }), DeleteLink = new UrlHelper(requestContext).Action("Delete", "Product", new { id = p.Id, Area = "Admin" }), }); return(apiproducts); }
private SortDefinition <Product> GetSortings(ProductFiltersViewModel model) { List <SortDefinition <Product> > sortings = new List <SortDefinition <Product> >(); var priceSorting = PriceSorting(model); if (priceSorting != null) { sortings.Add(priceSorting); } var ratingSorting = RatingSorting(model); if (ratingSorting != null) { sortings.Add(ratingSorting); } if (sortings.Count > 0) { return(Builders <Product> .Sort.Combine(sortings)); } else { return(null); } }
public List <Product> GetFilteredProducts(ProductFiltersViewModel model, int offset, int qty) { IMongoCollection <Product> collection = ProductConnect(); var filters = new List <FilterDefinition <Product> >(); if (model.Filters != null) { filters = Filters(model.Filters); } filters.AddRange(StaticFilters(model)); var filter = Builders <Product> .Filter.And(filters); var qresult = collection.Find(filter); var sortings = GetSortings(model); if (sortings != null) { qresult = qresult.Sort(sortings); } var result = qresult .Skip(offset) .Limit(qty) .ToList(); return(result); }
public PartialViewResult Filter(ProductFiltersViewModel model) { ClearHttp(); HttpContext.Session.SetOrUpdate <ProductFiltersViewModel>("ProductFilters", model); var result = CategoryProductLogic.GetProductsWithFilters(model, 0, Qty, model.inputSearch); return(PartialView("ProductCard", result.GetModel)); }
public ProductFiltersViewModel GetProductSearch() { var viewModel = new ProductFiltersViewModel { ProductCategories = _productCategoryService.GetProductCategoryList(), }; return(viewModel); }
public async Task <IActionResult> GetTotalQtyByFilters([FromQuery] ProductFiltersViewModel filtersVM) { try { var filtersDto = _mapper.Map <ProductFiltersViewModel, ProductFiltersDto>(filtersVM); int qty = await _productUseCases.GetTotalQtyByFilters(filtersDto); return(Ok(qty)); } catch (Exception e) { throw e; } }
public async Task <IActionResult> GetByFilters([FromQuery] ProductFiltersViewModel filtersVM) { try { var filtersDto = _mapper.Map <ProductFiltersViewModel, ProductFiltersDto>(filtersVM); IEnumerable <ProductDto> productsDto = await _productUseCases.GetByFilters(filtersDto); IEnumerable <ProductViewModel> productsVM = _mapper.Map <IEnumerable <ProductDto>, IEnumerable <ProductViewModel> >(productsDto); return(Ok(productsVM)); } catch (Exception e) { throw e; } }
public async Task <IActionResult> CreatePdf([FromQuery] ProductFiltersViewModel filtersVM) { try { var filtersDto = _mapper.Map <ProductFiltersViewModel, ProductFiltersDto>(filtersVM); MemoryStream stream = await _productUseCases.CreatePdf(filtersDto); stream.Position = 0; return(File(stream, "application/pdf")); } catch (Exception e) { throw e; } }
private SortDefinition <Product> PriceSorting(ProductFiltersViewModel model) { if (model.SortPrice == "Low") { return(Builders <Product> .Sort.Ascending(x => x.Price)); } if (model.SortPrice == "High") { return(Builders <Product> .Sort.Descending(x => x.Price)); } else { return(null); } }
public SortDefinition <Product> RatingSorting(ProductFiltersViewModel model) { if (model.SortRating == "Low") { return(Builders <Product> .Sort.Ascending(x => x.Rating)); } if (model.SortRating == "High") { return(Builders <Product> .Sort.Descending(x => x.Rating)); } else { return(null); } }
public async Task <ProductFiltersViewModel> GetFilters() { // TODO: create api method to get all filter setup var brands = await _shopy.ListBrands(); var sizes = await _shopy.ListSizes(); var categoriesLookup = await _shopy.LookupCategories(); var viewModel = new ProductFiltersViewModel { BrandFilters = _mapper.Map <IEnumerable <FilterViewModel> >(brands), SizeFilters = _mapper.Map <IEnumerable <FilterViewModel> >(sizes), CategoryFilters = _mapper.Map <IEnumerable <FilterViewModel> >(categoriesLookup), }; return(viewModel); }
public PartialViewResult GetMore(string category, int offset, string inputSearch) { ProductLogic.ModelOrError <OutputModelsForCategoryProduct.CategoryProductsModel> model; ProductFiltersViewModel filters = new ProductFiltersViewModel { Category = category, inputSearch = inputSearch }; if (HttpContext.Session.Keys.Contains("ProductFilters")) { filters = HttpContext.Session.Get <ProductFiltersViewModel>("ProductFilters"); } model = CategoryProductLogic.GetProductsWithFilters(filters, offset, Qty, inputSearch); if (model.GetModel != null) { return(PartialView("ProductCard", model.GetModel)); } return(null); }
private FilterDefinition <Product> PriceFilter(ProductFiltersViewModel model) { FilterDefinition <Product> priceFilter; var maxFilter = FilterDefinition <Product> .Empty; var minFilter = FilterDefinition <Product> .Empty; if (model.MaxPrice.HasValue) { maxFilter = Builders <Product> .Filter.Lte("Price", model.MaxPrice.Value); } if (model.MinPrice.HasValue) { minFilter = Builders <Product> .Filter.Gte("Price", model.MinPrice.Value); } priceFilter = maxFilter & minFilter; return(priceFilter); }
public FilterDefinition <Product> RatingFilter(ProductFiltersViewModel model) { FilterDefinition <Product> ratingFilter; var maxFilter = FilterDefinition <Product> .Empty; var minFilter = FilterDefinition <Product> .Empty; if (model.MaxRating.HasValue) { maxFilter = Builders <Product> .Filter.Lte("Rating", model.MaxRating.Value); } if (model.MinRating.HasValue) { minFilter = Builders <Product> .Filter.Gte("Rating", model.MinRating.Value); } ratingFilter = maxFilter & minFilter; return(ratingFilter); }
public IActionResult CategoryProducts(string category) { ClearHttp(); var filters = new ProductFiltersViewModel(); filters.Category = category; string inputString = Request.Query.FirstOrDefault(p => p.Key == "inputSearch").Value; filters.inputSearch = inputString; var model = CategoryProductLogic.GetProductsWithFilters(filters, 0, Qty, inputString); if (model.GetModel != null) { return(View(model.GetModel)); } TempData.AddOrUpdate("Error", model.GetErrorMessage); return(Redirect(Request.Headers["Referer"].ToString())); }
public List <FilterDefinition <Product> > StaticFilters(ProductFiltersViewModel model) { var categoryFilter = CategoryFilter(model); FilterDefinition <Product> priceFilter = PriceFilter(model); var ratingFilter = RatingFilter(model); if (model.inputSearch == null) { return(new List <FilterDefinition <Product> > { categoryFilter, priceFilter, ratingFilter }); } else { var searchFilter = Builders <Product> .Filter.Text(model.inputSearch); return(new List <FilterDefinition <Product> > { searchFilter, categoryFilter, priceFilter, ratingFilter }); } }
private FilterDefinition <Product> CategoryFilter(ProductFiltersViewModel model) { return(Builders <Product> .Filter.Eq("CategoryName", model.Category)); }
public IHttpActionResult UserSearch(ProductFiltersViewModel dto) { var productList = _productService.GetUserQueriedProductList(dto); return(Ok(productList)); }