Exemple #1
0
        public async Task <ActionResult> Index()
        {
            Dictionary <string, AppUser> userList = new Dictionary <string, AppUser>();

            foreach (AppUser user in _db.AppUsers)
            {
                userList.Add(user.UserName, user);
            }

            ICollection <Forum> model = _db.Forums.ToList();

            // List<AppUser> AppUsersList = new List<AppUser>;
            foreach (Post post in _db.Posts)
            {
                // var thisUser = AppUsersList.FirstOrDefault(entry => entry.AppUserId == post.CreatorId);
                await post.GeneratePreview();

                // userList.Add(post.CreatorId, thisUser.Username);
                _db.Entry(post).State = EntityState.Modified;
            }
            _db.SaveChanges();
            // ViewBag.UserDb = _db.AppUsers;
            ViewBag.userList         = userList;
            ViewBag.postByDate       = _db.Posts.ToList().OrderByDescending(e => e.CreationDate);
            ViewBag.postByPopularity = _db.Posts.Where(post => post.Title.Length > 0).ToList().OrderByDescending(e => e.Likes);
            // ViewBag.Usernames = userList;
            // (Implement on CSHTML) =
            // Scrolling list of most popular posts (stretch)
            // OR button at button to load next 10 most popular posts
            return(View(model));
        }
 public ActionResult Edit(AppUser appUser)
 {
     _db.Entry(appUser).State = EntityState.Modified;
     _db.SaveChanges();
     return(RedirectToAction("Index"));
 }
 public ActionResult Edit(Post post)
 {
     _db.Entry(post).State = EntityState.Modified;
     _db.SaveChanges();
     return(RedirectToAction("Index"));
 }
Exemple #4
0
 public ActionResult Create(Forum forum)
 {
     _db.Forums.Add(forum);
     _db.SaveChanges();
     return(RedirectToAction("Index"));
 }