public async Task <IActionResult> Edit(ArticleEditInputModel inputModel) { if (!this.ModelState.IsValid) { this.ViewData["Error"] = ArticleEditError; return(this.View(inputModel)); } var user = await this.userManager.GetUserAsync(this.User); var serviceModel = AutoMapperConfig.MapperInstance.Map <ArticleServiceModel>(inputModel); serviceModel.UserId = user.Id; if (inputModel.Image != null) { var imageUrl = await this.cloudinaryService.UploadPicture(inputModel.Image, inputModel.Title); serviceModel.ImageUrl = imageUrl; } await this.articleService.Edit(serviceModel); return(this.RedirectToAction("Single", "Article", new { area = string.Empty, id = inputModel.Id })); }
public async Task <Article> EditAsync(ArticleEditInputModel articleEditInputModel, string editorId) { var article = await this.GetAsync(articleEditInputModel.Id); this.categoryService.ThrowIfAnyNotExist(articleEditInputModel.CategoriesIds); this.ThrowIfAnyNotExist(articleEditInputModel.ConnectedArticlesIds); UpdateCategories(article.Categories, articleEditInputModel.CategoriesIds?.ToList()); UpdateConnectedArticles(article.ConnectedTo, articleEditInputModel.ConnectedArticlesIds?.ToList()); article.Title = articleEditInputModel.Title; article.Lead = articleEditInputModel.Lead; article.Content = articleEditInputModel.Content; article.Author = articleEditInputModel.Author; article.ImageId = articleEditInputModel.Image?.Id; article.IsTop = articleEditInputModel.IsTop; article.IsImportant = articleEditInputModel.IsImportant; article.Edits.Add(new ArticleEdit { EditorId = editorId, EditDateTime = DateTime.UtcNow }); await this.db.SaveChangesAsync(); return(article); }
public async Task <IActionResult> Edit(ArticleEditInputModel articleUpdateInputModel) { if (!ModelState.IsValid) { return(this.View(articleUpdateInputModel)); } var userId = this.userManager.GetUserId(this.User); var article = await this.articleService.EditAsync(articleUpdateInputModel, userId); return(RedirectToAction("Details", "Articles", new { article.Id })); }
public async Task <IActionResult> Edit(string id) { ArticleEditInputModel articleEditInputModel = (await this.articlesService.GetArticleById(id)).To <ArticleEditInputModel>(); if (articleEditInputModel == null) { return(this.Redirect("/")); throw new ArgumentNullException(nameof(articleEditInputModel)); } return(this.View(articleEditInputModel)); }
public IActionResult Edit(ArticleEditInputModel model) { if (!this.articles.Exist(model.Id)) { return(this.NotFound("There is no article with given Id.")); } if (!this.ModelState.IsValid) { return(this.View()); } var articleEditServiceModel = this.mapper.Map <ArticleEditServiceModel>(model); this.articles.Edit(articleEditServiceModel); return(this.RedirectToAction("Details", "Articles", new { Id = model.Id })); }
public async Task <IActionResult> Edit(string id, ArticleEditInputModel articleEditInputModel) { if (id == null) { return(NotFound()); } if (!this.ModelState.IsValid) { return(this.View(articleEditInputModel)); } ArticleServiceModel articleServiceModel = new ArticleServiceModel() { Title = articleEditInputModel.Title, Content = articleEditInputModel.Content }; await this.articlesService.Edit(id, articleServiceModel); return(this.Redirect("/Articles/All")); }