Ejemplo n.º 1
0
        public async Task <IActionResult> AddComment(NewsCommentsAndUsersViewModel model)
        {
            //if(model.Comment == null)
            //{
            //    return NotFound();
            //}

            if (ModelState.IsValid)
            {
                _db.Comment.Add(model.Comment);
                await _db.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            return(View(model.Comment));

            //_db.News.Add(model);
            //await _db.SaveChangesAsync();
            //return RedirectToAction(nameof(Index));
        }
Ejemplo n.º 2
0
        public async Task <IActionResult> Details(int?id)
        {
            if (id == null)
            {
                return(NotFound());
            }

            //var newsFromDb = await _db.News.Include(c => c.Comments)
            //                       .FirstOrDefaultAsync(n => n.Id == id);

            ViewBag.loggedInUserId = User.FindFirstValue(ClaimTypes.NameIdentifier);

            NewsCommentsAndUsersViewModel model = new NewsCommentsAndUsersViewModel
            {
                News     = await _db.News.FindAsync(id),
                Comments = await _db.Comment.Include(u => u.ApplicationUser)
                           .Where(c => c.NewsId == id).ToListAsync()
            };

            return(View(model));
        }