示例#1
0
 public ActionResult Edit([Bind(Include = "Id,Created,CommentBody,TicketId,UserId")] TicketComment ticketComment)
 {
     if (ModelState.IsValid)
     {
         db.Entry(ticketComment).State = EntityState.Modified;
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     ViewBag.TicketId = new SelectList(db.Tickets, "Id", "SubmitterId", ticketComment.TicketId);
     ViewBag.UserId   = new SelectList(db.Users, "Id", "FirstName", ticketComment.UserId);
     return(View(ticketComment));
 }
        public ActionResult DeleteConfirmed(int?id)
        {
            TicketComment ticketComment = db.TicketComments.Find(id);

            db.TicketComments.Remove(ticketComment);
            db.SaveChanges();
            //return RedirectToAction("Details", "Tickets", new { id = ticketId });
            //return RedirectToAction("Index", "Tickets");

            string url = this.Request.UrlReferrer.AbsolutePath;

            return(Redirect(url)); //This and the above lines of code redirect the user to the same page after deleting a comment.
        }
        // GET: TicketComments/Details/5
        public ActionResult Details(int?id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            TicketComment ticketComment = db.TicketComments.Find(id);

            if (ticketComment == null)
            {
                return(HttpNotFound());
            }
            return(View(ticketComment));
        }
 public ActionResult Edit([Bind(Include = "Id,TicketId,AuthorId,CommentBody,Created")] TicketComment ticketComment)
 {
     if (ModelState.IsValid)
     {
         db.Entry(ticketComment).State = EntityState.Modified;
         db.SaveChanges();
         //return RedirectToAction("Details", "Tickets", new { id = TicketId });
         return(RedirectToAction("Index", "Tickets"));
         //string url = this.Request.UrlReferrer.AbsolutePath;
         //return Redirect(url); //This and the above lines of code redirect the user to the same page after deleting an attachment.
     }
     ViewBag.TicketId = new SelectList(db.Tickets, "Id", "OwnerUserId", ticketComment.TicketId);
     return(View(ticketComment));
 }
        // GET: TicketComments/Edit/5
        public ActionResult Edit(int?id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            TicketComment ticketComment = db.TicketComments.Find(id);

            if (ticketComment == null)
            {
                return(HttpNotFound());
            }
            ViewBag.TicketId = new SelectList(db.Tickets, "Id", "OwnerUserId", ticketComment.TicketId);
            return(View(ticketComment));
        }
示例#6
0
        public ActionResult Create([Bind(Include = "Id,Created,CommentBody,TicketId,UserId,ProjectId")] TicketComment ticketComment)
        {
            if (ModelState.IsValid)
            {
                ticketComment.UserId  = User.Identity.GetUserId();
                ticketComment.Created = DateTime.Now;
                db.TicketComments.Add(ticketComment);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            ViewBag.TicketId = new SelectList(db.Tickets, "Id", "SubmitterId", ticketComment.TicketId);
            ViewBag.UserId   = new SelectList(db.Users, "Id", "FirstName", ticketComment.UserId);
            return(View(ticketComment));
        }
        public ActionResult Create([Bind(Include = "Id,TicketId,AuthorId,CommentBody,Created")] TicketComment ticketComment, string commentBody, int ticketId)
        {
            if (ModelState.IsValid)
            {
                var localDate = DateTime.UtcNow.AddHours(-4);

                Ticket ticket = db.Tickets.Find(ticketId); //Finds the ticket in which the comment belongs
                ticketComment.CommentBody = commentBody;
                ticketComment.AuthorId    = User.Identity.GetUserId();
                ticketComment.Created     = localDate;
                db.TicketComments.Add(ticketComment);
                db.SaveChanges();

                NotificationHelper.GenerateCommentNotification(ticket); //Passes the ticket in to create a notification that a comment was added to the ticket.


                return(RedirectToAction("Dashboard", "Tickets", new { id = ticketId })); //Returns user to the page of the ticket they were commenting on
            }

            ViewBag.TicketId = new SelectList(db.Tickets, "Id", "OwnerUserId", ticketComment.TicketId);
            return(View(ticketComment));
        }
        public ActionResult SubmitComment(TicketComment comment, HttpPostedFileBase image, int TicketId)
        {
            var user = db.Users.Find(User.Identity.GetUserId());
            var ticket = db.Tickets.Find(TicketId);
            if (image != null && image.ContentLength > 0)
            {
                //check the file name to make sure its an image
                var ext = Path.GetExtension(image.FileName).ToLower();
                if (ext != ".png" && ext != ".jpg" && ext != ".jpeg" && ext != ".gif" && ext != ".bmp")
                {
                    ModelState.AddModelError("image", "Invalid Format.");
                }
                if (image != null)
                {
                    //relative server path
                    var filePath = "/Uploads/";
                    //path on physical drive on server
                    var absPath = Server.MapPath("~" + filePath);
                    //media url for relative path
                    comment.MediaURl = filePath + image.FileName;
                    Directory.CreateDirectory(absPath);
                    //save image
                    image.SaveAs(Path.Combine(absPath, image.FileName));
                }
            }

            if (ModelState.IsValid)
            {
                comment.Created = DateTimeOffset.Now;
                var notification = new TicketNotification();
                db.TicketComments.Add(comment);
                ticket.TicketComments.Add(comment);
                notification.UserId = ticket.AssignedUserId;
                notification.TicketId = ticket.Id;
                notification.Content =  "left a comment on ticket!";
                db.TicketNotifications.Add(notification);

                db.SaveChanges();
            }

            return RedirectToAction("Details",ticket);
        }