コード例 #1
0
        public ActionResult ListByUser()
        {
            CheckAda();
            //if (GetLoggedInUser() == null)
            //{
            //    return ForceLogin();
            //}

            // TODO Return form for selecting a user from a drop-down list
            List <SelectListItem> users = new List <SelectListItem>();

            foreach (var u in db.Users)
            {
                SelectListItem item = new SelectListItem {
                    Text = u.UserName, Value = u.Id, Selected = true
                };
                users.Add(item);
            }

            ViewBag.message = "";
            ListByUserModel model = new ListByUserModel {
                Users = users
            };

            return(View(model));
            // End TODO
        }
コード例 #2
0
        public async Task <ActionResult> DoListByUser(ListByUserModel userView)
        {
            CheckAda();
            // TODO list all images uploaded by the user in userView (see List By Tag)
            ApplicationUser currentUser = await GetLoggedInUser();

            var user = db.Users.Find(userView.Id);

            if (user == null)
            {
                return(RedirectToAction("Error", "Home", new { ErrId = "ListByUser" }));
            }

            ViewBag.Username = currentUser.UserName;

            /*
             * Eager loading of related entities
             */
            var images = db.Entry(user).Collection(t => t.Images).Query().Include(im => im.Tag).ToList();

            return(View("ListAll", user.Images));
            // End TODO
        }