예제 #1
0
        /// <summary>
        /// Allows access to the Home Index page.
        /// </summary>
        /// <returns></returns>
        public IActionResult Index()
        {
            int listCount;

            if (this.User.Identity.IsAuthenticated)//Only allows access to registered users of the application.
            {
                var email  = this.User.Identity.Name;
                var userId = _userRepo.ReadAsyncByEmail(email).Result.Id;
                try
                {
                    listCount = _groceryLists.ReadUserGroceryLists(userId).Count();
                }
                catch (Exception)
                {
                    listCount = 0;
                }
                var listOfItems         = _itemRepo.ReadAllGroceryItems();
                var listsOfGroceryLists = _groceryLists.ReadUserGroceryLists(userId);
                var homeVM = new HomeVM
                {
                    GroceryListCount = listCount,
                    GroceryLists     = listsOfGroceryLists,
                    UserEmail        = email,
                    GroceryItems     = listOfItems
                };
                return(View(homeVM));
            }
            else
            {
                var homeVM = new HomeVM
                {
                    GroceryListCount = 0
                };
                return(View(homeVM));
            }
        }//end Index