public PostEditPage(MPost post) { InitializeComponent(); BindingContext = PostEditVM = new PostEditViewModel { Post = post }; }
public async Task <IActionResult> UpdateAsync(Guid id, [FromForm] PostEditViewModel model) { ViewData["Component"] = "post"; if (ModelState.IsValid) { try { var postRequest = commonFactory.Mapper.Map <PostEditViewModel, UpdatePostRequest>(model); var response = repositoryFactory.Post.Update(postRequest); if (response.IsSuccess) { return(Redirect("/post/manage")); } ViewData["error"] = response.Message; } catch (Exception ex) { throw; } } ViewData["update"] = true; model.CategoryList = await repositoryFactory.Category.GetCheckboxListAsync(model.CategoryIds); return(View("Update", model)); }
public async Task <IActionResult> Edit(int?id) { if (id == null) { return(NotFound()); } var post = await _postService.GetPostById((int)id); if (post == null) { return(NotFound()); } var blog = await _blogService.GetBlogById(post.Blog.BlogId); if ((await _authorizationService.AuthorizeAsync(User, blog, "OwnerPolicy")).Succeeded) { var viewModel = new PostEditViewModel((int)id, post.Title, post.Text, post.Tags, post.ImagePath, post.Blog); return(View(viewModel)); } return(Forbid()); }
public ActionResult Edit(PostEditViewModel model, IFormFile[] fileobj) { ViewBag.Categories = _ctgRepo.ListAll(); try { if (!ModelState.IsValid) { return(View(model)); } //Find id where Selected PostId equals to Id. var post = _repo.FindById(model.Id); //Extension method for Edit Post. extension.PostEdit(post, model, fileobj, _hosting); var isSuccess = _repo.Update(post); if (!isSuccess) { ModelState.AddModelError("", "Something went wrong..."); return(View(model)); } return(RedirectToAction(nameof(Index))); } catch { ModelState.AddModelError("", "Something went wrong... "); return(RedirectToAction(nameof(Index))); } }
public async Task <IActionResult> Edit(int id, PostEditViewModel postEditViewModel) { if (id != postEditViewModel.Id) { return(NotFound()); } if (ModelState.IsValid) { try { var post = _map.Map <Post>(postEditViewModel); await _uow.PostRepository.EditAsync(post); await _uow.Save(); } catch (DbUpdateConcurrencyException) { if (!PostExists(postEditViewModel.Id)) { return(NotFound()); } else { throw; } } return(RedirectToAction(nameof(Index))); } return(View(postEditViewModel)); }
public async Task <IActionResult> Update(int id, [FromBody] PostEditViewModel postEditModel) { if (postEditModel == null) { return(BadRequest()); } if (!ModelState.IsValid) { return(BadRequest()); } var post = await _postService.GetAsync(id); if (post == null) { return(NotFound()); } if (!HasCurrentUserEditRights(post)) { return(StatusCode(403)); } var editPostDto = MapToEditPostDTO(postEditModel); var updatedPost = await _postService.Update(id, editPostDto); var postViewModel = PostMapper.ConvertToPostViewModel(updatedPost); return(Ok(postViewModel)); }
public IActionResult Edit(PostEditViewModel model) { if (ModelState.IsValid) { BlogModel post = _postRepository.GetPostById(model.Id); post.author = model.author; post.title = model.title; post.preview = model.preview; post.fullPost = model.fullPost; if (model.img != null) { if (model.ExistImgPath != null) { string filePath = Path.Combine(hostingEnvironment.WebRootPath, "images", model.ExistImgPath); System.IO.File.Delete(filePath); } post.img = UploadedFile(model); } _postRepository.UpdatePost(post); return(RedirectToAction("Index")); } return(View()); }
public ActionResult Edit(int id, PostEditViewModel postData) { if (!ModelState.IsValid) { return(BadRequest()); } var post = db.Posts.Find(id); var userId = User.FindFirst(ClaimTypes.NameIdentifier).Value; if (post == null) { return(NotFound()); } if (post.AuthorId != userId && !User.IsInRole("Admin")) { return(BadRequest()); } post.Title = postData.Title; post.Content = postData.Content; db.SaveChanges(); return(Ok()); }
private async Task <ActionResult> AddOrEdit(PostEditViewModel model) { try { var record = await _postService.Get(model.Id); var isAdd = record == null; if (record == null) { record = PostRecord.Create(await _userService.GetUserById(_authenticationService.GetAuthenticatedUser().Identity)); } model.UpdateRecord(record, _categoryService); if (isAdd) { await _postService.Add(record); } return(this.Success()); } catch (ValidationException validationException) { return(this.Error(validationException.Message)); } }
public async Task <IActionResult> Edit(int id, PostEditViewModel model) { model.CheckArgumentIsNull(); if (!ModelState.IsValid) { model = await _postViewModelProvider .BuildEditViewModelAsync(model); model.ModelMessage = AppTextDisplay.ModelStateError; model.HasError = true; return(View(model)); } var data = model.Adapt <PostEditDto>(); await _postService.UpdateAsync(model : data); model = await _postViewModelProvider .BuildEditViewModelAsync(model); model.ShowNotification = true; model.ModelMessage = string.Format( AppTextDisplay.ModelUpdatedMsg, AppTextDisplay.PostEntityDisplay ); return(View(model)); }
public async Task <IActionResult> Edit(PostEditViewModel input) { if (!this.User.IsInRole(GlobalConstants.AdministratorRoleName) && !this.User.IsInRole(GlobalConstants.ModeratorRoleName)) { var userId = this.User.FindFirstValue(ClaimTypes.NameIdentifier); if (userId != input.UserId) { return(this.BadRequest()); } } if (!this.ModelState.IsValid) { return(this.View(input)); } var postId = await this.postsService.EditAsync(input.Id, input.Name, input.Content); if (postId == null) { return(this.NotFound()); } this.TempData["InfoMessage"] = "Post edited successfully!"; return(this.RedirectToAction(nameof(this.ByName), new { name = input.Url })); }
public async Task <IActionResult> Edit(PostEditViewModel postEditViewModel) { if (ModelState.IsValid) { var slug = BlogUtils.CreateSlug(postEditViewModel.Slug); if (string.IsNullOrEmpty(slug)) { ModelState.AddModelError(ModelStateErrorMsgKey, MsgInvalidSlug); return(View(postEditViewModel)); } var slugIsUnique = await _postRepo.CheckIfSlugIsUnique(slug, postEditViewModel.PostId); if (!slugIsUnique) { ModelState.AddModelError(ModelStateErrorMsgKey, MsgDuplicateSlug); return(View(postEditViewModel)); } postEditViewModel.Slug = slug; var updateResult = await _postRepo.UpdatePost(postEditViewModel); if (updateResult) { return(Redirect(Url.Action("AnyPost", "Blog", new { slug }))); } } ModelState.AddModelError(ModelStateErrorMsgKey, MsgSomethingIsWrong); return(View(postEditViewModel)); }
public async Task <IActionResult> PostEdit([FromRoute] string slug, [FromForm] PostEditViewModel postViewModel) { if (!string.IsNullOrEmpty(slug)) { var existingPost = await _postService.GetPost(slug); if (existingPost == null) { return(NotFound()); } } var post = postViewModel.AsModel(); post.Status = Services.PostStatus.Draft; var result = await _postService.SavePost(post); if (!result.Success) { // TODO: Show result.Error; } return(RedirectToAction(nameof(Index))); }
public async Task <IActionResult> Edit(PostEditViewModel post) { if (ModelState.IsValid) { Post post1 = _context.Posts.Find(post.Id); post1.Title = post.Title; post1.ContentPost = post.ContentPost; post1.ModifiedBy = HttpContext.Session.GetString("UserName"); post1.ModifiedDate = DateTime.Now; post1.Status = post.Status; post1.CategoryPost = post.CategoryPost; post1.CategoryId = post.CategoryId; if (post.HinhAnh != null) { if (post.ExistingPhotoPath != null) { string filePath = Path.Combine(hostingEnvironment.WebRootPath, "uploads_admin", post.ExistingPhotoPath); System.IO.File.Delete(filePath); } post1.HinhAnh = @"/uploads_admin/" + ProcessUploadedFile(post); } post.MetaTitle = XuLyChuoi.GetMetaTitle(post.Title); _context.Update(post1); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); // return RedirectToAction(nameof(Index)); } ViewData["CategoryId"] = new SelectList(_context.CategoryPosts, "Id", "CategoryName", post.CategoryId); return(View(post)); }
public async Task <IActionResult> Edit(string postId) { ViewBag.SubsectionPages = _subsectionPages; ViewBag.ActiveSubpage = "Edit"; Art art = await _db.Arts.Include(a => a.Author) .Include(a => a.Tags).ThenInclude(t => t.Tag) .FirstOrDefaultAsync(a => a.Id.ToString().Equals(postId)); if (art == null) { Redirect("/Posts/List"); } PostEditViewModel puvm = new PostEditViewModel(); puvm.SecretId = postId; puvm.PreviewUrl = art.FileUrl; puvm.Author = art.Author.ArtistName; puvm.Name = art.Name; puvm.Rating = art.Rating; puvm.Source = art.Source; StringBuilder sb = new StringBuilder(); foreach (var tag in art.Tags.Select(t => t.Tag.TagString)) { sb.Append(tag.Replace(" ", "_") + " "); } puvm.TagString = sb.ToString(); return(View(puvm)); }
public async Task <IActionResult> Edit(long?id) { if (id == null) { return(NotFound()); } var post = await _context.Posts.FindAsync(id); PostEditViewModel postEditViewModel = new PostEditViewModel { Id = post.Id, Title = post.Title, ContentPost = post.ContentPost, MetaDescription = post.MetaDescription, CategoryPost = post.CategoryPost, ExistingPhotoPath = post.HinhAnh, Status = post.Status, CategoryId = post.CategoryId }; if (post == null) { return(NotFound()); } ViewData["CategoryId"] = new SelectList(_context.CategoryPosts, "Id", "CategoryName", post.CategoryId); return(View(postEditViewModel)); }
// GET: Posts/Edit/5 public async Task <IActionResult> Edit(int?id) { if (id == null) { return(NotFound()); } var post = _context.Posts .Where(p => p.Id == id) .Include(p => p.MainImage) .Include(p => p.PostCategorys) .ToList() .FirstOrDefault(); if (post == null) { return(NotFound()); } PostEditViewModel pevm = new PostEditViewModel(); pevm.thePost = post; pevm.SelectedCats = post.PostCategorys.Select(pc => pc.CategoryId).ToList <int>(); pevm.PostStatusOptions = Enum.GetValues(typeof(PostStatus)); pevm.Cats = await _context.Categorys.ToListAsync(); pevm.Posts = await _context.Posts.ToListAsync(); pevm.Posts.Insert(0, new Post { Id = 0, Title = "none" }); return(View(pevm)); }
public ActionResult New(PostEditViewModel model) { if (ModelState.IsValid) { Post post = new Post { Title = model.Title, Content = model.Content, CategoryId = model.CategoryId, AuthorId = User.Identity.GetUserId(), CreationTime = DateTime.Now, Slug = model.Slug, Publish = false }; db.Posts.Add(post); db.SaveChanges(); return(RedirectToAction("Index")); } ViewBag.CategoryId = new SelectList(db.Categories.ToList(), "Id", "CategoryName"); return(View("Edit", new PostEditViewModel())); }
public IActionResult Create(PostEditViewModel model, [FromServices] LinkGenerator linkGenerator, [FromServices] IPingbackSender pingbackSender) { try { if (ModelState.IsValid) { // get tags string[] tagList = string.IsNullOrWhiteSpace(model.Tags) ? new string[] { } : model.Tags.Split(',').ToArray(); var request = new CreatePostRequest { Title = model.Title.Trim(), Slug = model.Slug.Trim(), HtmlContent = model.HtmlContent, EnableComment = model.EnableComment, ExposedToSiteMap = model.ExposedToSiteMap, IsFeedIncluded = model.FeedIncluded, ContentLanguageCode = model.ContentLanguageCode, IsPublished = model.IsPublished, Tags = tagList, CategoryIds = model.SelectedCategoryIds, RequestIp = HttpContext.Connection.RemoteIpAddress.ToString() }; var response = _postService.CreateNewPost(request); if (response.IsSuccess) { if (!model.IsPublished) { return(RedirectToAction(nameof(Manage))); } var pubDate = response.Item.PostPublish.PubDateUtc.GetValueOrDefault(); var link = GetPostUrl(linkGenerator, pubDate, response.Item.Slug); if (AppSettings.EnablePingBackSend) { Task.Run(async() => { await pingbackSender.TrySendPingAsync(link, response.Item.PostContent); }); } return(RedirectToAction(nameof(Manage))); } ModelState.AddModelError("", response.Message); return(View("CreateOrEdit", model)); } return(View("CreateOrEdit", model)); } catch (Exception ex) { Logger.LogError(ex, "Error Creating New Post."); ModelState.AddModelError("", ex.Message); return(View("CreateOrEdit", model)); } }
public IActionResult Edit(PostEditViewModel model, IFormFile file) { var post = context.Posts.FirstOrDefault(i => i.Id == model.Id); if (ModelState.IsValid) { if (file != null) { if (System.IO.File.Exists($"wwwroot\\img\\{model.ExistImage}")) { System.IO.File.Delete($"wwwroot\\img\\{model.ExistImage}"); } var path = Path.Combine(Directory.GetCurrentDirectory(), "wwwroot\\img", file.FileName); using (var fs = new FileStream(path, FileMode.Create)) { file.CopyTo(fs); model.ImageUrl = file.FileName; } } post.PostTitle = model.PostTitle; post.PostName = model.PostName; post.PostDescription = model.Description; post.ImageUrl = model.ImageUrl; post.PostDate = DateTime.Now; context.SaveChanges(); return(RedirectToAction("Index", "Home")); } return(View(model)); //Sabah Dersde Yazacam!!! }
public async Task <IActionResult> Edit(Guid id, [FromServices] IHtmlCodec htmlCodec) { var postResponse = _postService.GetPost(id); if (!postResponse.IsSuccess) { return(ServerError()); } var post = postResponse.Item; if (null != post) { var editViewModel = new PostEditViewModel { PostId = post.Id, IsPublished = post.IsPublished, HtmlContent = htmlCodec.HtmlDecode(post.EncodedHtmlContent), Slug = post.Slug, Title = post.Title, EnableComment = post.CommentEnabled, ExposedToSiteMap = post.ExposedToSiteMap, FeedIncluded = post.FeedIncluded, ContentLanguageCode = post.ContentLanguageCode }; ViewBag.PubDateStr = post.PubDateUtc == null ? null : $"{post.PubDateUtc.GetValueOrDefault():yyyy/M/d}"; var tagStr = post.Tags .Select(p => p.TagName) .Aggregate(string.Empty, (current, item) => current + (item + ",")); tagStr = tagStr.TrimEnd(','); editViewModel.Tags = tagStr; var catResponse = await _categoryService.GetAllCategoriesAsync(); if (!catResponse.IsSuccess) { return(ServerError("Unsuccessful response from _categoryService.GetAllCategoriesAsync().")); } var catList = catResponse.Item; if (null != catList && catList.Count > 0) { var cbCatList = catList.Select(p => new CheckBoxViewModel( p.DisplayName, p.Id.ToString(), post.Categories.Any(q => q.Id == p.Id))).ToList(); editViewModel.CategoryList = cbCatList; } return(View("CreateOrEdit", editViewModel)); } return(NotFound()); }
public IActionResult Edit(PostEditViewModel model) { var postToEdit = _mapper.Map <PostEditDTO>(model); _postService.EditPost(postToEdit); return(RedirectToAction("Details", "Posts", new { id = model.Id, Area = "" }));; }
public IActionResult PostEdit(PostEditViewModel model) { forumPost.PostID = model.PostID; forumPost.PostMessage = model.PostMessage; forumPost.EditPost(); return(RedirectToAction("Threadpage", "Forum", new { model.ThreadID })); }
public async Task Edit(PostEditViewModel viewModel) { var post = await _post .Include(q => q.Creator) .FirstAsync(a => a.Id == viewModel.Id); _mappingEngine.Map(viewModel, post); await _unitOfWork.SaveChangesAsync(); }
public static PostEditDto ToDto(this PostEditViewModel source, string fileName) { return(new PostEditDto { Description = source.Description, Id = source.Id, PrimaryPicture = fileName, Title = source.Title, }); }
public async Task <IActionResult> Edit(PostEditViewModel model) { if (ModelState.IsValid) { var user = await _userManager.GetUserAsync(User); var post = new Post { Id = model.Id, Author = user.Name + " " + user.Surname, Title = model.Title, Description = model.Description, Slug = _blogRepository.CreateSlug(model.Title), CategoryId = model.CategoryId, UserId = user.Id }; if (model.NewImage == null) { post.ImageUrl = model.CurrentImage; } else { if (!String.IsNullOrWhiteSpace(model.CurrentImage)) { _fileManager.RemoveImage(model.CurrentImage); } post.ImageUrl = _fileManager.SaveImage(model.NewImage); } _blogRepository.UpdatePost(post); if (await _blogRepository.SaveChangesAsync()) { return(RedirectToAction(nameof(Index))); } _clientNotification.AddToastNotification("Could not Update post", NotificationHelper.NotificationType.error, new ToastNotificationOption { NewestOnTop = true, CloseButton = true, PositionClass = "toast-top-full-width", PreventDuplicates = true }); return(View(model)); } _clientNotification.AddToastNotification("You Have Errors", NotificationHelper.NotificationType.error, new ToastNotificationOption { NewestOnTop = true, CloseButton = true, PositionClass = "toast-top-full-width", PreventDuplicates = true }); return(View(model)); }
public bool Update(PostEditViewModel postVM) { var post = dbContext.Posts.Where(p => p.Id == postVM.Id).Single(); post.Title = postVM.Title; post.Content = postVM.Content; dbContext.SaveChanges(); return(true); }
public async Task <IActionResult> Review([FromRoute] string slug) { var post = await _postService.GetPost(slug); if (post == null) { return(NotFound()); } return(View(PostEditViewModel.FromModel(post))); }
public ActionResult EditPost(int postId) { var item = postService.GetPostById(postId); PostEditViewModel vm = new PostEditViewModel() { Post = item, Categories = categoryService.GetAllCategories() }; return(View(vm)); }
public async Task <IActionResult> Delete(PostEditViewModel input) { if (!this.ModelState.IsValid) { return(this.View(input)); } await this.postsService.Delete(input); return(this.Redirect($"/Forum/Forum")); }
private async Task<ActionResult> AddOrEdit(PostEditViewModel model) { try { var record = await _postService.Get(model.Id); var isAdd = record == null; if (record == null) record = PostRecord.Create(await _userService.GetUserById(_authenticationService.GetAuthenticatedUser().Identity)); model.UpdateRecord(record, _categoryService); if (isAdd) await _postService.Add(record); return this.Success(); } catch (ValidationException validationException) { return this.Error(validationException.Message); } }
public Task<ActionResult> Edit(PostEditViewModel model) { return AddOrEdit(model); }