public async Task <IActionResult> GetAllProduct(ProductFilterDTO Filter) { try { return(Ok(await productService.GetAll(Filter))); } catch (Exception ex) { return(BadRequest(ex)); } }
public IHttpActionResult CheckIfProductExits(ProductFilterDTO item) { try { return(Ok(this.iProductBL.GetFilteredProducts(item))); } catch (Exception exp) { ErrorLogger.LogDebug(exp.Message); return(null); } }
public async Task <ActionResult> Get([FromQuery] ProductFilterDTO filter) { try { var pagedListOfProducts = await _products.Find(filter); return(Ok(pagedListOfProducts)); } catch (Exception ex) { return(StatusCode((int)HttpStatusCode.InternalServerError, ex.Message)); } }
public IQueryable <Product> Filter(IQueryable <Product> query, ProductFilterDTO filter) { if (!(filter.Name is null)) { query = query.Where(x => x.Name.Contains(filter.Name)); } if (!(filter.GroupId is null)) { query = query.Where(x => x.GroupId == filter.GroupId); } return(query); }
public async Task <PagedProductsDTO> Find(ProductFilterDTO filter) { var productQuery = _repo.GetQuery(); productQuery = productQuery .Skip((filter.PageNumber - 1) * filter.PageCapacity) .Take(filter.PageCapacity); var products = await productQuery.ToListAsync(); PagedProductsDTO result = new PagedProductsDTO() { PageNumber = filter.PageNumber, Products = _mapper.Map <IEnumerable <Product>, IEnumerable <ProductDTO> >(products) }; return(result); }
public async Task <JsonResult> GetProducts([FromBody] ProductFilterDTO filter) { BaseResponse <List <Product> > response = new BaseResponse <List <Product> >(); try { response.Result = await unitOfWork.GetProductRepository().GetProducts(filter); } catch (Exception ex) { response = new BaseResponse <List <Product> >(); response.Result = null; response.Success = false; response.Message = ex.Message; } JsonResult res = Json(response); return(res); }
public async Task <ResponeListDTO <ProductViewModel> > GetAll(ProductFilterDTO Filter) { Expression <Func <Product, bool> > predicate = (x) => (true); Filter.Name = (Filter.Name ?? "").Trim(); predicate = x => ( (x.Name.Trim().Contains(Filter.Name) || x.Categories.Name.Trim().Contains(Filter.Name)) && true ); var(Total, ModelList) = await base.GetByCustomConditionAsync(predicate, Filter.OrderBy, Filter.OrderType == "" || Filter.OrderType == "Asc"?OrderTypeEnum.Asc : OrderTypeEnum.Desc, Filter.PageIndex, Filter.PageSize, x => x.Categories); if (ModelList == null) { ModelList = new List <ProductViewModel>(); } return(new ResponeListDTO <ProductViewModel> { List = ModelList, ResultPaging = new ResponePagingDTO { PageSize = Filter.PageSize, RecordsFiltered = Total, RecordsTotal = ModelList.Count } }); }
public async Task <ServiceResponseWithPagination <List <ProductDTO> > > GetAll(PaginationDto pagination = null, ProductFilterDTO productFilter = null, DataOrderDTO ordering = null) { // Quering data var query = _dbContext.Product.AsQueryable(); // Filtering data query = Filter(query, productFilter); // Ordering if (!(ordering is null)) { var columns = new List <string> { "Id", "GroupId", "Name", "Price", "CreatedBy", "Status" }; if (columns.Exists(x => x == ordering.OrderBy)) { if (ordering.OrderBy == "CreatedBy") { ordering.OrderBy = "CreatedByUser.Username"; } var property = $"{ordering.OrderBy}"; if (!String.IsNullOrEmpty(ordering.Sort) && ordering.Sort.ToLower() == "desc") { query = ApplyOrder(query, property, "OrderByDescending"); } else { query = ApplyOrder(query, property, "OrderBy"); } } } // Pagination var paginationResult = await _httpContext.HttpContext.InsertPaginationParametersInResponse(query, pagination.RecordsPerPage, pagination.Page); // Generate result var result = await query.Paginate(pagination).Include(entity => entity.CreatedByUser.Products).Include(entity => entity.Group).ToListAsync(); // Return error if count is 0 if (result.Count == 0) { return(ResponseResultWithPagination.Failure <List <ProductDTO> >("Product is not Exist", ResponseType.NoContent)); } // Mapping var dto = _mapper.Map <List <ProductDTO> >(result); // Return Results return(ResponseResultWithPagination.Success <List <ProductDTO> >(dto, paginationResult)); }
public FilteredProductsDTO GetFilteredProducts(ProductFilterDTO filter) { try { FilteredProductsDTO fPDTO = new FilteredProductsDTO(); List <ProductDTO> items = new List <ProductDTO>(); if (filter.CategoryID != null) { items = mapObjectProducts(this.iUnitOfWork.ProductRepository.Get(x => x.categoryID.ToString() == filter.CategoryID).ToList()); var productsOfChildCategories = GetProductsOFCategory(filter.CategoryID); items.AddRange(productsOfChildCategories); } if (filter.CategoriesIDs != null) { if (filter.CategoriesIDs.Count > 0) { if (items.Count == 0) { items = mapObjectProducts(this.iUnitOfWork.ProductRepository.Get(x => filter.CategoriesIDs.Contains(x.categoryID.ToString())).ToList()); } else { items = items.Where(x => filter.CategoriesIDs.Contains(x.categoryID.ToString())).ToList(); } } } if (filter.NamePart != null && filter.NamePart != string.Empty) { if (items.Count == 0) { items = mapObjectProducts(this.iUnitOfWork.ProductRepository.Get(x => x.name.ToLower().Contains(filter.NamePart.ToLower())).ToList()); } else { items = items.Where(x => x.name.ToLower().Contains(filter.NamePart.ToLower())).ToList(); } } if (filter.PriceFrom != null && filter.PriceTO != null) { if (items.Count == 0) { items = mapObjectProducts(this.iUnitOfWork.ProductRepository.Get(x => x.priceAfter <= filter.PriceTO && x.priceAfter >= filter.PriceFrom).ToList()); } else { items = items.Where(x => x.priceAfter <= filter.PriceTO && x.priceAfter >= filter.PriceFrom).ToList(); } } // this condition executed if there is no filteration if (items.Count == 0 && filter.PriceFrom == null && filter.PriceTO == null && filter.NamePart == null && filter.CategoryID == null && filter.CategoriesIDs == null) { items = mapObjectProducts(this.iUnitOfWork.ProductRepository.Get().ToList().Take(20).ToList()); } if (filter.SortingType != null) { if (items.Count != 0) { if (filter.SortingType == 1) // price from high to low { ProductPriceFromHighToLow pPFHTL = new ProductPriceFromHighToLow(); items.Sort(pPFHTL); } if (filter.SortingType == 2) // price from low to high { ProductPriceFromLowToHigh pPFLTH = new ProductPriceFromLowToHigh(); items.Sort(pPFLTH); } if (filter.SortingType == 3) // rate from high to low { ProductRateFromHighToLow pRHTL = new ProductRateFromHighToLow(); items.Sort(pRHTL); } } } if (items.Count > 0) { fPDTO.Brands = items.Select(x => new CategoryDTO() { ID = Guid.Parse(x.categoryID.ToString()), name = x.parentCategoryName }).Distinct(new CategoryEqualityComparer()).ToList(); fPDTO.NumberOfAllItems = items.Count(); fPDTO.NumerOfPages = (int)(decimal.Ceiling((decimal)fPDTO.NumberOfAllItems / 20)); fPDTO.MaxPriceValue = (int)items.Max(x => x.priceAfter).Value + 100; // this filteration by page number if (filter.PageNumber == null || filter.PageNumber == 1) { items = items.Take(20).ToList(); } else { items = items.Skip((int)filter.PageNumber * 20).Take(20).ToList(); } } fPDTO.NumberOfCurrentItems = items.Count(); fPDTO.Products = items; return(fPDTO); } catch (Exception ex) { ErrorLogger.LogDebug(ex.Message); return(null); } }
public async Task <IActionResult> GetAll([FromQuery] PaginationDto pagination = null, [FromQuery] ProductFilterDTO filter = null, [FromQuery] DataOrderDTO ordering = null) { var paginationResult = await _Service.GetAll(pagination, filter, ordering); return(Ok(paginationResult)); }