Пример #1
0
        public ForJsonShopProducts GetShopProductFormulaires(ref RequestShop requestShop)
        {
            Utils utils = new Utils();
            List <ProductFormulaire> listProductFormulaire = new List <ProductFormulaire>();

            if (requestShop.IsFirstRequest)
            {
                listProductFormulaire = (from p in context.Product
                                         join rp in context.Relationprix on p.Id equals rp.IdProduit
                                         join prix in context.Prix on rp.IdPrix equals prix.Id
                                         select new ProductFormulaire(p.Id, p.Nom, utils.CreatePathImg(p.Image.Trim(), true), p.Marque, prix.PrixUniraire)).ToList();

                requestShop.Total = listProductFormulaire.Count();
                if (listProductFormulaire.Count > requestShop.NbShow)
                {
                    int moduloPagination = listProductFormulaire.Count % requestShop.NbShow;
                    if (moduloPagination == 0)
                    {
                        requestShop.Pagination = listProductFormulaire.Count / requestShop.NbShow;
                        listProductFormulaire  = listProductFormulaire.GetRange(0, requestShop.NbShow);
                    }
                    else
                    {
                        requestShop.Pagination = (listProductFormulaire.Count - moduloPagination) / requestShop.NbShow;
                        requestShop.Pagination++;
                    }
                }
                else
                {
                    requestShop.Pagination = 1;
                }
                listProductFormulaire         = listProductFormulaire.GetRange(0, requestShop.NbShow);
                requestShop.CurrentPagination = 1;
                requestShop.CurrentTotal      = requestShop.NbShow;
            }
            else
            {
                listProductFormulaire = (from p in context.Product
                                         join rp in context.Relationprix on p.Id equals rp.IdProduit
                                         join prix in context.Prix on rp.IdPrix equals prix.Id
                                         select new ProductFormulaire(p.Id, p.Nom, utils.CreatePathImg(p.Image.Trim(), true), p.Marque, prix.PrixUniraire))
                                        .Skip(requestShop.CurrentTotal).Take(requestShop.NbShow * requestShop.CurrentPagination).ToList();
                requestShop.CurrentTotal = requestShop.NbShow * requestShop.CurrentPagination;
            }
            requestShop.IsFirstRequest = true;
            ForJsonShopProducts forJsonShopProducts = new ForJsonShopProducts(listProductFormulaire);

            return(forJsonShopProducts);
        }
Пример #2
0
        public ForJsonShopProducts GetShopProducts([FromBody] RequestShop requestShop)
        {
            ForJsonShopProducts shop;

            try
            {
                shop       = productRepository.GetShopProductFormulaires(ref requestShop);
                shop.Error = new CustomError(Status.ok);
            }
            catch (Exception ex)
            {
                shop = new ForJsonShopProducts(new CustomError(Status.error, ex.Message));
            }
            return(shop);
        }