コード例 #1
0
        // GET: TicketNotifications/Edit/5
        public ActionResult Edit(int?id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            TicketNotification ticketNotification = db.TicketNotifications.Find(id);

            if (ticketNotification == null)
            {
                return(HttpNotFound());
            }
            ViewBag.RecipientId = new SelectList(db.Users, "Id", "LastName", ticketNotification.RecipientId); //Finds the db.Property by Id followed by the
            //property being used for the view.
            ViewBag.SenderId = new SelectList(db.Users, "Id", "LastName", ticketNotification.SenderId);
            ViewBag.TicketId = new SelectList(db.Tickets, "Id", "Title", ticketNotification.TicketId);
            return(View(ticketNotification));
        }
コード例 #2
0
        public ActionResult Edit(Tickets tickets)
        {
            if (ModelState.IsValid)
            {

                var userId = User.Identity.GetUserId();
                var changed = System.DateTimeOffset.Now;
                var oldTicket = db.Tickets.AsNoTracking().FirstOrDefault(t => t.Id == tickets.Id);
                var AssignedUser = db.Users.Find(tickets.AssignedToUserId);
                EmailService es = new EmailService();
                if (oldTicket.Title != tickets.Title)
                {
                    var history1 = new TicketHistory();
                    history1.TicketsId = tickets.Id;
                    history1.Property = "Title";
                    history1.OldValue = oldTicket.Title;
                    history1.NewValue = tickets.Title;
                    history1.Changed = changed;
                    history1.UserId = userId;
                    db.TicketHistories.Add(history1);
                }

                if (oldTicket.Description != tickets.Description)
                {
                    var history2 = new TicketHistory();
                    history2.TicketsId = tickets.Id;
                    history2.Property = "Description";
                    history2.OldValue = oldTicket.Description;
                    history2.NewValue = tickets.Description;
                    history2.Changed = changed;
                    history2.UserId = userId;
                    db.TicketHistories.Add(history2);
                }

                if (oldTicket.TicketPriorityId != tickets.TicketPriorityId)
                {
                    var history3 = new TicketHistory();
                    history3.TicketsId = tickets.Id;
                    history3.Property = "Priority";
                    history3.OldValue = oldTicket.TicketPriority.Name;
                    history3.NewValue = db.TicketPriorities.Find(tickets.TicketPriorityId).Name;
                    history3.Changed = changed;
                    history3.UserId = userId;
                    db.TicketHistories.Add(history3);
                    IdentityMessage im3 = new IdentityMessage
                    {
                        Subject = "Ticket Priority Change",
                        Body = tickets.Title + " had a priority change.",
                        Destination = AssignedUser.Email
                    };
                    es.SendAsync(im3);

                    var notification3 = new TicketNotification();
                    notification3.TicketsId = tickets.Id;
                    notification3.TimeStamp = changed;
                    notification3.UserId = userId;
                    notification3.Message = "Subject: " + im3.Subject + "Message: " + im3.Body;
                    notification3.Message = im3.Subject;
                    db.TicketNotification.Add(notification3);
                }

                if (oldTicket.TicketStatusId != tickets.TicketStatusId)
                {
                    var history4 = new TicketHistory();
                    history4.TicketsId = tickets.Id;
                    history4.Property = "Status";
                    history4.OldValue = oldTicket.TicketStatus.Name;
                    history4.NewValue = db.TicketStatus.Find(tickets.TicketStatusId).Name;
                    history4.Changed = changed;
                    history4.UserId = userId;
                    db.TicketHistories.Add(history4);
                    IdentityMessage im4 = new IdentityMessage
                    {
                        Subject = "Ticket Status Change",
                        Body = tickets.Title + " has had a status change.",
                        Destination = AssignedUser.Email
                    };
                    es.SendAsync(im4);

                    var notification4 = new TicketNotification();
                    notification4.TicketsId = tickets.Id;
                    notification4.TimeStamp = changed;
                    notification4.UserId = userId;
                    notification4.Message = "Subject: " + im4.Subject + "Message: " + im4.Body;
                    notification4.Message = im4.Subject;
                    db.TicketNotification.Add(notification4);
                }

                if (oldTicket.TicketTypeId != tickets.TicketTypeId)
                {
                    var history5 = new TicketHistory();
                    history5.TicketsId = tickets.Id;
                    history5.Property = "Type of Ticket";
                    history5.OldValue = oldTicket.TicketType.Name;
                    history5.NewValue = db.TicketType.Find(tickets.TicketTypeId).Name;
                    history5.Changed = changed;
                    history5.UserId = userId;
                    db.TicketHistories.Add(history5);
                }

                if (oldTicket.AssignedToUserId != tickets.AssignedToUserId)
                {
                    var history6 = new TicketHistory();
                    history6.TicketsId = tickets.Id;
                    history6.Property = "Assigned To";
                    history6.OldValue = oldTicket.AssignedToUser == null ? "" : oldTicket.AssignedToUser.FirstName;
                    history6.NewValue = db.Users.Find(tickets.AssignedToUserId).FirstName;

                    history6.Changed = changed;
                    history6.UserId = userId;
                    db.TicketHistories.Add(history6);

                    IdentityMessage im6 = new IdentityMessage
                    {
                        Subject = "Ticket Assignment",
                        Body = tickets.Title + " has been assigned to you.",
                        Destination = AssignedUser.Email
                    };
                    es.SendAsync(im6);

                    var notification6 = new TicketNotification();
                    notification6.TicketsId = tickets.Id;
                    notification6.TimeStamp = changed;
                    notification6.UserId = userId;
                    notification6.Message = "Subject: " + im6.Subject + "Message : " + im6.Body;
                    db.TicketNotification.Add(notification6);
                }

                tickets.Updated = DateTimeOffset.Now;
                db.Tickets.Attach(tickets);
                db.Entry(tickets).Property(p => p.AssignedToUserId).IsModified = true;
                db.Entry(tickets).Property(p => p.Description).IsModified = true;
                db.Entry(tickets).Property(p => p.TicketStatusId).IsModified = true;
                db.Entry(tickets).Property(p => p.TicketTypeId).IsModified = true;
                db.Entry(tickets).Property(p => p.TicketPriorityId).IsModified = true;

                if(tickets.TicketStatusId == 1)
                {
                    tickets.AssignedToUserId = null;
                }

                db.SaveChanges();
                return RedirectToAction("Index");
            }

            ViewBag.ProjectId = new SelectList(db.Projects, "Id", "Name", tickets.ProjectId);
            ViewBag.TicketPriorityId = new SelectList(db.TicketPriorities, "Id", "Name", tickets.TicketPriorityId);
            ViewBag.TicketStatusId = new SelectList(db.TicketStatus, "Id", "Name", tickets.TicketStatusId);
            ViewBag.TicketTypeId = new SelectList(db.TicketType, "Id", "Name", tickets.TicketTypeId);
            ViewBag.AssignedToUserId = new SelectList(db.Users, "Id", "FirstName");
            return RedirectToAction("Index");
        }
コード例 #3
0
        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);
        }
コード例 #4
0
        public ActionResult Edit(Ticket ticket)
        {
            var user = db.Users.Find(User.Identity.GetUserId());
            var oldTicket = db.Tickets.AsNoTracking().FirstOrDefault(t => t.Id == ticket.Id);
            if (ModelState.IsValid)
            {
                if (oldTicket.Body != ticket.Body)
                {
                    var notification = new TicketNotification();
                    var history = new TicketHistory();
                    history.OldValue = oldTicket.Body;
                    history.NewValue = ticket.Body;
                    history.ChangedById = User.Identity.GetUserId();
                    history.TicketId = ticket.Id;
                    db.TicketHistories.Add(history);
                    notification.UserId = ticket.AssignedUserId;
                    notification.TicketId = ticket.Id;
                    notification.Content =  "changed the body of the ticket!";
                    db.TicketNotifications.Add(notification);

                }

                if (oldTicket.Title != ticket.Title)
                {
                    var notification = new TicketNotification();
                    var history = new TicketHistory();
                    history.OldValue = oldTicket.Title;
                    history.NewValue = ticket.Title;
                    history.ChangedById = User.Identity.GetUserId();
                    history.TicketId = ticket.Id;
                    db.TicketHistories.Add(history);
                    notification.UserId = ticket.AssignedUserId;
                    notification.TicketId = ticket.Id;
                    notification.Content =  "changed the title of the ticket!";
                    db.TicketNotifications.Add(notification);

                }

                //if (oldTicket.AssignedUserId != ticket.AssignedUserId)
                //{
                //    var notification = new TicketNotification();
                //    var history = new TicketHistory();
                //    history.OldValue = oldTicket.AssignedUser.DisplayName;
                //    history.NewValue = db.Tickets.Find(ticket.Id).AssignedUser.DisplayName;
                //    history.ChangedById = User.Identity.GetUserId();
                //    history.TicketId = ticket.Id;
                //    db.TicketHistories.Add(history);
                //    notification.UserId = ticket.AssignedUserId;
                //    notification.TicketId = ticket.Id;
                //    db.TicketNotifications.Add(notification);
                //}

                if (oldTicket.PriorityId != ticket.PriorityId)
                {
                    var notification = new TicketNotification();
                    var history = new TicketHistory();
                    history.OldValue = oldTicket.Priority.Name;
                    history.NewValue = db.TicketPriorities.Find(ticket.PriorityId).Name;
                    history.ChangedById = User.Identity.GetUserId();
                    history.TicketId = ticket.Id;
                    db.TicketHistories.Add(history);
                    notification.UserId = ticket.AssignedUserId;
                    notification.TicketId = ticket.Id;
                    notification.Content =  "changed the priority of the ticket!";
                    db.TicketNotifications.Add(notification);
                }

                if (oldTicket.ProjectId != ticket.ProjectId)
                {
                    var notification = new TicketNotification();
                    var history = new TicketHistory();
                    history.OldValue = oldTicket.Project.Name;
                    history.NewValue = db.Projects.Find(ticket.ProjectId).Name;
                    history.ChangedById = User.Identity.GetUserId();
                    history.TicketId = ticket.Id;
                    db.TicketHistories.Add(history);
                    notification.UserId = ticket.AssignedUserId;
                    notification.TicketId = ticket.Id;
                    notification.Content =  "changed the project of the ticket!";
                    db.TicketNotifications.Add(notification);
                }

                if (oldTicket.StatusId != ticket.StatusId)
                {
                    var notification = new TicketNotification();
                    var history = new TicketHistory();
                    history.OldValue = oldTicket.Status.Name;
                    history.NewValue = db.TicketStatuses.Find(ticket.StatusId).Name;
                    history.ChangedById = User.Identity.GetUserId();
                    history.TicketId = ticket.Id;
                    db.TicketHistories.Add(history);
                    notification.UserId = ticket.AssignedUserId;
                    notification.TicketId = ticket.Id;
                    notification.Content =  "changed the status of the ticket!";
                    db.TicketNotifications.Add(notification);
                }

                if (oldTicket.TypeId != ticket.TypeId)
                {
                    var notification = new TicketNotification();
                    var history = new TicketHistory();
                    history.OldValue = oldTicket.Type.Name;
                    history.NewValue = db.TicketTypes.Find(ticket.TypeId).Name;
                    history.ChangedById = User.Identity.GetUserId();
                    history.TicketId = ticket.Id;
                    db.TicketHistories.Add(history);
                    notification.UserId = ticket.AssignedUserId;
                    notification.TicketId = ticket.Id;
                    notification.Content =  "changed the type of the ticket!";
                    db.TicketNotifications.Add(notification);

                }

                db.Tickets.Add(ticket);
                ticket.Updated = DateTimeOffset.Now;

                db.Entry(ticket).State = EntityState.Modified;

                db.SaveChanges();

            }
            return RedirectToAction("Details", new { id = ticket.Id });
        }
コード例 #5
0
        public async Task<ActionResult> Edit([Bind(Include = "Id,Title,Description,Created,Updated,ProjectId,TicketTypeId,TicketPriorityId,TicketStatusId,OwnerUserId,AssignedToUserId")] Ticket ticket, string assignedUser)
        {
            var editable = new List<string>() { "Title", "Description" };
            if (User.IsInRole("Admin"))
                editable.AddRange(new string[] { "AssignedToUserId", "TicketTypeId", "TicketPriorityId", "TicketStatusId", "Updated"});
            if (User.IsInRole("Project Manager"))
                editable.AddRange(new string[] { "AssignedToUserId", "TicketTypeId", "TicketPriorityId", "TicketStatusId", "Updated" });

            if (ModelState.IsValid)
            {
                ticket.Updated = DateTimeOffset.Now;
                var oldTicket = db.Tickets.AsNoTracking().FirstOrDefault(t => t.Id == ticket.Id);
                var histories = GetTicketHistories(oldTicket, ticket).Where(h => editable.Contains(h.History.Property));

                var mailer = new EmailService();
                foreach (var item in histories)
                {
                    db.TicketHistories.Add(item.History);
                   // if (item.Notification != null)
                       //await mailer.SendAsync(item.Notification);
                }

                if (oldTicket.AssignedToUserId != ticket.AssignedToUserId)
                {
                    if (ticket.AssignedToUserId != null)
                    {
                        TicketNotification newUserNotification = new TicketNotification()
                        {
                            TicketId = ticket.Id,
                            UserId = ticket.AssignedToUserId,
                            Message = "You have been assigned to this ticket: " + ticket.Title + ".",
                            Created = DateTimeOffset.Now
                        };
                        db.TicketNotifications.Add(newUserNotification);
                    }

                    if (oldTicket.AssignedToUserId != null)
                    {
                        TicketNotification oldUserNotification = new TicketNotification()
                        {
                            TicketId = ticket.Id,
                            UserId = oldTicket.AssignedToUserId,
                            Message = "You have been unassigned from this ticket: " + oldTicket.Title + ".",
                            Created = DateTimeOffset.Now
                        };
                        db.TicketNotifications.Add(oldUserNotification);
                    }
                }

                if(oldTicket.Title != ticket.Title)
                {
                    TicketNotification notification = new TicketNotification()
                    {
                        TicketId = ticket.Id,
                        UserId = ticket.AssignedToUserId,
                        Message = "A ticket you're assigned to has had a title change. The title was changed from '" + oldTicket.Title + "' to '" + ticket.Title + "'.",
                        Created = DateTimeOffset.Now
                    };
                    db.TicketNotifications.Add(notification);
                }

                if(oldTicket.Description != ticket.Description)
                {
                    TicketNotification notification = new TicketNotification()
                    {
                        TicketId = ticket.Id,
                        UserId = ticket.AssignedToUserId,
                        Message = "A ticket you're assigned to has had a description change. The description was changed from '" + oldTicket.Description + "' to '" + ticket.Description + "'.",
                        Created = DateTimeOffset.Now
                    };
                    db.TicketNotifications.Add(notification);
                }

                if(oldTicket.TicketPriorityId != ticket.TicketPriorityId)
                {
                    TicketNotification notification = new TicketNotification()
                    {
                        TicketId = ticket.Id,
                        UserId = ticket.AssignedToUserId,
                        Message = "The priority of a ticket you're assigned to has changed. The ticket that changed is '" + ticket.Title + "'.",
                        Created = DateTimeOffset.Now
                    };
                    db.TicketNotifications.Add(notification);
                }

                if(oldTicket.TicketStatusId != ticket.TicketStatusId)
                {
                    TicketNotification notification = new TicketNotification()
                    {
                        TicketId = ticket.Id,
                        UserId = ticket.AssignedToUserId,
                        Message = "The status of a ticket you're assigned to has changed. The ticket that changed is '" + ticket.Title + "'.",
                        Created = DateTimeOffset.Now
                    };
                    db.TicketNotifications.Add(notification);
                }

                db.Update(ticket, editable.ToArray());
                
                await db.SaveChangesAsync();
                return RedirectToAction("Details", new { ticket.Id });
            }
            ViewBag.TicketPriorityId = new SelectList(db.TicketPriorities, "Id", "Name", ticket.TicketPriorityId);
            ViewBag.TicketStatusId = new SelectList(db.TicketStatuses, "Id", "Name", ticket.TicketStatusId);
            ViewBag.TicketTypeId = new SelectList(db.TicketTypes, "Id", "Name", ticket.TicketTypeId);
            ViewBag.AssignedToUserId = new SelectList(db.Users, "Id", "DisplayName", ticket.AssignedToUserId);
            return View(ticket);
        }
コード例 #6
0
 private void SendNotification(string ATUId, int ticketId, string msgSubject)
 {
     var notification = new TicketNotification();
     var ticketTitle = db.Tickets.Find(ticketId).Title;
     var uEmail = db.Users.FirstOrDefault(u => u.Id == ATUId).Email;
     var udName = db.Users.FirstOrDefault(u => u.Id == ATUId).DisplayName;
     var body = "Dear " + udName + ", ";
     if (msgSubject == "A Ticket Has Been Assigned to You")
     {
         body += "A ticket entitled " + ticketTitle
             + " has been assigned to you. ";
         notification.Purpose = "Assignment";
     }
     else
     {
         body += "A ticket to which you are assigned, entitled " + ticketTitle + ", has been modified by another user. ";
         notification.Purpose = "Ticket modified";
     }
     body += "Please log in to the application, click on 'Tickets', and then on the title of this ticket to see the details. "
             + "This is an auto-generated e-mail. Please do not reply to it.";
     manager.SendEmail(ATUId, msgSubject, body);
     notification.TicketId = ticketId;
     notification.UserId = ATUId;
     notification.DateTime = DateTimeOffset.UtcNow;
     db.Entry(notification).State = EntityState.Added;
     db.SaveChanges();
 }
コード例 #7
0
ファイル: HistoryHelper.cs プロジェクト: HemaMitra/BugTracker
        public bool InitializeNoti(int ticketId, string userId, string notiReci, string message)
        {
            TicketNotification noti = new TicketNotification();
            noti.TicketId = ticketId;
            noti.UserId = userId;
            noti.Recipient = notiReci;
            noti.Message = message;
            bool result = Notification(noti.Recipient, noti.Message);
            if (result == true)
            {
                noti.NotiSent = true;
                noti.SentDate = System.DateTimeOffset.Now;
                db.TicketNotification.Add(noti);
                db.SaveChanges();
            }

            return true;
        }