Exemplo n.º 1
0
        public IActionResult CreateMessage(HomepageWrapper FromForm)
        {
            int?LoggedId = HttpContext.Session.GetInt32("UserId");

            if (LoggedId == null)
            {
                return(RedirectToAction("LoginReg"));
            }
            if (ModelState.IsValid)
            {
                DbContext.Add(FromForm.Message);
                DbContext.SaveChanges();
                return(RedirectToAction("Homepage"));
            }
            else
            {
                return(Homepage());
            }
        }
Exemplo n.º 2
0
        public IActionResult Homepage()
        {
            int?LoggedId = HttpContext.Session.GetInt32("UserId");

            if (LoggedId == null)
            {
                return(RedirectToAction("LoginReg"));
            }
            ;

            HomepageWrapper HMod = new HomepageWrapper()
            {
                AllMessages = DbContext.Messages
                              .Include(m => m.Poster)
                              .Include(m => m.ListOfComments)
                              .ThenInclude(c => c.User)
                              .Include(c => c.ListOfComments)
                              .ToList(),
                LoggedUser = DbContext.Users
                             .FirstOrDefault(u => u.UserId == (int)LoggedId),
            };

            return(View("Homepage", HMod));
        }