// GET: Control/Posteds/Edit/5 public async Task <IActionResult> Edit(int?id) { if (id == null) { return(NotFound()); } var posted = await _context.Posteds.FindAsync(id); if (posted == null) { return(NotFound()); } EditPostModel model = new EditPostModel(); model.ApplicationUserId = posted.ApplicationUserId; model.CreatedAt = posted.CreatedAt; model.Id = posted.Id; model.ExistPhotoPath = posted.ImagePath; model.Point = posted.Point; model.SeasonId = posted.SeasonId; ViewData["ApplicationUserId"] = new SelectList(_context.Users, "Id", "Id", model.ApplicationUserId); ViewData["SeasonId"] = new SelectList(_context.Seasons, "Id", "Id", model.SeasonId); return(View(model)); }
public async Task <IActionResult> EditBlog(EditPostModel model) { var newUrl = UploadedFile(model); if (ModelState.IsValid) { try { await model.EditBlogAsync(newUrl); var msg = "Congrats! Editted Blog Successfully"; _logger.LogInformation("Blog Editted Successfully"); model.Response = new ResponseModel(msg, ResponseType.Success); return(RedirectToAction("Index")); } catch (Exception ex) { var msg = "Failed to Edit Blog"; model.Response = new ResponseModel(msg, ResponseType.Failure); _logger.LogError(ex.Message); } } model.Categories = model.GetAllCategoryForSelectAsync(); return(View(model)); }
public EditPostModel GetPostForEdit(int id) { EditPostModel postModel = _posts.Where(post => post.Id == id) .Select( post => new EditPostModel { //Book = post.Book, //BookImage = post.Book.Image, Labels = post.Labels, PostBody = post.Body, PostCommentStatus = post.CommentStatus, PostDescription = post.Description, PostId = post.Id, PostKeyword = post.Keyword, PostTitle = post.Title, PostPicture = post.Picture, //DownloadLinks = post.DownloadLinks, PostStatus = post.Status }) .FirstOrDefault(); return(postModel); }
public async Task When_author_is_current_user_should_update_post() { var userId = 1; var postId = 1; var editPostModel = new EditPostModel { Id = postId, Title = "title", Content = "content" }; var post = new Post { UserId = userId, Title = "title", Content = "content" }; var users = new List <User>() { new User() { Id = userId, Email = "email" } }; _mockUserRepository.Setup(repo => repo.Get(It.IsAny <Func <User, bool> >())) .Returns((Func <User, bool> predicate) => users.Where(predicate).ToList()); _mockPostRepository.Setup(repo => repo.FindById(postId)).ReturnsAsync(post); await _postService.Edit(editPostModel, "email"); _mockPostRepository.Verify(repo => repo.Update(post), Times.Exactly(1)); }
public async Task EditPostContent(EditPostModel model) { var post = await this.GetByIdAsync(model.PostId); post.Content = new HtmlSanitizer().Sanitize(model.Content); this.postsRepository.Update(post); await this.postsRepository.SaveChangesAsync(); }
public async Task <IActionResult> EditBlog(int id) { var model = new EditPostModel(); await model.LoadByIdAsync(id); model.Categories = model.GetAllCategoryForSelectAsync(); return(View(model)); }
public string EditPostDescription(EditPostModel editPostModel) { var postForEdit = this.context.Posts.SingleOrDefault(x => x.Id == editPostModel.Id); postForEdit.Description = editPostModel.Description; context.SaveChanges(); return($"Post Description was successfully edited to {postForEdit.Description}"); }
public async Task <bool> EditGroupPost(EditPostModel post) { var client = new HttpClient(); var json = JsonConvert.SerializeObject(post); HttpContent content = new StringContent(json, Encoding.UTF8, "application/json"); var response = await client.PostAsync(ConnectionString + "api/GroupPost/EditGroupPost", content); return(response.IsSuccessStatusCode); }
public ActionResult EditPostIf(EditPostModel postModel) { interfaceOperation = true; var post = postsApi.GetPostById(postModel.Id); postModel.Text = post.Text; postModel.NewText = post.Text; return(View(postModel)); }
public string EditPostPrice(EditPostModel editPostModel) { var postForEdit = this.context.Posts.Find(editPostModel.Id); postForEdit.Price = editPostModel.Price; context.SaveChanges(); return("Post Price was successfully edited"); }
public static BllPost ToPost(this EditPostModel post) { return(new BllPost { BlogId = post.BlogId, Content = post.Content, Id = post.Id, Title = post.Title }); }
public async Task <PostDetailsModel> Put(int id, [FromBody] EditPostModel editModel) { if (ModelState.IsValid) { editModel.PostId = id; return(await _postsService.UpdatePost(editModel)); } throw new HttpResponseException(HttpStatusCode.BadRequest); }
/// <summary> /// Creates a new post /// </summary> /// <param name="editPostModel">New post</param> /// <param name="userEmail">Author's email</param> public async Task Create(EditPostModel editPostModel, string userEmail) { var post = _editPostMapper.ToDalModel(editPostModel); var user = _userRepository.GetByEmail(userEmail); post.UserId = user.Id; post.CreateDate = DateTime.Now; post.UpdateDate = post.CreateDate; await _postRepository.Create(post); }
public async Task <ActionResult> EditPost([Bind(Include = "Id, NewPostTitle, NewPostContent, ForumId, UserId, DateCreated")] EditPostModel model) { if (ModelState.IsValid) { var post = BuildEditPostModel(model); await _postRepositories.UpdatePostContent(post); return(RedirectToAction("Index", "Post", new { id = post.Id })); } return(View(model)); }
public async Task <IActionResult> Edit(EditPostModel model) { if (!await this.postService.DoesItExist(model.PostId)) { return(this.NotFound()); } await this.postService.EditPostContent(model); return(this.RedirectToAction("Index", "Post", new { id = model.PostId })); }
private Post BuildEditPostModel(EditPostModel model) { return(new Post { Id = model.Id, Title = model.NewPostTitle, Content = model.NewPostContent, Forum_Id = model.ForumId, User_Id = model.UserId, Created = model.DateCreated }); }
/// <summary> /// Edits an existing post /// </summary> /// <param name="editPostModel">Post</param> /// <param name="userEmail">Author's email</param> public async Task Edit(EditPostModel editPostModel, string userEmail) { var currentUser = _userRepository.GetByEmail(userEmail); var post = await _postRepository.FindById(editPostModel.Id); if (post.UserId != currentUser.Id) { throw new EditFailedException(); } post.Title = editPostModel.Title; post.Content = editPostModel.Content; post.UpdateDate = DateTime.Now; await _postRepository.Update(post); }
public ActionResult Edit([Bind(Include = "Id,Title,Content")] EditPostModel editPostModel) { if (ModelState.IsValid) { Post post = db.Posts.Find(editPostModel.Id); post.Title = editPostModel.Title; post.Content = editPostModel.Content; db.Entry(post).State = EntityState.Modified; db.SaveChanges(); return(RedirectToAction("Details", new { id = editPostModel.Id })); } return(View(editPostModel)); }
public ActionResult Edit(EditPostModel model) { if (ModelState.IsValid) { var post = new Post() { Body = model.Body, Title = model.Title, IsPublic = model.IsPublic, IdPost = model.PostId }; Services.PostService.EditPost(post); } return(RedirectToAction("ManagePosts")); }
public async Task <ActionResult> Update(EditPostModel model) { if (model.AuthorId != _contextService.CurrentAccount.AccountId) { return(Json(new { success = false, errorMsg = "您不是帖子的作者,不能编辑该帖子。" })); } var result = await _commandService.SendAsync(new UpdatePostCommand(model.Id, model.Subject, model.Body)); if (result.Status != AsyncTaskStatus.Success) { return(Json(new { success = false, errorMsg = result.ErrorMessage })); } return(Json(new { success = true })); }
private string UploadedFile(EditPostModel model) { string uniqueFileName = "defaultIcon.jpg"; if (model.CoverImage != null) { string uploadsFolder = Path.Combine(_webHostEnvironment.WebRootPath, "CoverImages"); uniqueFileName = Guid.NewGuid().ToString() + "_" + model.CoverImage.FileName; string filePath = Path.Combine(uploadsFolder, uniqueFileName); using (var fileStream = new FileStream(filePath, FileMode.Create)) { model.CoverImage.CopyTo(fileStream); } } return(uniqueFileName); }
// GET: Blog/Edit/5 public async Task <ActionResult> EditAsync(Guid id) { var username = _session.GetString("UserName"); var post = await BlogService.Posts(id); var editPost = new EditPostModel(); editPost.Id = post.Id; editPost.Title = post.Title; editPost.Content = post.Content; editPost.SubmitDate = post.SubmitDate; editPost.Username = post.Author.UserName; return(View(editPost)); }
public async Task <ActionResult> EditAsync(int id, EditPostModel post) { try { var username = _session.GetString("UserName"); var postId = await BlogService.UpdatePost(post.Id, post.Title, post.Content, post.SubmitDate, post.Username); return(RedirectToAction("Index")); } catch (Exception ex) { ModelState.AddModelError("Edit error", ex.Message); return(View()); } }
public async Task Should_get_specific_post(int id, EditPostModel expected) { var post = new Post { Id = id }; var editPostModel = new EditPostModel { Id = id }; _mockPostRepository.Setup(repo => repo.FindById(id)).ReturnsAsync(post); _mockEditPostMapper.Setup(mapper => mapper.ToBlModel(post)).Returns(editPostModel); var result = await _postService.GetById(id); result.Should().BeEquivalentTo(expected); }
public async Task EditPostContentEditsTheContent() { await this.SeedPosts(); var model = new EditPostModel { PostId = this.testPost1.Id, Content = "Hi guys I am a noobie.", PostTitle = this.testPost1.Title, }; await this.postsService.EditPostContent(model); var result = this.testPost1.Content == model.Content; Assert.True(result); }
public static IEnumerable <BllTag> ToTags(this EditPostModel post) { string tags = post.Tags ?? ""; var matches = TagService.GetTagMatches(tags); var bllTags = new List <BllTag>(); foreach (Match match in matches) { bllTags.Add(new BllTag { Name = match.Value, PostId = post.Id }); } return(bllTags); }
public async Task <IActionResult> Edit(EditPostModel model) { //if (id != posted.Id) //{ // return NotFound(); //} Posted posted = _context.Posteds.Find(model.Id); if (ModelState.IsValid && posted != null) { posted.Point = model.Point; posted.CreatedAt = model.CreatedAt; posted.ApplicationUserId = model.ApplicationUserId; posted.SeasonId = model.SeasonId; if (model.ImagePath != null && model.ImagePath.Length > 0) { //if (model.ExistPhotoPath != null) //{ // string filepath = Path.Combine(hostingEnvironment.WebRootPath, "images", model.ExistPhotoPath); // System.IO.File.Delete(filepath); //} posted.ImagePath = ProccedFileUpload(model); } try { _context.Update(posted); await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!PostedExists(posted.Id)) { return(NotFound()); } else { throw; } } return(RedirectToAction(nameof(Index))); } ViewData["ApplicationUserId"] = new SelectList(_context.Users, "Id", "Id", posted.ApplicationUserId); ViewData["SeasonId"] = new SelectList(_context.Seasons, "Id", "Id", posted.SeasonId); return(View(model)); }
public async Task <ActionResult> Update(EditPostModel model) { var currentAccount = _contextService.GetCurrentAccount(HttpContext); if (model.AuthorId != currentAccount.AccountId) { return(Json(new { success = false, errorMsg = "您不是帖子的作者,不能编辑该帖子。" })); } var result = await _commandService.ExecuteAsync(new UpdatePostCommand(model.Id, model.Subject, model.Body)); if (result.Status == CommandStatus.Failed) { return(Json(new { success = false, errorMsg = result.Result })); } return(Json(new { success = true })); }
public async Task <ActionResult> Update(EditPostModel model) { if (model.AuthorId != _contextService.CurrentAccount.AccountId) { return(Json(new { success = false, errorMsg = "您不是帖子的作者,不能编辑该帖子。" })); } AsyncTaskResult <CommandResult> asyncTaskResult = await _commandService.ExecuteAsync(new UpdatePostCommand(model.Id, model.Subject, model.Body), CommandReturnType.EventHandled); var result = asyncTaskResult.Data; if (result.Status == CommandStatus.Failed) { return(Json(new { success = false, errorMsg = result.ErrorMessage })); } return(Json(new { success = true })); }
public void ReturnsCorrectPost_When_Executed_WithValidData() { //Arrange var expectedPostsFound = new EditPostModel { Id = 3, Title = "Title No 3", Description = "The shortest post description - part 3", Price = 30, UserId = 1 }; var foundPost = new Mock <Post>(); foundPost.Object.Status = true; //Act & Assert Assert.AreEqual(expectedPostsFound.Id, postServices.FindPostById(3).Id); }