예제 #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);
        }
예제 #2
0
        public ActionResult Create(ComentBindingModel model)
        {
            if (model == null || !this.ModelState.IsValid)
            {
                this.AddNotification("Invalid input data", NotificationType.ERROR);
                return this.RedirectToAction("Index", "Home");
            }

            var userId = this.User.Identity.GetUserId();
            var eventById = this.db.Events.Find(model.EventId);

            var comment = new Comment
                {
                    AuthorId = userId,
                    Text = model.Text,
                    Date = DateTime.Now,
                    Event = eventById
                };

            this.db.Comments.Add(comment);
            this.db.SaveChanges();

            var commentView = this.db.Comments
                                  .Where(c => c.Id == comment.Id)
                                  .Select(CommentViewModel.ViewModel())
                                  .FirstOrDefault();

            return this.PartialView("_CommentRow", commentView);
        }
예제 #3
0
 public static CommentInputModel CreateFromComment(Comment c)
 {
     return new CommentInputModel()
     {
         Text = c.Text,
         EventId = c.EventId,
     };
 }
        public ActionResult Create(int id, string eventfulId, bool isEventfulEvent, string Text)
        {
            try
            {
                if (isEventfulEvent)
                {
                    string guid = User.Identity.GetUserId();
                    //Get the user
                    Events.External.AspNetUser user = this.eventfulDb.AspNetUsers.Single(u => u.Id.Equals(guid, StringComparison.InvariantCultureIgnoreCase));

                    //Create the comment
                    EventfulComment comment = new EventfulComment();
                    comment.AuthorId = user.Id;
                    comment.Date = DateTime.Now;
                    comment.EventfulId = eventfulId;
                    comment.Text = Text;

                    //Save
                    user.EventfulComments.Add(comment);
                    this.eventfulDb.SaveChanges();
                }
                else
                {
                    //Create the comment
                    Comment comment = new Comment();
                    comment.Event = this.eventsdb.Events.Single(e => e.Id == id);
                    comment.AuthorId = User.Identity.GetUserId();
                    comment.Date = DateTime.Now;
                    comment.EventId = id;
                    comment.Text = Text;

                    //Save
                    this.eventsdb.Comments.Add(comment);
                    this.eventsdb.SaveChanges();
                }
                return RedirectToAction("Index", "Home");
            }
            catch (Exception e)
            {
                return View();
            }
        }