public IActionResult Category(int id)
        {
            //all advertisements
            var advertisements = _advertisements.GetAll();
            //if subcategory - all its advertisements added
            var categoryAdvertisements = advertisements.FindAll(a => a.CategoryId == id);

            var categories = _categories.GetAll();

            foreach (Category cat in categories)
            {
                //finds subcategories to this category
                if (cat.CategoryId == id)
                {
                    //finds
                    List <Advertisement> subcategoryAds = advertisements.FindAll(a => a.CategoryId == cat.CategoryId);
                    categoryAdvertisements.AddRange(subcategoryAds);
                }
            }

            var model = new CatalogModel()
            {
                Advertisements = categoryAdvertisements,
                Category       = _categories.Get(id)
            };

            return(View(model));
        }
Esempio n. 2
0
        public IActionResult MyAdvertisements()
        {
            var advertisements   = _advertisements.GetAll();
            var myAdvertisements = advertisements.FindAll(a => a.Email == HttpContext.Session.GetUserEmail());

            return(View(myAdvertisements));
        }