public async Task <ActionResult> DeleteComment(int id, string returnUrl) { CommentsEntities context = new CommentsEntities(); Comments comment = new Comments(); comment = await context.Comments.FindAsync(id); if (comment != null) { context.Comments.Remove(comment); await context.SaveChangesAsync(); return(Redirect(returnUrl ?? "Blog/Index")); } else { return(View("Error", new string[] { "Комментарий не найден" })); } }
public async Task <ActionResult> WriteComment(Comments comment, string returnUrl) { if (ModelState.IsValid) { CommentsEntities context = new CommentsEntities(); BlogPostsManager bpMan = new BlogPostsManager(); comment.Content = bpMan.AddLineBreaks(comment.Content); comment.Time = this.HttpContext.Timestamp; comment.Author = CurrentUser.UserName; comment.PostId = comment.Id; comment.Id = 0; context.Comments.Add(comment); try { await context.SaveChangesAsync(); } catch (DbEntityValidationException e) { #if false foreach (var eve in e.EntityValidationErrors) { Console.WriteLine("Entity of type \"{0}\" in state \"{1}\" has the following validation errors:", eve.Entry.Entity.GetType().Name, eve.Entry.State); foreach (var ve in eve.ValidationErrors) { Console.WriteLine("- Property: \"{0}\", Error: \"{1}\"", ve.PropertyName, ve.ErrorMessage); } } #endif } return(Redirect(returnUrl ?? "Blog/Index")); } return(View("Error", new string[] { "TODO: Доделать. Ошибка связанная с созданием поста" })); }