public PageResult <ProductCategoryModel> GetSearchPaging(ProductSearch search) { var query = _productCategoryRepository.FindAll(); //if (search.Id > 0) //{ // query = query.Where(r => r.Id == search.Id); //} //if (!string.IsNullOrEmpty(search.Name)) //{ // query = query.Where(r => r.Name.Contains(search.Name)); //} //if (!string.IsNullOrEmpty(search.Description)) //{ // query = query.Where(r => r.Description.Contains(search.Description)); //} var Total = query.Count(); var data = query .OrderBy(f => f.CreatedDate) .Skip((search.PageIndex - 1) * search.PageSize) .Take(search.PageSize) .Select(f => f.ToModel()) .ToList(); foreach (var item in data) { if (item.ParentId != null && item.ParentId > 0) { var nameParent = data.Where(f => f.Id == item.ParentId).FirstOrDefault().Name; item.NameParent = nameParent; } } var result = new PageResult <ProductCategoryModel>() { Results = data, PageIndex = search.PageIndex, PageSize = search.PageSize, Total = Total, }; return(result); }
public PageResult <ProductViewModel> GetAllPaging(int?categoryId, string keyword, int page, int pageSize) { var query = _productRepository.FindAll(); if (!string.IsNullOrEmpty(keyword)) { query = query.Where(x => x.Name.Contains(keyword) || x.Description.Contains(keyword) || x.Id.ToString().Contains(keyword)); } if (categoryId.HasValue) { var childCates = _productCategoryRepository.FindAll(x => x.ParentId == categoryId); if (childCates.Count() > 0) { var productByCategories = from p in query join c in childCates on p.CategoryId equals c.Id select p; var productByParentId = query.Where(x => x.CategoryId == categoryId); query = productByCategories.Concat(productByParentId); } else { query = query.Where(x => x.CategoryId == categoryId.Value); } } int totalRow = query.Count(); query = query.OrderByDescending(x => x.CreatedDate).Skip((page - 1) * pageSize).Take(pageSize); var data = query.ProjectTo <ProductViewModel>().ToList(); return(new PageResult <ProductViewModel>() { CurentPage = page, PageSize = pageSize, Results = data, RowCount = totalRow }); }
public void Delete(int id) { var category = productCategoryRepository.FindById(id); var sibling = productCategoryRepository.FindAll(x => x.ParentId == category.ParentId && x.SortOrder > category.SortOrder && x.Id != category.Id); // update followed siblings from category int order = category.SortOrder; foreach (var item in sibling) { item.SortOrder = ++order; productCategoryRepository.Update(item); } productCategoryRepository.Remove(id); }
/// <summary> /// this method delets product from the category /// </summary> /// <param name="productId">product id</param> /// <param name="categoryId">category id</param> /// <param name="currentUserId">category id</param> public async Task <string> DeleteProductFromCategoryByIdAsync(int productId, int categoryId, string currentUserId) { var product = await _productRepository.GetByIdAsync(productId); var ProductCategory = _productCategoryRepository.FindAll().FirstOrDefault(x => x.ProductId == productId && x.CategoryId == categoryId); if (product == null) { throw new AuctionException("Product not found", System.Net.HttpStatusCode.NotFound); } else if (ProductCategory == null) { throw new AuctionException("Category not found", System.Net.HttpStatusCode.NotFound); } if (currentUserId == product.UserId) { _productCategoryRepository.Delete(ProductCategory); await _productCategoryRepository.SaveAsync(); return($"Product has been removed from category, Category Id :{categoryId}, ProductId : {productId}"); } throw new AuctionException("Product doesn't belong to user", System.Net.HttpStatusCode.Forbidden); }
public PagedResult <ProductViewModel> GetAllPaging(int?categoryId, string keyword, int page, int pageSize, string SortBy) { var query = productRepository.FindAll(p => p.Status == Status.Active); if (categoryId.HasValue) { var subCategories = productCategoryRepository.FindAll(x => x.ParentId == categoryId); var CategoryIds = subCategories.Select(x => x.Id).ToList(); query = query.Where(p => p.CategoryId == categoryId.Value || CategoryIds.Contains(p.CategoryId)); } if (!string.IsNullOrWhiteSpace(keyword)) { //query = query.Where(p => p.Name.Contains(keyword) || // p.Description.Contains(keyword) || // p.Seokeywords.Contains(keyword) || // p.SeoDecription.Contains(keyword)); query = query.Where(p => p.Name.Contains(keyword) || p.Description.Contains(keyword)); } int totalRow = query.Count(); switch (SortBy) { case ProductSortType.Latest: query = query.OrderByDescending(p => p.DateCreated).Skip((page - 1) * pageSize).Take(pageSize); break; case ProductSortType.Name: query = query.OrderBy(p => p.Name).Skip((page - 1) * pageSize).Take(pageSize); break; case ProductSortType.Price: query = query.OrderByDescending(x => x.PromotionPrice.HasValue ? x.PromotionPrice : x.Price).Skip((page - 1) * pageSize).Take(pageSize); break; } var data = query.ProjectTo <ProductViewModel>().ToList(); var paginationSet = new PagedResult <ProductViewModel>() { Results = data, CurrentPage = page, RowCount = totalRow, PageSize = pageSize }; return(paginationSet); }
public GetProductCategorysResponse GetProductCategorys() { GetProductCategorysResponse response = new GetProductCategorysResponse(); try { IEnumerable <ProductCategoryView> productCategorys = _productCategoryRepository.FindAll() .ConvertToProductCategoryViews(); response.ProductCategoryViews = productCategorys; } catch (Exception ex) { } return(response); }
public async Task <List <ProductCategoryViewModel> > GetAll() { try { var dataReturn = (await _productCategoryRepository.FindAll()).OrderBy(x => x.ParentId).AsNoTracking().ToList(); var items = new ProductCategoryViewModel().Map(dataReturn).ToList(); return(items); } catch (Exception e) { Console.WriteLine(e); throw; } }
public async Task <PageListUtility <Product_Dto> > SearchProductWithPaginations(PaginationParams param, string productCateID, string productName, bool isPaging = true) { var productCateList = _productCategoryRepository.FindAll(); var productList = _productRepository.FindAll(); if (!string.IsNullOrEmpty(productCateID)) { productCateList = productCateList.Where(x => x.Product_Cate_ID == productCateID); } if (!string.IsNullOrEmpty(productName)) { productList = productList.Where(x => x.Product_Name == productName); } var query = productCateList.Join( productList, x => x.Product_Cate_ID, y => y.Product_Cate_ID, (x, y) => new Product_Dto { Amount = y.Amount, Content = y.Content, Discount = y.Discount, From_Date_Sale = y.From_Date_Sale, Hot_Sale = y.Hot_Sale, IsSale = y.IsSale, New = y.New, Price = y.Price, Price_Sale = y.Price_Sale, Product_Cate_ID = y.Product_Cate_ID, Product_ID = y.Product_ID, Product_Name = y.Product_Name, Status = y.Status, Time_Sale = y.Time_Sale, To_Date_Sale = y.To_Date_Sale, Update_By = y.Update_By, Update_Time = y.Update_Time, FileImages = y.FileImages, FileVideos = y.FileVideos }).OrderByDescending(x => x.Update_Time); return(await PageListUtility <Product_Dto> .PageListAsync(query, param.PageNumber, param.PageSize, isPaging)); }
public PageResult <ProductModel> GetSearchPaging(ProductSearch search) { var query = _productRepository.FindAll(p => p.ProductCategory). Select(p => new ProductModel() { Id = p.Id, CategoryId = p.CategoryId, Head = p.Head, Description = p.Description, Price = p.Price, PromotionalPrice = p.PromotionalPrice, Views = p.Views, ManufactureDate = p.ManufactureDate, ExpirationDate = p.ExpirationDate, IsDeteled = p.IsDeteled, CreatedDate = p.CreatedDate, UpdatedDate = p.UpdatedDate, Name = p.Name, ProductCategoryParent = _productCategoryRepository.FindAll().Where(pc => pc.Id == p.ProductCategory.ParentId).FirstOrDefault().ToModel(), ProductCategories = p.ProductCategory.ToModel() }); var Total = query.Count(); var data = query //.OrderByDescending(U => U.CreatedDate) .Skip((search.PageIndex - 1) * search.PageSize) .Take(search.PageSize) .ToList(); var result = new PageResult <ProductModel>() { Results = data, PageIndex = search.PageIndex, PageSize = search.PageSize, Total = Total, }; return(result); }
public async Task <ProductCategory_Dto> GetProductCategoryByID(string productCateID) { return(await _productCategoryRepository.FindAll(x => x.Product_Cate_ID == productCateID) .ProjectTo <ProductCategory_Dto>(_configuration).FirstOrDefaultAsync()); }
public List <ProductCategoryViewModel> GetAll() { return(_productCategoryRepository.FindAll().OrderBy(m => m.LevelCate).ThenBy(m => m.ParentId).ThenBy(m => m.SortOrder).ProjectTo <ProductCategoryViewModel>() .ToList()); }
public async Task <BaseReponse <ModelListResult <ProductViewModel> > > GetAllPaging(ProductRequest request) { var categoryEntities = await _categoryRepository.FindAll(); var productEntities = await _productRepository.FindAllProductAsync(x => true); var response = (from c in categoryEntities.AsNoTracking() join p in productEntities.AsNoTracking() on c.Id equals p.CategoryId select new ProductViewModel { Name = p.Name, Id = p.Id, CategoryId = p.CategoryId, ProductCategory = new ProductCategoryViewModel() { Name = c.Name }, Description = p.Description, Content = p.Content, DateCreated = p.DateCreated, DateModified = p.DateModified, HomeFlag = p.HomeFlag, HotFlag = p.HotFlag, Price = p.Price, OriginalPrice = p.OriginalPrice, PromotionPrice = p.PromotionPrice, SeoAlias = p.SeoAlias, SeoDescription = p.SeoDescription, SeoKeywords = p.SeoKeywords, SeoPageTitle = p.SeoPageTitle, Unit = p.Unit, ViewCount = p.ViewCount, Status = p.Status, Image = p.Image }).AsParallel(); if (!string.IsNullOrEmpty(request.SearchText)) { response = response.AsParallel().AsOrdered().WithDegreeOfParallelism(3).Where(x => x.Name.Contains(request.SearchText)); } else if (!string.IsNullOrEmpty(request.Name)) { response = response.AsParallel().AsOrdered().WithDegreeOfParallelism(3).Where(x => x.Name.Contains(request.Name)); } else if (request?.CategoryId > 0) { response = response.Where(x => x.CategoryId == request.CategoryId); } var totalCount = response.AsParallel().AsOrdered().Count(); if (request.IsPaging) { response = response.AsParallel().AsOrdered().WithDegreeOfParallelism(3).OrderByDescending(x => x.DateModified) .Skip((request.PageIndex - 1) * request.PageSize).Take(request.PageSize); } return(new BaseReponse <ModelListResult <ProductViewModel> >() { Data = new ModelListResult <ProductViewModel>() { Items = response.ToList(), Message = Message.Success, RowCount = totalCount, PageSize = request.PageSize, PageIndex = request.PageIndex }, Message = Message.Success, Status = (int)QueryStatus.Success }); }
public List <ProductCategoryViewModel> GetAll() { var categoryVms = _productCategoryRepository.FindAll().OrderBy(x => x.ParentId).ThenBy(x => x.SortOrder).ProjectTo <ProductCategoryViewModel>().ToList(); return(categoryVms); }
public PagedResult <ProductViewModel> GetAllPaging(int?categoryId, string keyword, int page, int pageSize, string sortBy) { var query = _productRepository.FindAll(x => x.Status == Status.Active); if (categoryId.HasValue) { if (categoryId.Value != 0) { var lstSubCatelog = _productCategoryRepository.FindAll(x => x.ParentId == categoryId) .Select(x => x.Id).ToList(); if (lstSubCatelog.Count == 0) { query = query.Where(x => x.CategoryId == categoryId.Value); } else { query = query.Where(x => lstSubCatelog.Contains(x.CategoryId)); } } } if (!string.IsNullOrEmpty(keyword)) { query = query.Where(x => x.Name.Contains(keyword)); } int totalRow = query.Count(); switch (sortBy) { case "PriceESC": query = query.OrderBy(x => x.PromotionPrice ?? x.Price) .Skip((page - 1) * pageSize).Take(pageSize); break; case "PriceDESC": query = query.OrderByDescending(x => x.PromotionPrice ?? x.Price) .Skip((page - 1) * pageSize).Take(pageSize); break; case "ViewCount": query = query.OrderByDescending(x => x.ViewCount) .Skip((page - 1) * pageSize).Take(pageSize); break; default: query = query.OrderByDescending(x => x.DateCreated) .Skip((page - 1) * pageSize).Take(pageSize); break; } var data = query.ProjectTo <ProductViewModel>().ToList(); var paginationSet = new PagedResult <ProductViewModel>() { Results = data, CurrentPage = page, RowCount = totalRow, PageSize = pageSize }; return(paginationSet); }
public List <ProductCategoryViewModel> GetAll() { //extension project just used for IQueryable return(_productCategoryRepository.FindAll().OrderBy(n => n.ParentId).ProjectTo <ProductCategoryViewModel>() .ToList()); }
public Task <List <ProductCategory> > GetAll() { return(_productCategoryRepository.FindAll().ToListAsync()); }
public List <ProductCategoryViewModel> GetAll() { return(_productCategoryRepository.FindAll().OrderBy(x => x.ParentId) .ProjectTo <ProductCategoryViewModel>().ToList()); }
public List <ProductCategoryViewModel> GetAll() { return(_mapper.Map <List <ProductCategoryViewModel> >(_productCategoryRepository.FindAll().ToList())); }