Advertisement
ivaylokenov

Untitled

Nov 18th, 2019
136
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.90 KB | None | 0 0
  1. public class ArticlesController : Controller
  2. {
  3.         private readonly IArticleService articleService;
  4.  
  5.         public ArticlesController(IArticleService articleService)
  6.             => this.articleService = articleService;
  7.  
  8.         [HttpGet]
  9.         [Authorize]
  10.         public IActionResult Create() => this.View();
  11.  
  12.         [HttpPost]
  13.         [Authorize]
  14.         public async Task<IActionResult> Create(ArticleFormModel article)
  15.         {
  16.             if (this.ModelState.IsValid)
  17.             {
  18.                 await this.articleService.Add(article.Title, article.Content, this.User.GetId());
  19.  
  20.                 this.TempData.Add(ControllerConstants.SuccessMessage, "Article created successfully it is waiting for approval!");
  21.  
  22.                 return this.RedirectToAction(nameof(UsersController.Mine), ControllerConstants.Users);
  23.             }
  24.  
  25.             return this.View(article);
  26.         }
  27. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement