public IActionResult Create() { PublishArticleFormModel model = new PublishArticleFormModel(); model.Categories = this.articles.GetPosibleCategories(); return(View(model)); }
public async Task <IActionResult> Create(PublishArticleFormModel model) { model.Content = this.htmlService.Sanitize(model.Content); var userId = this.userManager.GetUserId(User); await this.articleService.CreateAsync(model.Title, model.Content, userId); return(RedirectToAction(nameof(Index))); }
public async Task <IActionResult> Create(PublishArticleFormModel model) { model.Content = this._html.Sanitize(model.Content); var userId = _users.GetUserId(User); await this._articles.CreateAsync(model.Title, model.Content, userId); return(RedirectToAction(nameof(Index))); }
public async Task <IActionResult> Create(PublishArticleFormModel model) { model.Content = this.htmlService.DoSanitize(model.Content); var authorId = this.userManager.GetUserId(User); await this.articleService.CreateAsync(model.Title, model.Content, authorId); TempData.AddSuccessMessage($"Article {model.Title} successfully published."); return(RedirectToAction(nameof(Index))); }
public async Task <IActionResult> Create(PublishArticleFormModel model) { model.Content = this.htmlSanitizer.Sanitize(model.Content); var userId = userManager.GetUserId(User); await articles.CreateAsync( model.Title, model.Content, userId ); TempData.AddSuccessMessage($"Article {model.Title} was published successfully!"); return(RedirectToAction(nameof(Index))); }
public async Task <IActionResult> Create(PublishArticleFormModel model) { model.Content = this.html.Sanitize(model.Content); var userId = this.userManager.GetUserId(this.User); await this.articles.CreateAsync(model.Title, model.Content, userId); TempData.AddSuccessMessage($"Article {model.Title} was successfully published."); //return RedirectToAction(nameof(HomeController.Index), "Home", new { area = string.Empty }); return(RedirectToAction(nameof(Index))); }
public async Task <IActionResult> Create(PublishArticleFormModel model, IFormFile file) { if (!ModelState.IsValid) { return(View(model)); } model.Content = this.html.Sanitize(model.Content); var userId = this.userManager.GetUserId(User); await this.articles.CreateAsync(model.Title, model.Content, userId, file, model.CategoryId); return(RedirectToAction(nameof(Index))); }
public async Task <IActionResult> Create(PublishArticleFormModel model) { //if (!ModelState.IsValid) //{ // return View(model); //due to the Validate Filter this is not needed aslo Validate summary in VIEW is not needed //} model.Content = this.html.Sanitize(model.Content); var userId = this.userManager.GetUserId(User); await this.articles.CreateAsync(model.Title, model.Content, userId); return(RedirectToAction(nameof(Index))); }
[ValidateModelState] // validates model state filter public async Task <IActionResult> Create(PublishArticleFormModel model) { //if (!this.ModelState.IsValid) //{ // return this.View(model); //} var userId = this.userManager.GetUserId(this.User); model.Content = this.htmlService.Sanitize(model.Content); await this.blogService.CreateAsync(model.Title, model.Content, userId); return(this.RedirectToAction(nameof(Index))); }
public async Task <IActionResult> Create(PublishArticleFormModel articleModel) { if (!ModelState.IsValid) { this.TempData.AddErrorMessage( $@"Title must be between {ArticleTitleMinLength} and {ArticleTitleMaxLength} symbols. Content must be more then {ArticleContentMinLength} symbols."); return(RedirectToAction(nameof(Create))); } articleModel.Content = this.html.Sanitize(articleModel.Content); var userId = userManager.GetUserId(User); await this.articles.Create(articleModel.Title, articleModel.Content, userId); this.TempData.AddSuccessMessage($"{articleModel.Title} published successfuly."); return(RedirectToAction(nameof(Index), new { page = 1, searchTerm = string.Empty })); }