Пример #1
0
 public ActionResult AddComment(TicketComments newComment, HttpPostedFileBase image)
 {
     var ticket = db.Tickets.Find(newComment.TicketID);
     if (image != null && image.ContentLength > 0)
     {
         var ext = Path.GetExtension(image.FileName).ToLower();
         if (ext != ".png" && ext != ".jpg" && ext != ".jpeg" && ext != ".gif" && ext != ".bmp")
         {
             ModelState.AddModelError("image", "Invalid Format");
         }
     }
     if (ModelState.IsValid)
     {
         if (image != null)
         {
             var filePath = "/Uploads/";
             var absPath = Server.MapPath("~" + filePath);
             newComment.MediaURL = filePath + image.FileName;
             Directory.CreateDirectory(absPath);
             image.SaveAs(Path.Combine(absPath, image.FileName));
         }
         new EmailService().SendAsync(new IdentityMessage()
         {
             Destination = ticket.AssignedTo.Email,
             Subject = "Comment Notification for " + ticket.Title,
             Body = User.Identity.Name + " added: " + newComment.Body
         });
         TicketNotifications notification = new TicketNotifications();
         notification.NotifiedUserID = ticket.AssignedToID;
         notification.TicketID = ticket.ID;
         notification.Property = "Comment";
         db.Notifications.Add(notification);
         newComment.Created = System.DateTimeOffset.Now;
         newComment.AuthorID = User.Identity.GetUserId();
         db.Comments.Add(newComment);
         db.SaveChanges();
     }
     return RedirectToAction("Details", "Tickets", new { id = ticket.ID });
 }
Пример #2
0
        public ActionResult EditComment(TicketComments changeTicketComment)
        {
            if (ModelState.IsValid)
            {
                changeTicketComment.Created = System.DateTimeOffset.Now;
                changeTicketComment.UserId = User.Identity.GetUserId();
                db.TicketComments.Attach(changeTicketComment);
                db.Entry(changeTicketComment).Property(p => p.Created).IsModified = true;
                db.Entry(changeTicketComment).Property(p => p.Body).IsModified = true;
                db.SaveChanges();

            }
            return RedirectToAction("Details", new { id = changeTicketComment.TicketsId });
        }
Пример #3
0
 public ActionResult CreateTicketComment(TicketComments comment)
 {
     if (ModelState.IsValid)
     {
         comment.Created = System.DateTimeOffset.Now;
         comment.UserId = User.Identity.GetUserId();
         db.TicketComments.Add(comment);
         db.SaveChanges();
     }
     return RedirectToAction("Details", new { id = comment.TicketsId });
 }
Пример #4
0
        public ActionResult CreateComments(TicketComments tc,HttpPostedFileBase image,string backUrl)
        {
            // uploading image
            if (image != null && image.ContentLength > 0)
            {
                // Check the file name for allowed file types
                var ext = Path.GetExtension(image.FileName).ToLower();
                if (ext != ".png" && ext != ".jpg" && ext != ".jpeg" && ext != ".gif" && ext != ".bmp" && ext != ".doc" && ext != ".pdf")
                {
                    ModelState.AddModelError("image", "Invalid Format");
                }
            }

            if (ModelState.IsValid)
            {
                // Saving Image
                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
                    tc.FileUrl = filePath + "/" + image.FileName;

                    // save image
                    Directory.CreateDirectory(absPath);
                    image.SaveAs(Path.Combine(absPath, image.FileName));
                }
                tc.CommentsCreated = System.DateTimeOffset.Now;
                tc.FilePath = null;
                db.TicketComments.Add(tc);
                db.SaveChanges();

                // Notification
                var ticket = db.Tickets.Find(tc.TicketId);

                if(ticket.TicketStatus.StatusName != "Unassigned")
                {
                    var userId = User.Identity.GetUserId();
                    string notiReci = histHelper.getAssignedUserEmail(ticket.AssignedToUserId);
                    string notiMessage = "Hello " + notiReci + ". A new comment has been created for the following ticket <U>" + ticket.Id + "</U>";
                    histHelper.InitializeNoti(ticket.Id, userId, notiReci, notiMessage);
                }
            }
            if (backUrl.Equals("Edit"))
            {
                return RedirectToAction("Edit", "Tickets", new { id = tc.TicketId });
            }
            return RedirectToAction("Details", "Tickets", new { id = tc.TicketId });
        }
Пример #5
0
        // Edit Comment
        public ActionResult EditComment(TicketComments tc)
        {
            if (ModelState.IsValid)
            {

                TicketComments Comment = db.TicketComments.Find(tc.Id);
                Comment.UpdatedBy = User.Identity.GetUserName();
                Comment.UpdateDate = System.DateTimeOffset.Now;
                Comment.Comments = tc.Comments;
                Comment.FileDesc = tc.FileDesc;
                db.TicketComments.Attach(Comment);

                db.Entry(Comment).Property("UpdateDate").IsModified = true;
                db.Entry(Comment).Property("Comments").IsModified = true;
                db.Entry(Comment).Property("UpdatedBy").IsModified = true;
                db.Entry(Comment).Property("FileDesc").IsModified = true;
                db.SaveChanges();

                // Notification
                var ticket = db.Tickets.Find(tc.TicketId);

                if (ticket.TicketStatus.StatusName != "Unassigned")
                {
                    var userId = User.Identity.GetUserId();
                    string notiReci = histHelper.getAssignedUserEmail(ticket.AssignedToUserId);
                    string notiMessage = "Hello " + notiReci + ". A comment has been changed for the following ticket <U>" + ticket.Id +
                        "</U>";
                    histHelper.InitializeNoti(ticket.Id, userId, notiReci, notiMessage);
                }
            }
            return RedirectToAction("Details", "Tickets", new { id = tc.TicketId });
        }