Esempio n. 1
0
        public ActionResult CreateComment(CommentInputModel model, int tempId)
        {
            if (model != null && this.ModelState.IsValid)
            {
                var currentUser = User.Identity.GetUserId();
                var comment = new Comment()
                {
                    AuthorId = this.User.Identity.GetUserId(),
                    Text = model.Text,
                    EventId = tempId
                };

                try {
                    this.db.Comments.Add(comment);
                    this.db.SaveChanges();
                    this.AddNotification("Comment Posted", NotificationType.INFO);
                    // Display success notification
                    return this.RedirectToAction("My");
                }

                catch (DbEntityValidationException dbEx)
                {
                    foreach (var validationErrors in dbEx.EntityValidationErrors)
                    {
                        foreach (var validationError in validationErrors.ValidationErrors)
                        {
                            Trace.TraceInformation("Property: {0} Error: {1}", validationError.PropertyName, validationError.ErrorMessage);
                        }
                    }
                }

            }
            return this.View(model);
        }
Esempio n. 2
0
        public ActionResult DeleteComment(int id, CommentInputModel model)
        {
            var commentToDelete = this.LoadComment(id);
            if (commentToDelete == null)
            {
                this.AddNotification("Cannot delete comment #" + id, NotificationType.ERROR);
                return this.RedirectToAction("My");
            }

            var comment = this.db.Comments.Where(e => e.Id == id)
                                          .SingleOrDefault();
            db.Comments.Remove(comment);
            db.SaveChanges();
            this.AddNotification("Comment Deleted", NotificationType.INFO);
            return RedirectToAction("My");
        }