Ejemplo n.º 1
0
        public IActionResult ThisUser(int id)
        {
            int?userId = HttpContext.Session.GetInt32("UserId");

            if (userId == null)
            {
                ModelState.AddModelError("myUser.Email", "Login to continue");
                return(View("Index"));
            }
            ViewBag.User = (int)userId;

            Allideas userLike = new Allideas()
            {
                thisUser = dbContext.Users.Where(u => u.UserId == id)
                           .Include(i => i.PostedIdeas)
                           .Include(i => i.LikedPost).Single(),

                allLikes = dbContext.Likes.Include(i => i.Idea)
                           .ThenInclude(idx => idx.Poster)
                           .Where(i => i.Idea.UserId == id).ToList()
            };


            return(View(userLike));
        }
Ejemplo n.º 2
0
        public IActionResult BrightIdeas()
        {
            int?userId = HttpContext.Session.GetInt32("UserId");

            if (userId == null)
            {
                ModelState.AddModelError("myUser.Email", "Login to continue");
                return(View("Index"));
            }
            int id = (int)userId;

            ViewBag.User = id;
            ViewBag.Name = HttpContext.Session.GetString("Username");

            Allideas ideas = new Allideas()
            {
                allIdeas = dbContext.Ideas.Include(idea => idea.Poster)
                           .Include(idea => idea.Likes)
                           .ThenInclude(Like => Like.User)
                           .OrderByDescending(d => d.Likes.Count)
                           .ToList()
            };

            return(View(ideas));
        }
Ejemplo n.º 3
0
        public IActionResult postIdeas(Idea newIdea)
        {
            int?userId = HttpContext.Session.GetInt32("UserId");

            ViewBag.User = (int)userId;

            string Name = HttpContext.Session.GetString("Username");

            ViewBag.Name = Name;

            if (ModelState.IsValid)
            {
                if (newIdea.UserId == userId)
                {
                    dbContext.Add(newIdea);
                    dbContext.SaveChanges();
                }
                return(RedirectToAction("BrightIdeas"));
            }
            else
            {
                Allideas ideas = new Allideas()
                {
                    allIdeas = dbContext.Ideas.Include(idea => idea.Poster)
                               .Include(idea => idea.Likes)
                               .ThenInclude(Like => Like.User)
                               .OrderByDescending(d => d.Likes.Count)
                               .ToList()
                };
                return(View("BrightIdeas", ideas));
            }
        }