public ActionResult Create(Comment comment) { if (ModelState.IsValid) { comment.Author = User.Identity.Name; cdb.Comments.Add(comment); cdb.SaveChanges(); Post post = pdb.Posts.Find(comment.RefferedPost); IntegerData idata = new IntegerData(); idata.Data = comment.ID; post.Comments.Add(idata); pdb.Entry(post).State = EntityState.Modified; pdb.SaveChanges(); //if is hitchhiker if (comment.Hitchhiker == true) { Hitchhiker hitch = new Hitchhiker() { Name = comment.Author, Phone = comment.PhoneNumber, PostID = comment.RefferedPost }; hdb.Hitchhikers.Add(hitch); hdb.SaveChanges(); } return(RedirectToAction("Details", "Post", new { id = post.ID })); } else { return(View(comment)); } }
public async Task CreateComment(int id, [FromBody] Comment comment) { Post currentPost = db.Posts.Find(id); if (currentPost != null && comment != null) { currentPost.comments.Add(comment); db.Entry(currentPost).State = EntityState.Modified; await db.SaveChangesAsync(); } logger.LogInformation($"Method POST / path: {Request.Path} / status: {Response.StatusCode}"); }
public async Task <IActionResult> PutComment(int id, Comment comment) { if (id != comment.CommentId) { return(BadRequest()); } _context.Entry(comment).State = EntityState.Modified; try { await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!CommentExists(id)) { return(NotFound()); } else { throw; } } return(NoContent()); }
public async Task Update(Post model, Guid postId) { _context.Entry(await _context.Posts .FirstOrDefaultAsync(p => p.Id == postId)) .CurrentValues .SetValues(model); }
public async Task <IActionResult> PutPost(int id, Post Post) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } if (id != Post.PostId) { return(BadRequest()); } _context.Entry(Post).State = EntityState.Modified; try { await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!PostExists(id)) { return(NotFound()); } else { throw; } } return(NoContent()); }
public async Task UpdatePostAsync(int id, CreatePostDTO postDTO) { var post = await context.Posts.FindAsync(id); if (post == null) { throw new NotFoundException(ErrorCode.ResourceNotFound, "post was not found"); } post.Annotation = postDTO.Annotation; post.Content = postDTO.Content; post.Title = postDTO.Title; post.DateRefreshed = DateTime.Now; context.Entry(post).State = EntityState.Modified; await context.SaveChangesAsync(); }
public ActionResult Edit(Post post) { if (ModelState.IsValid) { if (post.GoogleMap == null) { post.GoogleMap = "https://www.google.com/maps/embed?pb=!1m18!1m12!1m3!1d15196.733401840413!2d34.76801167151065!3d31.969372704850464!2m3!1f0!2f0!3f0!3m2!1i1024!2i768!4f13.1!3m3!1m2!1s0x1502b3f5eb44e1c1%3A0xfbe9b8c6bce59319!2z15TXnteh15zXldecINeU15DXp9eT157XmSDXlNee15vXnNec15Qg15zXnteZ16DXlNec!5e0!3m2!1siw!2sil!4v1501339255742"; } if (post.Photo == null) { post.Photo = "https://cdn.dribbble.com/users/22251/screenshots/803201/no-photo-grey.png"; } pdb.Entry(post).State = EntityState.Modified; pdb.SaveChanges(); return(RedirectToAction("Index", "Users")); } RedirectToAction("Index", "Users"); return(View()); }