示例#1
0
        // GET: Articles
        public IActionResult Index(string MotCle, string CategorieArticle)
        {
            List <IndexArticleViewModel> ArticleVMList = new List <IndexArticleViewModel>();
            var garderieContext = _context.Articles.Include(a => a.Categorie).Include(a => a.EnfantInventaire).Include(a => a.Inventaire);

            /*var articles = from a in garderieContext
             *             select a;*/

            ServiceReference2.GarderieServiceClient serv = new ServiceReference2.GarderieServiceClient();
            var articles = serv.GetAllArticlesAsync().Result;


            IQueryable <string> categories = from ca in _context.CategoriesArticle
                                             join a in garderieContext on ca.CategorieId equals a.CategorieId
                                             orderby ca.CategorieId
                                             select ca.Nom;

            if (!String.IsNullOrEmpty(MotCle))
            {
                articles = articles.Where(s => s.nom.Contains(MotCle) || s.Description.Contains(MotCle)).ToArray();
            }

            if (!String.IsNullOrEmpty(CategorieArticle))
            {
                var categorie = _context.CategoriesArticle.FirstOrDefault(ca => ca.Nom == CategorieArticle).CategorieId;
                articles = articles.Where(x => x.Categorie.idCategorie == categorie).ToArray();
            }

            if (!articles.Any())
            {
                articles = serv.GetAllArticlesAsync().Result;
            }

            foreach (var article in articles)
            {
                IndexArticleViewModel viewModel = new IndexArticleViewModel
                {
                    ArticleId   = article.idArticle,
                    Nom         = article.nom,
                    Quantite    = (int)article.quantite,
                    Photo       = article.Photo,
                    Description = article.Description,
                    Categorie   = article.Categorie.nom,
                    Categories  = new SelectList(categories.Distinct().ToList())
                };
                ArticleVMList.Add(viewModel);
            }
            return(View(ArticleVMList));
        }
示例#2
0
        // GET: CategoriesArticle
        public async Task <IActionResult> Index()
        {
            ServiceReference2.GarderieServiceClient serv       = new ServiceReference2.GarderieServiceClient();
            ServiceReference2.Categorie[]           categories = serv.GetAllCategoriesAsync().Result;


            List <IndexCategoriesArticleViewModel> categoriesArticleVMList = new List <IndexCategoriesArticleViewModel>();

            //var categories = await _context.CategoriesArticle.ToListAsync();
            foreach (ServiceReference2.Categorie categorie in categories)
            {
                IndexCategoriesArticleViewModel viewModel = new IndexCategoriesArticleViewModel
                {
                    CategorieId = categorie.idCategorie,
                    Nom         = categorie.nom
                };
                categoriesArticleVMList.Add(viewModel);
            }

            return(View(categoriesArticleVMList));
        }