Advertisement
Guest User

Untitled

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