コード例 #1
0
 /// <summary>
 /// GET Requested method for update operations for a 
 /// specific grocery list. 
 /// </summary>
 /// <param name="id"></param>
 /// <returns></returns>
 public IActionResult Edit(int id)
 {
     var groceryList = _groceryLists.ReadGroceryList(id);
     var privUsers = groceryList.AssociativeEntities.Select(u => u.PrivUserEmail).ToList();
     //again get user id
     string userId = _manager.GetUserId(HttpContext.User);
     //get user
     var gList = _groceryItem.ReadAllGroceryItems();
     //Validate
     if (groceryList == null)
     {
         return RedirectToAction("Index", "Home");
     }
     GroceryListVM glVM = new GroceryListVM
     {
         OwnerId = groceryList.OwnerId,
         GroceryItems = gList,
         ListId = id,
         OwnerName = groceryList.OwnerName,
         AssociativeEntities = groceryList.AssociativeEntities,
         GroceryListName = groceryList.GroceryListName,
         UserId = userId,
         UserName = User.Identity.Name,
         PriviledgedUsers = privUsers,
     };
     return View(glVM);
 }
コード例 #2
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