public IActionResult GetPublicProducts(GetPublicProductPagingRequest requet) { var products = _productService.GetPublicProducts(requet); if (products == null) { return(BadRequest("Không có sản phẩm nào")); } return(Ok(products)); }
public async Task <ActionResult> Get(string languageId, [FromQuery] GetPublicProductPagingRequest request) { var result = await _publicProductService.GetAllPaging(languageId, request); if (result == null) { return(BadRequest()); } return(Ok(result)); }
public async Task <IActionResult> GetPaggingProduct(string languageId, [FromQuery] GetPublicProductPagingRequest request) { var product = await _publicProductService.GetAllByCategoryId(languageId, request); if (product == null) { return(BadRequest()); } return(Ok(product)); }
public async Task <PagedResult <ProductViewModel> > GetAllByCategoryId(GetPublicProductPagingRequest request) { //1. Select join var query = from p in _context.Products join pt in _context.ProductTranslations on p.Id equals pt.ProductId join pic in _context.ProductInCategories on p.Id equals pic.ProductId join c in _context.Categories on pic.CategoryId equals c.Id where pt.LanguageId == request.LanguageId select new { p, pt, pic }; //2. filter if (request.CategoryId.HasValue && request.CategoryId.Value > 0) { query = query.Where(p => p.pic.CategoryId == request.CategoryId); } //3. Paging int totalRow = await query.CountAsync(); var data = await query.Skip((request.PageIndex - 1) *request.PageSize) .Take(request.PageSize) .Select(x => new ProductViewModel() { Id = x.p.Id, Name = x.pt.Name, DateCreated = x.p.DateCreated, Description = x.pt.Description, Details = x.pt.Details, LanguageId = x.pt.LanguageId, OriginalPrice = x.p.OriginalPrice, Price = x.p.Price, SeoAlias = x.pt.SeoAlias, SeoDescription = x.pt.SeoDescription, SeoTitle = x.pt.SeoTitle, Stock = x.p.Stock, ViewCount = x.p.ViewCount }).ToListAsync(); //4. Select and projection var pagedResult = new PagedResult <ProductViewModel>() { TotalRecord = totalRow, Items = data }; return(pagedResult); }
public async Task <PagedResult <ProductVm> > GetAllByCategoryId(GetPublicProductPagingRequest request) { var query = from p in _context.products join pt in _context.productCategories on p.idCategory equals pt.idCategory select new { p, pt }; //2. filter if (request.idCategory != null) { query = query.Where(p => p.pt.idCategory == request.idCategory); } //3. Paging int totalRow = await query.CountAsync(); var data = await query.Skip((request.PageIndex - 1) *request.PageSize) .Take(request.PageSize) .Select(x => new ProductVm() { idProduct = x.p.idProduct, productName = x.p.productName, idSize = x.p.idSize, idBrand = x.p.idBrand, idColor = x.p.idColor, idType = x.p.idType, idCategory = x.p.idCategory, price = x.p.price, salePrice = x.p.salePrice, detail = x.p.detail, dateAdded = DateTime.Now, photoReview = "a", }).ToListAsync(); //4. Select and projection var pagedResult = new PagedResult <ProductVm>() { TotalRecords = totalRow, PageIndex = request.PageIndex, PageSize = request.PageSize, Items = data }; return(pagedResult); }
public async Task <PagedResult <ProductViewModel> > GetAllByCategoryId(GetPublicProductPagingRequest request) { //Buoc 1: Select join var query = from p in _context.Products join pd in _context.ProductDetails on p.Id equals pd.ProductId join pic in _context.ProductInCategories on p.Id equals pic.ProductId join c in _context.Categories on pic.ProductId equals c.Id select new { p, pd, pic }; //Buoc 2: Filter if (request.CategoryId.HasValue && request.CategoryId.Value > 0) //HasValue = true và Value hớn hơn 0 { query = query.Where(p => p.pic.CategoryId == request.CategoryId); } //Buoc 3: Paging int totalRow = await query.CountAsync(); var data = await query.Skip((request.PageIndex - 1) *request.PageSize) .Take(request.PageSize) .Select(x => new ProductViewModel() //x là kết quả tìm kiếm được { Id = x.p.Id, Name = x.pd.Name, DateCreated = x.p.DateCreated, Description = x.pd.Description, Details = x.pd.Details, OriginalPrice = x.p.OriginalPrice, Price = x.p.Price, Stock = x.p.Stock, ViewCount = x.p.ViewCount }).ToListAsync(); //Buoc 4: Select and projection var pagedResult = new PagedResult <ProductViewModel>() { TotalRecords = totalRow, PageSize = request.PageSize, PageIndex = request.PageIndex, Items = data }; return(pagedResult); }
public async Task <PagedResult <ProductViewModel> > GetPublicProducts(GetPublicProductPagingRequest request) { var client = _httpClientFactory.CreateClient(); client.BaseAddress = new Uri(_configuration["BaseAddress"]); var sessions = _httpContextAccessor.HttpContext.Session.GetString("Token"); client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", sessions); var json = JsonConvert.SerializeObject(request); var httpContent = new StringContent(json, Encoding.UTF8, "application/json"); var respone = await client.PostAsync($"/api/product/publicfilter", httpContent); var body = await respone.Content.ReadAsStringAsync(); var product = JsonConvert.DeserializeObject <PagedResult <ProductViewModel> >(body); return(product); }
public async Task <PagedResult <ProductViewModel> > GetAllByCategoryId(GetPublicProductPagingRequest request) { var query = from p in _context.products join pt in _context.productDetails on p.idProduct equals pt.idProduct join pic in _context.ProductInCategories on p.idProduct equals pic.idProduct join c in _context.productCategories on pic.idCategory equals c.idCategory select new { p, pt, pic }; //2. filter if (request.idCategory.HasValue && request.idCategory.Value > 0) { query = query.Where(p => p.pic.idCategory == request.idCategory); } //3. Paging int totalRow = await query.CountAsync(); var data = await query.Skip((request.PageIndex - 1) *request.PageSize) .Take(request.PageSize) .Select(x => new ProductViewModel() { Id = x.p.idProduct, ProductName = x.pt.ProductName, price = x.pt.price, salePrice = x.pt.salePrice, ViewCount = x.p.ViewCount, detail = x.pt.detail, }).ToListAsync(); //4. Select and projection var pagedResult = new PagedResult <ProductViewModel>() { TotalRecords = totalRow, PageIndex = request.PageIndex, PageSize = request.PageSize, Items = data }; return(pagedResult); }
public async Task <PagedResult <ProductViewModel> > GetAllByCategoryId(GetPublicProductPagingRequest request) { var query = from p in shopDBContext.Products join pt in shopDBContext.ProductTranslations on p.ID equals pt.ProductId join pic in shopDBContext.ProductInCategories on p.ID equals pic.ProductID join c in shopDBContext.Categories on pic.CategoryID equals c.ID where pt.LanguageId == request.LanguageID && pic.CategoryID == request.CategoryID select new { p, pt, pic }; var data = await query.Skip((request.PageIndex - 1) *request.PageSize) .Take(request.PageSize) .Select(x => new ProductViewModel() { Id = x.p.ID, Name = x.pt.Name, DateCreated = x.p.DateCreated, Description = x.pt.Description, Details = x.pt.Details, LanguageId = x.pt.LanguageId, OriginalPrice = x.p.OriginalPrice, Price = x.p.Price, SeoAlias = x.pt.SeoAlias, SeoDescription = x.pt.SeoDescription, SeoTitle = x.pt.SeoTitle, Stock = x.p.Stock, ViewCount = x.p.ViewCount }).ToListAsync(); var pagedResult = new PagedResult <ProductViewModel>() { TotalRecords = await query.CountAsync(), Items = data }; return(pagedResult); }
public async Task <IActionResult> GetAllPaging(string languageId, [FromQuery] GetPublicProductPagingRequest request) { var products = await _productService.GetAllByCategoryId(languageId, request); return(Ok(products)); }
public Task <PageResult <ProductVm> > GetAllByCategoryId(GetPublicProductPagingRequest request) { throw new NotImplementedException(); }
public async Task <PagedResult <ProductViewModel> > GetAllByCategoryId(string languageId, GetPublicProductPagingRequest request) { var query = from p in _context.ProductRepository.GetQuery() join pt in _context.ProductTranslationRepository.GetQuery() on p.Id equals pt.ProductId join pic in _context.ProductInCategoryRepository.GetQuery() on p.Id equals pic.ProductId join c in _context.CategoryRepository.GetQuery() on pic.CategoryId equals c.Id where pt.LanguageId == languageId select(new { p, pt, pic }); if (request.CategoryId.HasValue && request.CategoryId.Value > 0) { query = query.Where(x => x.pic.CategoryId == request.CategoryId); } var totalRow = await query.CountAsync(); var data = await query.Skip((request.PageIndex - 1) *request.PageSize).Take(request.PageSize) .Select(x => new ProductViewModel() { Id = x.p.Id, Price = x.p.Price, Original = x.p.Original, Stock = x.p.Stock, ViewCount = x.p.ViewCount, DateCreated = x.p.DateCreated, Name = x.pt.Name, Description = x.pt.Description, Details = x.pt.Details, SeoDescription = x.pt.SeoDescription, SeoTitle = x.pt.SeoTitle, SeoAlias = x.pt.SeoAlias, LanguageId = x.pt.LanguageId }).ToListAsync(); var pagedResult = new PagedResult <ProductViewModel> { PageSize = request.PageSize, PageIndex = request.PageIndex, Items = data, TotalRecords = totalRow }; return(pagedResult); }
public async Task <IActionResult> GetAllPaging(string languageId, [FromQuery] GetPublicProductPagingRequest request) {//FROMQUERY là tất cá các tham số Get...PagingRequest là nó lấy từ query ra var products = await _publicProductService.GetAllByCategoryId(languageId, request); return(Ok(products)); }
public async Task <ApiResult <PagedResult <ProductViewModel> > > GetAllBySupplierID(GetPublicProductPagingRequest request) { var query = from p in _context.ProductImage join pis in _context.ProductInSuppliers on p.Prod_ID equals pis.Prod_ID join s in _context.Suppliers on pis.Supplier_ID equals s.Supplier_ID select new { p, pis, s }; if (request.Supplier_ID.HasValue && request.Supplier_ID.Value > 0) { query = query.Where(p => p.pis.Supplier_ID == request.Supplier_ID); } //Paging int totalRow = await query.CountAsync(); var data = await query.Skip((request.PageIndex - 1) *request.PageSize) .Take(request.PageSize) .Select(x => new ProductViewModel() { Prod_ID = x.p.Prod_ID, Prod_Name = x.p.Prod_Name, DateCreate = x.p.DateCreate, Description = x.p.Description, Price = x.p.Price, Quantity = x.p.Quantity, Status = x.p.Status }).ToListAsync(); //Select and projection var pagedResult = new PagedResult <ProductViewModel>() { TotalRecords = totalRow, Items = data }; return(new ApiSuccessResult <PagedResult <ProductViewModel> >(pagedResult)); }
public async Task <IActionResult> Get([FromQuery] GetPublicProductPagingRequest request) { var products = await _publicProductService.GetAllCategoryId(request); return(Ok(products)); }
public PagedResult <ProductOverViewModel> GetPublicProducts(GetPublicProductPagingRequest request) { try { var query = from p in _context.Products join pic in _context.CategoryProducts on p.id equals pic.product_id join c in _context.Categories on pic.cate_id equals c.id where p.isDelete == false select new { p, pic, c }; if (!String.IsNullOrEmpty(request.Keyword)) { query = query.Where(x => EF.Functions.Like(x.p.name, $"%{request.Keyword}%")); } if (!String.IsNullOrEmpty(request.CategorySlug)) { query = query.Where(x => x.c.cate_slug.Equals(request.CategorySlug)); } if (!String.IsNullOrEmpty(request.BrandSlug)) { query = query.Where(x => x.p.Brand.brand_slug.Equals(request.BrandSlug)); } switch (request.idSortType) { case 1: query = query.OrderBy(x => x.p.name); break; case 2: query = query.OrderByDescending(x => x.p.name); break; case 3: query = query.OrderBy(x => x.p.promotion_price > 0 ? x.p.promotion_price : x.p.unit_price); break; case 4: query = query.OrderByDescending(x => x.p.promotion_price > 0 ? x.p.promotion_price : x.p.unit_price); break; } if (request.Lowestprice != null && request.Highestprice != null) { query = query.Where(x => (x.p.promotion_price > 0 ? x.p.promotion_price : x.p.unit_price) >= request.Lowestprice && (x.p.promotion_price > 0 ? x.p.promotion_price : x.p.unit_price) <= request.Highestprice); } else if (request.Lowestprice != null && request.Highestprice == null) { query = query.Where(x => (x.p.promotion_price > 0 ? x.p.promotion_price : x.p.unit_price) >= request.Lowestprice); } else if (request.Lowestprice == null && request.Highestprice != null) { query = query.Where(x => (x.p.promotion_price > 0 ? x.p.promotion_price : x.p.unit_price) <= request.Highestprice); } var data = query.AsEnumerable() .GroupBy(g => g.p); int totalRow = data.Count(); List <ProductOverViewModel> result = data.Skip((request.PageIndex - 1) * request.PageSize) .Take(request.PageSize) .Select(a => new ProductOverViewModel() { id = a.Key.id, name = a.Key.name, best_seller = a.Key.best_seller, create_at = a.Key.create_at, featured = a.Key.featured, image = a.Key.image, instock = a.Key.instock, promotion_price = a.Key.promotion_price, short_desc = a.Key.short_desc, slug = a.Key.slug, isActive = a.Key.isActive, unit_price = a.Key.unit_price, }).ToList(); var pageResult = new PagedResult <ProductOverViewModel>() { TotalRecords = totalRow, PageSize = request.PageSize, PageIndex = request.PageIndex, Items = result, }; return(pageResult); } catch { var pageResult = new PagedResult <ProductOverViewModel>() { TotalRecords = 0, PageSize = request.PageSize, PageIndex = request.PageIndex, Items = null, }; return(pageResult); } }
Task <PageResult <ProductViewModel> > IPublicProductService.GetAllByCategoryId(String languageId, GetPublicProductPagingRequest request) { throw new NotImplementedException(); }
public async Task <PagedResult <ProductViewModel> > GetAllByCategoryId(GetPublicProductPagingRequest request) { var output = new PagedResult <ProductViewModel>(); //b1. select join var query = from p in _context.Products join pt in _context.ProductTranslations on p.Id equals pt.ProductId join pic in _context.ProductInCategories on p.Id equals pic.ProductId join c in _context.Categories on pic.CategoryId equals c.Id where pt.LanguageId == request.LanguageId select new { p, pt, pic }; //b2. filter if (request.CategoryId.HasValue && request.CategoryId.Value > 0) { query = query.Where(p => p.pic.CategoryId == request.CategoryId); } else { output.Message = "CategoryId ko duoc de trong!!!"; output.ResultCode = 0; return(output); } //var user = (_context.Categories.Find(x => x. == request.CategoryId)).FirstOrDefault(); //if (user == null) //{ // output.ResultCode = 0; // output.Message = "Invalid User!"; // return output; //} if (string.IsNullOrEmpty(request.LanguageId)) { output.Message = "LanguageId ko duoc de trong!!!"; output.ResultCode = 0; return(output); } //b3. paging int totalRow = await query.CountAsync(); var data = await query.Skip((request.pageIndex - 1) *request.pageSize) .Take(request.pageSize) .Select(x => new ProductViewModel() { Id = x.p.Id, Name = x.pt.Name, DateCreated = x.p.DateCreated, Description = x.pt.Description, Details = x.pt.Details, SeoDesciption = x.pt.SeoDesciption, SeoAlias = x.pt.SeoAlias, SeoTitle = x.pt.SeoTitle, LanguageId = x.pt.LanguageId, OriginalPrice = x.p.OriginalPrice, Price = x.p.Price, Stock = x.p.Stock, ViewCount = x.p.ViewCount, } ).ToListAsync(); //b4. select and projection var pagedResult = new PagedResult <ProductViewModel>() { TotalRecords = totalRow, Items = data, PageSize = request.pageSize, PageIndex = request.pageIndex, Message = "Success!", ResultCode = 1 }; return(pagedResult); }
public async Task <PageResult <ProductViewModel> > GetAllByCategoryId(string languageId, GetPublicProductPagingRequest request) { var query = from p in _context.Products join pt in _context.ProductTranslations on p.Id equals pt.ProductId join pic in _context.ProductInCategories on p.Id equals pic.ProductId select new { p, pt, pic }; if (request.CategoryId.HasValue && request.CategoryId.Value > 0) { query = query.Where(x => x.pic.CategoryId == request.CategoryId); } if (!string.IsNullOrEmpty(languageId)) { query = query.Where(x => x.pt.LanguageId == languageId); } int totalRows = await query.CountAsync(); var data = await query.Skip((request.pageIndex - 1) *request.pageSize).Take(request.pageSize) .Select(x => new ProductViewModel() { Id = x.p.Id, Price = x.p.Price, OriginalPrice = x.p.Price, Stock = x.p.Stock, ViewCount = x.p.ViewCount, DateCreated = x.p.DateCreated, SeoAlias = x.pt.SeoAlias, SeoDescription = x.pt.SeoDescription, SeoTitle = x.pt.SeoTitle, Description = x.pt.Description, Details = x.pt.Details, Name = x.pt.Name, LanguageId = x.pt.LanguageId }).ToListAsync(); var pageResult = new PageResult <ProductViewModel>() { TotalRecord = totalRows, Items = data }; return(pageResult); }