Exemple #1
0
        public async Task <ActionResult> Create([Bind(Include = "TicketID,CommentorID,CommentDate,Comment1")] CommentViewModel commentVM)
        {
            // set commentDate b/c it's not in the view.
            commentVM.CommentDate = DateTime.UtcNow;

            if (ModelState.IsValid)
            {
                db.Comments.Add(commentVM.ToComment());
                await db.SaveChangesAsync();

                return(RedirectToAction("Details", "Tickets", new { id = commentVM.TicketID }));
            }

            var username = HttpContext.User.Identity.Name;

            ViewBag.TicketID    = new SelectList(db.Tickets.Where(t => t.ID == commentVM.TicketID), "ID", "Title", commentVM.TicketID);
            ViewBag.CommentorID = new SelectList(db.Users.Where(u => u.ASPUserName == username), "ID", "ASPUserName");
            return(View(commentVM.ToComment()));
        }