Example #1
0
        public async Task <ActionResult <IEnumerable <Produit> > > GetProduitsHomePage(int?page, int pagesize = 10, string souscategorie = "")
        {
            var prods = new List <Produit>();

            if (string.IsNullOrEmpty(souscategorie))
            {
                prods = await _context.Produits.ToListAsync();
            }
            else
            {
                prods = await _context.Produits.Include(x => x.SousCategorie).Where(x => x.SousCategorie.NsousCategorie == souscategorie).ToListAsync();
            }

            var countDetails = prods.Count();

            var result = new GIS.Models.Query.PageResult <Produit>
            {
                Count     = countDetails,
                PageIndex = page ?? 0,
                PageSize  = pagesize,
                Items     = prods.Skip((page ?? 0) * pagesize).Take(pagesize).ToList(),
            };

            return(Ok(result));
        }
Example #2
0
        public async Task <ActionResult <IEnumerable <Produit> > > GetProduits(int?page, int pagesize = 10)
        {
            var prods = await _context.Produits.ToListAsync();


            var countDetails = prods.Count();

            var result = new GIS.Models.Query.PageResult <Produit>
            {
                Count     = countDetails,
                PageIndex = page ?? 0,
                PageSize  = pagesize,
                Items     = prods.Skip((page ?? 0) * pagesize).Take(pagesize).ToList(),
            };

            return(Ok(result));
        }
Example #3
0
        public async Task <ActionResult <IQueryable <Produit> > > SearchProduitsAsync(int?page, int pagesize = 10, string filter = "", string filterPrix = "desc")
        {
            List <Produit> prods;

            if (!string.IsNullOrEmpty(filter))
            {
                string cleanfilter = StringCleaner(filter);
                if (filterPrix == "desc")
                {
                    prods = await _context.Produits
                            .OrderByDescending(x => x.Prix)
                            .Include(x => x.SousCategorie)
                            .Where(
                        x => EF.Functions.Like(cleanfilter, ("%" + StringCleaner(x.NomProduit) + "%")) ||
                        EF.Functions.Like(StringCleaner(x.NomProduit), ("%" + cleanfilter + "%")) ||
                        cleanfilter.Contains(StringCleaner(x.NomProduit))

                        || EF.Functions.Like(cleanfilter, ("%" + StringCleaner(x.SousCategorie.NsousCategorie) + "%")) ||
                        EF.Functions.Like(StringCleaner(x.SousCategorie.NsousCategorie), ("%" + cleanfilter + "%")) ||
                        cleanfilter.Contains(StringCleaner(x.SousCategorie.NsousCategorie))

                        || EF.Functions.Like(cleanfilter, ("%" + StringCleaner(x.Marque) + "%")) ||
                        EF.Functions.Like(x.Marque, ("%" + cleanfilter + "%")) ||
                        cleanfilter.Contains(StringCleaner(x.Marque))
                        ).ToListAsync();
                }
                else
                {
                    prods = await _context.Produits
                            .OrderBy(x => x.Prix)
                            .Include(x => x.SousCategorie)
                            .Where(
                        x => EF.Functions.Like(cleanfilter, (StringCleaner("%" + x.NomProduit + "%"))) ||
                        EF.Functions.Like(x.NomProduit, (StringCleaner("%" + cleanfilter + "%")))

                        || EF.Functions.Like(cleanfilter, (StringCleaner("%" + x.SousCategorie.NsousCategorie + "%"))) ||
                        EF.Functions.Like(x.SousCategorie.NsousCategorie, (StringCleaner("%" + cleanfilter + "%")))

                        || EF.Functions.Like(cleanfilter, (StringCleaner("%" + x.Marque + "%"))) ||
                        EF.Functions.Like(x.Marque, (StringCleaner("%" + cleanfilter + "%")))).ToListAsync();
                }
            }
            else
            {
                if (filterPrix == "desc")
                {
                    prods = await _context.Produits.Include(x => x.SousCategorie).OrderByDescending(x => x.Prix).ToListAsync();
                }
                else
                {
                    prods = await _context.Produits.Include(x => x.SousCategorie).OrderBy(x => x.Prix).ToListAsync();
                }
            }


            var countDetails = prods.Count();

            var result = new GIS.Models.Query.PageResult <Produit>
            {
                Count          = countDetails,
                PageIndex      = page ?? 0,
                PageSize       = pagesize,
                Items          = prods.Skip((page ?? 0) * pagesize).Take(pagesize).ToList(),
                FilterProdName = filter
            };

            return(Ok(result));
        }
Example #4
0
        public ActionResult <IQueryable <Produit> > GetProduits([FromBody] List <SimpleCaracDto> specs, int?page, int pagesize = 10, string sousCategorie = "", string filter = "", string filterPrix = "desc")
        {
            var           prods2        = new HashSet <Produit>();
            var           caracs        = new Dictionary <string, List <string> >();
            var           returnedcracs = new List <CaracDto>();
            List <string> brands        = new List <string>();
            List <string> filters       = new List <string>();

            string[] brandstofilter = {};

            if (!string.IsNullOrEmpty(filter))
            {
                brandstofilter = filter.Split(",");
            }


            if (string.IsNullOrEmpty(sousCategorie))
            {
                if (filterPrix == "desc")
                {
                    _context.Produits.Include(x => x.SousCategorie).OrderByDescending(x => x.Prix)
                    .ToList().ForEach(x => prods2.Add(x));
                }
                else
                {
                    _context.Produits.Include(x => x.SousCategorie).OrderBy(x => x.Prix)
                    .ToList().ForEach(x => prods2.Add(x));
                }


                if (!string.IsNullOrEmpty(filter))
                {
                    var filtredprods = new HashSet <Produit>();
                    foreach (var brand in brandstofilter)
                    {
                        foreach (var prod in prods2)
                        {
                            if (prod.Marque == brand)
                            {
                                filtredprods.Add(prod);
                            }
                        }
                    }
                    prods2 = filtredprods;
                    //var prodlist = prods2.Where(p => filter.ToLower().Contains(p.Marque.ToLower()))
                    //    .ToList();

                    //prodlist.ToList().ForEach(x => prods2.Add(x));
                }
            }
            else
            {
                if (specs.Count() != 0)
                {
                    //When whe have specs and we should filter products

                    if (filterPrix == "desc")
                    {
                        //prods2 = await _context.Produits.Include(x => x.SousCategorie).Where(x => x.SousCategorie.NsousCategorie.ToLower() == sousCategorie).Include(x => x.Caracteristiques).OrderByDescending(x => x.Prix).ToListAsync();

                        //******************************************************************************************************
                        //******************************************************************************************************

                        specs.ForEach(carac =>
                        {
                            _context.Caracteristique
                            .Include(x => x.Produit)
                            .ThenInclude(x => x.SousCategorie)
                            .OrderByDescending(x => x.Produit.Prix)
                            .Where(x => x.Produit.SousCategorie.NsousCategorie == sousCategorie)
                            .Where(x => x.Key == carac.Key && x.Value == carac.Value)
                            .Select(x => x.Produit)
                            .ToList()
                            .ForEach(x =>
                            {
                                if (!prods2.Any(p => p.IdProd == x.IdProd))
                                {
                                    prods2.Add(x);
                                }
                            });
                        });


                        //************************************************************************************************************
                        //*****************************************************************************************************************
                    }
                    else
                    {
                        //_context.Produits
                        //    .Include(x => x.SousCategorie)
                        //    .Where(x => x.SousCategorie.NsousCategorie.ToLower() == sousCategorie)
                        //    .Include(x => x.Caracteristiques).OrderBy(x => x.Prix)
                        //    .ToList().ForEach(x => prods2.Add(x));

                        //*****************************************************************************************************************
                        //*****************************************************************************************************************

                        specs.ForEach(carac =>
                        {
                            _context.Caracteristique
                            .Include(x => x.Produit)
                            .ThenInclude(x => x.SousCategorie)
                            .OrderBy(x => x.Produit.Prix)
                            .Where(x => x.Produit.SousCategorie.NsousCategorie == sousCategorie)
                            .Where(x => x.Key == carac.Key && x.Value == carac.Value)
                            .Select(x => x.Produit)
                            .ToList()
                            .ForEach(x =>
                            {
                                if (!prods2.Any(p => p.IdProd == x.IdProd))
                                {
                                    prods2.Add(x);
                                }
                            });
                        });


                        //*****************************************************************************************************************
                        //*****************************************************************************************************************
                    }
                }
                else
                {
                    //Normal process
                    if (filterPrix == "desc")
                    {
                        _context.Produits
                        .Include(x => x.SousCategorie)
                        .Where(x => x.SousCategorie.NsousCategorie.ToLower() == sousCategorie)
                        .Include(x => x.Caracteristiques)
                        .OrderByDescending(x => x.Prix)
                        .ToList().ForEach(x => prods2.Add(x));
                    }
                    else
                    {
                        _context.Produits
                        .Include(x => x.SousCategorie)
                        .Where(x => x.SousCategorie.NsousCategorie.ToLower() == sousCategorie)
                        .Include(x => x.Caracteristiques)
                        .OrderBy(x => x.Prix)
                        .ToList().ForEach(x => prods2.Add(x));
                    }
                }
                if (!string.IsNullOrEmpty(filter))
                //if (filter.Count()!=0)
                {
                    var filtredprods = new HashSet <Produit>();
                    foreach (var brand in brandstofilter)
                    {
                        foreach (var prod in prods2)
                        {
                            if (prod.Marque == brand)
                            {
                                filtredprods.Add(prod);
                            }
                        }
                    }
                    prods2 = filtredprods;
                    //prods2.Where(p => filter.ToLower().Contains(p.Marque.ToLower()))
                    // .ToList().ForEach(x => prods2.Add(x));
                }

                var caracteristiques = new List <Caracteristique>();
                prods2.SelectMany(x => x.Caracteristiques).ToList().ForEach(x => caracteristiques.Add(x));
                caracteristiques.ForEach(c =>
                {
                    if (caracs.Keys.Contains(c.Key))
                    {
                        if (caracs[c.Key] == null)
                        {
                            caracs[c.Key] = new List <string>();
                        }

                        if (!caracs[c.Key].Contains(c.Value))
                        {
                            caracs[c.Key].Add(c.Value);
                        }
                    }
                    else
                    {
                        caracs.Add(c.Key, new List <string>()
                        {
                            c.Value
                        });
                    }
                });

                foreach (KeyValuePair <string, List <string> > entry in caracs)
                {
                    returnedcracs.Add(new CaracDto(entry.Key, entry.Value));
                    // do something with entry.Value or entry.Key
                }
            }
            var brandys = new List <string>().AsEnumerable();

            if (string.IsNullOrEmpty(sousCategorie))
            {
                brandys = _context.Produits.Select(x => x.Marque).ToList()
                          .Distinct();
            }
            else
            {
                brandys = _context.Produits
                          .Include(x => x.SousCategorie)
                          .Where(x => x.SousCategorie.NsousCategorie == sousCategorie)
                          .Select(x => x.Marque).ToList()
                          .Distinct();
            }

            foreach (var item in brandys)
            {
                brands.Add(item);
            }

            var countDetails = prods2.Count();

            var result = new GIS.Models.Query.PageResult <Produit>
            {
                Count     = countDetails,
                PageIndex = page ?? 0,
                PageSize  = pagesize,
                Items     = prods2.Skip((page ?? 0) * pagesize).Take(pagesize).ToList(),
                Brands    = brands.ToList(),
                Filters   = filters,
                Caracs    = returnedcracs
            };

            return(Ok(result));
        }
Example #5
0
        public ActionResult <IQueryable <Produit> > SearchProduitsAsyncBySpecs([FromBody] List <SimpleCaracDto> specs, int?page, int pagesize = 10, string sousCategorie = "", string filterPrix = "desc")
        {
            var caracteristiques = new List <Caracteristique>();

            var prods = new HashSet <Produit>();

            if (filterPrix == "desc")
            {
                specs.ForEach(carac =>
                {
                    _context.Caracteristique
                    .Include(x => x.Produit)
                    .ThenInclude(x => x.SousCategorie)
                    .OrderByDescending(x => x.Produit.Prix)
                    .Where(x => x.Produit.SousCategorie.NsousCategorie == sousCategorie)
                    .Where(x => x.Key == carac.Key && x.Value == carac.Value)
                    .Select(x => x.Produit)
                    .ToList()
                    .ForEach(x =>
                    {
                        if (!prods.Any(p => p.IdProd == x.IdProd))
                        {
                            prods.Add(x);
                        }
                    });
                });
            }
            else
            {
                specs.ForEach(carac =>
                {
                    _context.Caracteristique
                    .Include(x => x.Produit)
                    .ThenInclude(x => x.SousCategorie)
                    .OrderBy(x => x.Produit.Prix)
                    .Where(x => x.Produit.SousCategorie.NsousCategorie == sousCategorie)
                    .Where(x => x.Key == carac.Key && x.Value == carac.Value)
                    .Select(x => x.Produit)
                    .ToList()
                    .ForEach(x =>
                    {
                        if (!prods.Any(p => p.IdProd == x.IdProd))
                        {
                            prods.Add(x);
                        }
                    });
                });
            }

            var countDetails = prods.Count();

            var result = new GIS.Models.Query.PageResult <Produit>
            {
                Count     = countDetails,
                PageIndex = page ?? 0,
                PageSize  = pagesize,
                Items     = prods.Skip((page ?? 0) * pagesize).Take(pagesize).ToList(),
            };

            return(Ok(result));
        }