public async Task <IActionResult> Edit(int id, BlogPostEditInputModel inputModel) { if (id != inputModel.Id) { return(this.NotFound()); } if (this.ModelState.IsValid) { try { await this.blogPostService.UpdateAsync(inputModel.Id, inputModel.Title, inputModel.Content, inputModel.PreviewContent); } catch (DbUpdateConcurrencyException) { if (this.blogPostService.CheckBlogPostExist(id)) { return(this.NotFound()); } else { throw; } } } return(this.RedirectToAction(nameof(this.Index))); }
public async Task <ActionResult <BlogPostExportModel> > Put(string id, [FromForm] BlogPostEditInputModel input) { if (id != input.Id) { return(this.BadRequest()); } var model = await this.blogPostService.GetByIdAsync <BlogPostExportModel>(id); if (model == null) { return(this.NotFound()); } // var userId = this.User.FindFirst(ClaimTypes.NameIdentifier).Value; var user = await this.userManager.GetUserAsync(this.User); await this.blogPostService.EditAsync(input, user.Id, this.imageFilesDirectory); return(this.NoContent()); }
public IActionResult Edit(BlogPostEditInputModel model) { if (!this.ModelState.IsValid) { var products = this.productService.GetAllProducts(); var selectListItemProducts = products.Select(p => new SelectListItem { Value = p.Id.ToString(), Text = p.Name }) .ToList(); model.Products = selectListItemProducts; return(this.View(model)); } this.blogPostsService.EditPost(model.Id, model.Title, model.Content, model.ProductId); return(this.RedirectToAction(nameof(All))); }
public async Task <string> EditAsync(BlogPostEditInputModel input, string userId, string imageFilesDirectory) { var entity = await this.blogPostsRepository .All() .FirstOrDefaultAsync(x => x.Id == input.Id); // var userEntity = this.usersRepository.AllAsNoTracking() // .FirstOrDefault(x => x.UserName == articleInputModel.UserId); // take the user and record its id in the article, product, conformity, etc.\\ entity.Title = input.Title.Trim(); entity.Author = input.Author.Trim(); entity.Details = input.Details.Trim(); entity.PublishDate = input.PublishDate; entity.ExternalPostUrl = input.ExternalPostUrl; entity.UserId = userId; entity.Categories = null; entity.Likes = input.Likes; // Stream fileStream = await this.UploadFileAsync(input, imageFilesDirectory, entity); await this.blogPostsRepository.SaveChangesAsync(); // await this.AddCategoriesAsync(entity, input.Categories); return(entity.Id); }
public IActionResult Edit(int id) { var postExists = this.blogPostsService.PostExistsById(id); if (!postExists) { var errorViewModel = new ErrorViewModel { RequestId = ErrorMessages.BlogPostErrorMessage }; return(this.View(GlobalConstants.ErrorViewName, errorViewModel)); } var products = this.productService.GetAllProducts(); var selectListItemProducts = products.Select(p => new SelectListItem { Value = p.Id.ToString(), Text = p.Name }) .ToList(); var post = this.blogPostsService.GetPostById <BlogPost>(id); var blogPostEditInputModel = new BlogPostEditInputModel { Id = post.Id, Title = post.Title, Content = post.Content, ProductId = post.ProductId, Products = selectListItemProducts }; return(this.View(blogPostEditInputModel)); }
public ActionResult Edit(BlogPostEditInputModel postInputModel) { if (this.ModelState.IsValid) { var post = this.Data.Posts.Find(postInputModel.Id); post.Id = postInputModel.Id; post.Title = postInputModel.Title; post.Content = postInputModel.Content; post.AuthorId = postInputModel.AuthorId; post.CreatedOn = postInputModel.CreatedOn; this.Data.Posts.Update(post); this.Data.SaveChanges(); return this.RedirectToAction("Index"); } return this.View(postInputModel); }
public ActionResult Edit(int? id) { if (id == null) { return new HttpStatusCodeResult(HttpStatusCode.BadRequest); } var post = this.Data.Posts.Find(id); if (post == null) { return this.HttpNotFound(); } var model = new BlogPostEditInputModel { Id = post.Id, Title = post.Title, Content = post.Content, CreatedOn = post.CreatedOn, AuthorId = post.AuthorId }; return this.View(model); }