public List <ProductQuantityViewModel> GetQuantity(int productId)
        {
            var productQuantityModel = _productQuantityRepository.FindAll(x => x.ProductId == productId);
            var productQuantityVm    = Mapper.Map <List <ProductQuantity>, List <ProductQuantityViewModel> >(productQuantityModel.ToList());

            return(productQuantityVm);
        }
Exemplo n.º 2
0
        public List <ColorViewModel> GetColorByProduct(int productId)
        {
            var query = (from t in _productQuantityRepository.FindAll()
                         join pt in _colorRepository.FindAll()
                         on t.ColorId equals pt.Id
                         where t.ProductId == productId
                         select pt).Distinct();

            return(query.ProjectTo <ColorViewModel>().ToList());
        }
Exemplo n.º 3
0
 public void AddQuantity(int productId, List <ProductQuantityViewModel> quantities)
 {
     _productQuantityRepository.RemoveMultiple(_productQuantityRepository.FindAll(x => x.ProductId == productId).ToList());
     foreach (var quantity in quantities)
     {
         _productQuantityRepository.Add(new ProductQuantity()
         {
             ProductId          = productId,
             ProductConditionId = quantity.ProductConditionId,
             Quantity           = quantity.Quantity
         });
     }
 }
Exemplo n.º 4
0
        public List <ProductQuantityModel> GetQuantityByProductId(int productId)
        {
            var model = new List <ProductQuantityModel>();

            if (productId > 0)
            {
                var productQuantity = _productQuantityRepository.FindAll().Where(q => q.ProductId == productId).Select(q => q.ToModel()).ToList();
                if (productQuantity != null && productQuantity.Count > 0)
                {
                    model = productQuantity;
                }
            }
            return(model);
        }
Exemplo n.º 5
0
 public void AddQuantity(int productId, List <ProductQuantityViewModel> quantities)
 {
     _productQuantityRepository.RemoveMultiple(_productQuantityRepository.FindAll(x => x.ProductId == productId).ToList());
     foreach (var quantity in quantities)
     {
         _productQuantityRepository.Add(new ProductQuantity()
         {
             ProductId  = productId,
             ColorId    = quantity.ColorId,
             PerfumeId  = quantity.PerfumeId,
             SizeId     = quantity.SizeId,
             Quantity   = quantity.Quantity,
             MoreImages = quantity.MoreImages
         });
     }
 }
Exemplo n.º 6
0
        public async Task AddQuantity(int productId, List <ProductQuantityViewModel> quantities)
        {
            var dataNeedDelete = await _productQuantityRepository.FindAll(x => x.ProductId == productId);

            await _productQuantityRepository.RemoveMultiple(dataNeedDelete.AsNoTracking().ToList());

            foreach (var quantity in quantities)
            {
                await _productQuantityRepository.Add(new ProductQuantity()
                {
                    ProductId = productId,
                    ColorId   = quantity.ColorId,
                    SizeId    = quantity.SizeId,
                    Quantity  = quantity.Quantity
                });
            }
        }
Exemplo n.º 7
0
        public List <ColorViewModel> GetColors(int productId)
        {
            var productQuantityVm = _productQuantityRepository.FindAll(x => x.ProductId == productId)
                                    .ProjectTo <ProductQuantityViewModel>().ToList();

            var res = (from t in productQuantityVm
                       join s in _colorRepository.FindAll()
                       on t.ColorId equals s.Id
                       select new
            {
                Id = s.Id,
                Name = s.Name,
                Code = s.Code
            }).AsEnumerable().Select(x => new ColorViewModel()
            {
                Id   = x.Id,
                Name = x.Name,
                Code = x.Code
            });

            return(res.Distinct().ToList());
        }
Exemplo n.º 8
0
        public async Task <ModelListResult <ProductFullViewModel> > FilterProducts(ProductRequest request)
        {
            List <ProductFullViewModel> response = new List <ProductFullViewModel>();
            var categoryEntities = await _categoryRepository.FindAll();

            var productEntities = await _productRepository.FindAllProductAsync(x => true);

            var productQuantityEntities = await _productQuantity.FindAll();

            if (request.ColorId > 0 && request.SizeId > 0)
            {
                response = (from c in categoryEntities.AsNoTracking()
                            join p in productEntities.AsNoTracking() on c.Id equals p.CategoryId
                            join quan in productQuantityEntities.AsNoTracking() on p.Id equals quan.ProductId
                            where quan.ColorId == request.ColorId && quan.SizeId == request.SizeId
                            select new ProductFullViewModel
                {
                    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,
                    ColorId = quan.ColorId,
                    SizeId = quan.SizeId
                }).ToList();
            }
            else if (request.ColorId > 0)
            {
                response = (from c in categoryEntities.AsNoTracking()
                            join p in productEntities.AsNoTracking() on c.Id equals p.CategoryId
                            join quan
                            in productQuantityEntities.AsNoTracking() on p.Id equals quan.ProductId
                            where quan.ColorId == request.ColorId
                            select new ProductFullViewModel
                {
                    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,
                    ColorId = quan.ColorId,
                    SizeId = quan.SizeId
                }).ToList();
            }
            else if (request.SizeId > 0)
            {
                response = (from c in categoryEntities.AsNoTracking()
                            join p in productEntities.AsNoTracking() on c.Id equals p.CategoryId
                            join quan
                            in productQuantityEntities.AsNoTracking() on p.Id equals quan.ProductId
                            where quan.SizeId == request.SizeId
                            select new ProductFullViewModel
                {
                    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,
                    ColorId = quan.ColorId,
                    SizeId = quan.SizeId
                }).ToList();
            }
            else
            {
                response = (from c in categoryEntities.AsNoTracking()
                            join p in productEntities.AsNoTracking() on c.Id equals p.CategoryId

                            select new ProductFullViewModel
                {
                    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,
                }).ToList();
            }
            if (!string.IsNullOrEmpty(request.SearchText))
            {
                response = response.AsParallel().Where(x => x.Name.Contains(request.SearchText)).ToList();
            }
            else if (!string.IsNullOrEmpty(request.Name))
            {
                response = response.AsParallel().Where(x => x.Name.Contains(request.Name)).ToList();
            }
            else if (request?.CategoryId > 0)
            {
                response = response.AsParallel().Where(x => x.CategoryId == request.CategoryId).ToList();
            }
            else if (request.ColorId > 0)
            {
                response = response.AsParallel().Where(x => x.ColorId == request.CategoryId).ToList();
            }
            else if (request.SizeId > 0)
            {
                response = response.AsParallel().Where(x => x.SizeId == request.SizeId).ToList();
            }

            var totalCount = response.AsParallel().WithExecutionMode(ParallelExecutionMode.ForceParallelism).AsParallel().AsOrdered().Count();

            if (request.IsPaging)
            {
                response = response.AsParallel().OrderByDescending(x => x.DateModified)
                           .Skip((request.PageIndex - 1) * request.PageSize).Take(request.PageSize).ToList();
            }
            return(new ModelListResult <ProductFullViewModel>()
            {
                Items = response.ToList(),
                Message = Message.Success,
                RowCount = totalCount,
                PageSize = request.PageSize,
                PageIndex = request.PageIndex
            });
        }
Exemplo n.º 9
0
 public List <ProductQuantityViewModel> GetQuantities(int productId)
 {
     return(productQuantityRepository.FindAll(x => x.ProductId == productId).ProjectTo <ProductQuantityViewModel>().ToList());
 }