Ejemplo n.º 1
0
 public async Task <IActionResult> OnGetBlockedNewsAsync(int newsId)
 {
     try
     {
         if (_context.AspNetNews.Any(@post => post.Id == newsId))
         {
             _context.AspNetNews.FirstOrDefault(@post => post.Id == newsId).Blocked = true;
             await _context.SaveChangesAsync();
         }
     }
     catch
     {
     }
     StatusMessage = "Новость заблокирована!";
     return(RedirectToPage("./Posts"));
 }
Ejemplo n.º 2
0
 public async Task <IActionResult> OnGetPublishNewsAsync(int newsId)
 {
     if (_context.AspNetNews.Any(newsItem => newsItem.Id == newsId))
     {
         _context.AspNetNews.FirstOrDefault(@post => post.Id == newsId).Blocked = false;
         await _context.SaveChangesAsync();
     }
     StatusMessage = "Новость разблокирована!";
     return(RedirectToPage("./Posts"));
 }
Ejemplo n.º 3
0
        public async Task <IActionResult> CreateComment(string message, string idNews, string idUser)
        {
            AspNetNewsComment _comment = new AspNetNewsComment()
            {
                Date   = DateTime.Now,
                NewsId = int.Parse(idNews),
                Text   = message,
                UserId = idUser
            };

            _context.AspNetNewsComments.Add(_comment);
            await _context.SaveChangesAsync();

            return(RedirectToAction("NewsDetails", "Home", new { url = _context.AspNetNews.Where(news => news.Id == int.Parse(idNews)).ToList()?[0].Url }));
        }