public EditArticleBindingModel GetEditModel(int id) { var article = this.Context .Articles .FirstOrDefault(a => a.Id == id); if (article == null) { return(null); } var categoryName = this.Context .Categories .FirstOrDefault(c => c.Id == article.CategoryId) .Name; var categories = this.Context .Categories .Select(c => c.Name) .ToList(); var model = new EditArticleBindingModel { Id = article.Id, Title = article.Title, Category = categoryName, Content = article.Content, Categories = categories, ImageUrl = article.ImageUrl }; return(model); }
public EditArticleBindingModel GetEditModel(int id) { Article article = this.Context .Articles .FirstOrDefault(a => a.Id == id); if (article == null) { return(null); } string categoryName = this.Context .Categories .FirstOrDefault(c => c.Id == article.CategoryId) .Name; List <string> categories = this.Context .Categories .Select(c => c.Name) .ToList(); EditArticleBindingModel model = new EditArticleBindingModel { Title = article.Title, Category = categoryName, Content = article.Content, Categories = categories }; return(model); }
public ActionResult Edit(int id) { EditArticleBindingModel model = this.articles.GetEditModel(id); if (model == null) { return(this.RedirectToAllArticles()); } return(this.View(model)); }
public async Task <IActionResult> EditArticle(EditArticleBindingModel model) { if (!this.ModelState.IsValid) { SetErrorMessage(CommonConstants.DangerMessage); return(this.EditArticle(model.Id)); } int generatedId = await this.articleService.EditArticleAsync(model); if (generatedId < 1) { return(RedirectToAction(RedirectConstants.IndexSuffix)); } return(Redirect(string.Format(RedirectConstants.AdministratorAreaArticleDetailsPage, generatedId))); }
public async Task <int> EditArticleAsync(EditArticleBindingModel model) { var article = this.DbContext .Articles .FirstOrDefault(x => x.Id == model.Id); if (article == null) { return(ErrorId); } model.Content = Html_String_Utility.EncodeThisPropertyForMe(model.Content); model.HighLightVideoURL = Html_String_Utility.EncodeThisPropertyForMe(model.HighLightVideoURL); model.PhotoURL = Html_String_Utility.EncodeThisPropertyForMe(model.PhotoURL); article.Content = model.Content; article.PhotoURL = model.PhotoURL; article.HighLightVideoURL = model.HighLightVideoURL; await this.DbContext.SaveChangesAsync(); return(article.Id); }
public ActionResult Edit(EditArticleBindingModel model) { this.articles.Edit(model.Id, model.Title, model.Content, model.Category); return(this.RedirectToAllArticles()); }
public ActionResult Edit(EditArticleBindingModel model) { this.articles.Edit(model.Id, model.Title, model.Content, model.Category, model.ImageUrl); return(this.RedirectToAction("All", "Articles", new { area = "" })); }
public async Task <IActionResult> DeleteArticle(EditArticleBindingModel model) { bool isDeleted = await this.articleService.DeleteArticleAsync(model.Id); return(RedirectToAction(RedirectConstants.IndexSuffix)); }