Exemple #1
0
        public async Task <IActionResult> Products([FromServices] IGetDisplayModel getDisplayModel, int categoryId = -1)
        {
            DisplayModel displayModel;

            if (categoryId == -1)
            {
                displayModel = await getDisplayModel.GetDisplayModelAsync(db);
            }
            else
            {
                Category category = await db.Categories.SingleOrDefaultAsync(p => p.Id == categoryId);

                displayModel = await getDisplayModel.GetDisplayModelAsync(db, category);
            }

            return(View(displayModel));
        }
Exemple #2
0
        public async Task <IActionResult> Categories([FromServices] IGetDisplayModel getDisplayModel)
        {
            List <DisplayModel> displayModels = new List <DisplayModel>();
            List <Category>     categories    = db.Categories.ToList();

            foreach (Category category in categories)
            {
                DisplayModel tempDisplayModel = await getDisplayModel.GetDisplayModelAsync(db, category);

                displayModels.Add(tempDisplayModel);
            }

            return(View(displayModels));
        }