Пример #1
0
        public async System.Threading.Tasks.Task <ActionResult> Delete(int id)
        {
            Tickets ticket       = db.Tickets.Find(id);
            var     strLoginUser = User.Identity.GetUserId();

            //Sends Ticket staus change to history audit log
            HistoryHelper audit = new HistoryHelper();

            audit.AddHistory(ticket.Id, "Status", ticket.TicketStatus.Name, "Resolved", strLoginUser);

            //Updates Status to Closed in the ticket table
            ticket.TicketStatusId = 4;
            var developer = db.Users.Find(ticket.AssignedToUserId);

            if (developer != null && developer.Email != null)
            {
                var svc = new EmailService();
                var msg = new IdentityMessage();
                msg.Destination = developer.Email;
                msg.Subject     = "Bug Tracker Update: " + ticket.Title;
                msg.Body        = ("Ticket ID: " + ticket.Id + " - " + ticket.Title + "has been resolved");
                await svc.SendAsync(msg);
            }

            db.Tickets.Attach(ticket);
            db.Entry(ticket).Property("TicketStatusId").IsModified = true;
            db.SaveChanges();

            return(RedirectToAction("Index", new { id = ticket.Id }));
        }
Пример #2
0
        public async Task <ActionResult> Edit([Bind(Include = "Id,ProjectId,TicketTypeId,TicketStatusId,TicketPriorityId,Progress,OwnerUserId,AssignedToUserId,AssignedToUserTwoId,Title,Description,Created,Updated")] Ticket ticket)
        {
            if (ModelState.IsValid)
            {
                //Get a reference to the Old Ticket
                var oldTicket = db.Tickets.AsNoTracking().FirstOrDefault(t => t.Id == ticket.Id);
                //Compare it to the incoming Ticket(ticket)

                ticket.OwnerUserId     = User.Identity.GetUserId();
                ticket.Updated         = DateTime.Now;
                db.Entry(ticket).State = EntityState.Modified;
                db.SaveChanges();

                await notificationHelper.Notify(oldTicket, ticket);

                historyHelper.AddHistory(oldTicket, ticket);

                return(RedirectToAction("Index", "Home"));
            }


            var userId     = User.Identity.GetUserId();
            var tAssigned  = roleHelper.UsersInRole("Developer");
            var myProjects = projHelper.ListUserProjects(userId);
            var myTickets  = tickHelper.ListUserTickets();


            ViewBag.Id = new SelectList(myTickets, "Id", "FirstName", ticket.Id);
            ViewBag.AssignedToUserId = new SelectList(tAssigned, "Id", "FirstName", ticket.AssignedToUserId);
            ViewBag.OwnerUserId      = new SelectList(db.Users, "Id", "FirstName", ticket.OwnerUserId);
            ViewBag.ProjectId        = new SelectList(myProjects, "Id", "Name", ticket.ProjectId);
            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);
            return(View(ticket));
        }
Пример #3
0
        public async Task <ActionResult> Assign([Bind(Include = "Id,AssignedToUserId,Created,OwnerUserId,Title,Description,ProjectId,TicketTypeId,TicketStatusId,TicketPrioritiesId")] Tickets tickets)

        {
            HistoryHelper historyHelper = new HistoryHelper();

            StringBuilder updateMessage = new StringBuilder();

            var oldTicketInfo = db.Tickets.AsNoTracking().FirstOrDefault(t => t.Id == tickets.Id);

            if (oldTicketInfo.AssignedToUserId != tickets.AssignedToUserId &&
                oldTicketInfo.AssignedToUserId != null)
            {
                var oldAssignedUser  = db.Users.Find(oldTicketInfo.AssignedToUserId).FirstName + " " + db.Users.Find(tickets.AssignedToUserId).LastName;
                var newAssignedUser2 = db.Users.Find(tickets.AssignedToUserId).FirstName + " " + db.Users.Find(tickets.AssignedToUserId).LastName;
                historyHelper.AddHistory(tickets.Id, "Assigned User", oldAssignedUser, newAssignedUser2, User.Identity.GetUserId());
                updateMessage.AppendFormat("Assigned User: {0}, ", newAssignedUser2);
            }

            if (oldTicketInfo.AssignedToUserId == null && oldTicketInfo.AssignedToUserId != tickets.AssignedToUserId)
            {
                var oldAssignedUser  = "******";
                var newAssignedUser3 = db.Users.Find(tickets.AssignedToUserId).FirstName + " " + db.Users.Find(tickets.AssignedToUserId).LastName;
                historyHelper.AddHistory(tickets.Id, "Assigned User", oldAssignedUser, newAssignedUser3, User.Identity.GetUserId());
                updateMessage.AppendFormat("Assigned User: {0}, ", newAssignedUser3);
            }
            //Send Notification
            var developer = db.Users.Find(tickets.AssignedToUserId);

            if (developer != null && developer.Email != null)
            {
                var svc = new EmailService();
                var msg = new IdentityMessage();
                msg.Destination = developer.Email;
                msg.Subject     = "Bug Tracker Update: " + tickets.Title + " Assigned";
                msg.Body        = ("The following Ticket ID: " + tickets.Id + " - " + tickets.Title + ": " + updateMessage);
                await svc.SendAsync(msg);
            }



            TicketHistories ticketHistory   = new TicketHistories();
            var             old             = TempData["oldVal"];
            var             owner           = TempData["owner"];
            var             newAssignedUser = db.Users.Find(tickets.AssignedToUserId).FirstName;

            if (ModelState.IsValid)
            {
                ticketHistory.TicketId   = tickets.Id;
                ticketHistory.Property   = "Ticket Assigned";
                ticketHistory.OldValue   = old.ToString();
                ticketHistory.NewValue   = newAssignedUser;
                ticketHistory.UserId     = tickets.OwnerUserId;
                ticketHistory.ChangeDate = tickets.Created;
                ticketHistory.Changed    = true;

                db.TicketHistories.Add(ticketHistory);
                //db.SaveChanges();

                tickets.Updated         = DateTime.Now;
                tickets.OwnerUserId     = owner.ToString();
                tickets.TicketStatusId  = 2;
                db.Entry(tickets).State = EntityState.Modified;
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }
            ViewBag.AssignedToUserId   = new SelectList(db.Users, "Id", "FirstName", tickets.AssignedToUserId);
            ViewBag.OwnerUserId        = new SelectList(db.Users, "Id", "FirstName", tickets.OwnerUserId);
            ViewBag.ProjectId          = new SelectList(db.Projects, "Id", "Name", tickets.ProjectId);
            ViewBag.TicketPrioritiesId = new SelectList(db.TicketPriorities, "Id", "Name", tickets.TicketPrioritiesId);
            ViewBag.TicketStatusId     = new SelectList(db.TicketStatuses, "Id", "Name", tickets.TicketStatusId);
            ViewBag.TicketTypeId       = new SelectList(db.TicketTypes, "Id", "Name", tickets.TicketTypeId);
            return(View(tickets));
        }
Пример #4
0
        public async Task <ActionResult> Edit([Bind(Include = "Id,Title,Description,Created,Updated,ProjectId,TicketTypeId,TicketPrioritiesId,TicketStatusId,OwnerUserID, AssignedToUserId")] Tickets tickets)
        {
            if (ModelState.IsValid)
            {
                //TicketHistories ticketHistory = new TicketHistories();
                HistoryHelper historyHelper = new HistoryHelper();

                StringBuilder updateMessage = new StringBuilder();

                //Old vs new data
                var oldTicketInfo = db.Tickets.AsNoTracking().FirstOrDefault(t => t.Id == tickets.Id);

                if (oldTicketInfo.Title != tickets.Title)
                {
                    historyHelper.AddHistory(tickets.Id, "Title", oldTicketInfo.Title, tickets.Title, User.Identity.GetUserId());
                    updateMessage.AppendFormat("Ticket Title: {0}, ", tickets.Title);
                }

                if (oldTicketInfo.Description != tickets.Description)
                {
                    historyHelper.AddHistory(tickets.Id, "Description", oldTicketInfo.Description, tickets.Description, User.Identity.GetUserId());
                    updateMessage.AppendFormat("Description: {0}, ", tickets.Description);
                }

                if (oldTicketInfo.TicketTypeId != tickets.TicketTypeId)
                {
                    var oldTicketType = db.TicketTypes.Find(oldTicketInfo.TicketTypeId).Name;
                    var newTicketType = db.TicketTypes.Find(tickets.TicketTypeId).Name;
                    historyHelper.AddHistory(tickets.Id, "Ticket Type", oldTicketType, newTicketType, User.Identity.GetUserId());
                    updateMessage.AppendFormat("Ticket Type: {0}, ", newTicketType);
                }

                if (oldTicketInfo.ProjectId != tickets.ProjectId)
                {
                    var oldProject = db.Projects.Find(oldTicketInfo.ProjectId).Name;
                    var newProject = db.Projects.Find(tickets.ProjectId).Name;
                    historyHelper.AddHistory(tickets.Id, "Project Id", oldProject, newProject, User.Identity.GetUserId());
                    updateMessage.AppendFormat("Project: {0}, ", newProject);
                }

                if (oldTicketInfo.TicketPrioritiesId != tickets.TicketPrioritiesId)
                {
                    var oldPriority = db.TicketPriorities.Find(oldTicketInfo.TicketPrioritiesId).Name;
                    var newPriority = db.TicketPriorities.Find(tickets.TicketPrioritiesId).Name;
                    historyHelper.AddHistory(tickets.Id, "Priority", oldPriority, newPriority, User.Identity.GetUserId());
                    updateMessage.AppendFormat("Ticket Priority: {0}, ", newPriority);
                }

                if (oldTicketInfo.TicketStatusId != tickets.TicketStatusId)
                {
                    var oldStatus = db.TicketStatuses.Find(oldTicketInfo.TicketStatusId).Name;
                    var newStatus = db.TicketStatuses.Find(tickets.TicketStatusId).Name;
                    historyHelper.AddHistory(tickets.Id, "Ticket Status", oldStatus, newStatus, User.Identity.GetUserId());
                    updateMessage.AppendFormat("Ticket Status: {0}, ", newStatus);
                }

                if (oldTicketInfo.AssignedToUserId != tickets.AssignedToUserId &&
                    oldTicketInfo.AssignedToUserId != null)
                {
                    var oldAssignedUser = db.Users.Find(oldTicketInfo.AssignedToUserId).FirstName + " " + db.Users.Find(tickets.AssignedToUserId).LastName;
                    var newAssignedUser = db.Users.Find(tickets.AssignedToUserId).FirstName + " " + db.Users.Find(tickets.AssignedToUserId).LastName;
                    historyHelper.AddHistory(tickets.Id, "Assigned User", oldAssignedUser, newAssignedUser, User.Identity.GetUserId());
                    updateMessage.AppendFormat("Assigned User: {0}, ", newAssignedUser);
                }

                if (oldTicketInfo.AssignedToUserId == null && oldTicketInfo.AssignedToUserId != tickets.AssignedToUserId)
                {
                    var oldAssignedUser = "******";
                    var newAssignedUser = db.Users.Find(tickets.AssignedToUserId).FirstName + " " + db.Users.Find(tickets.AssignedToUserId).LastName;
                    historyHelper.AddHistory(tickets.Id, "Assigned User", oldAssignedUser, newAssignedUser, User.Identity.GetUserId());
                    updateMessage.AppendFormat("Assigned User: {0}, ", newAssignedUser);
                }

                tickets.Updated = DateTime.Now;
                if (tickets.TicketStatusId == 1)
                {
                    tickets.AssignedToUserId = null;
                }
                db.Entry(tickets).State = EntityState.Modified;
                db.SaveChanges();

                //Send Notification
                var developer = db.Users.Find(tickets.AssignedToUserId);
                if (developer != null && developer.Email != null)
                {
                    var svc = new EmailService();
                    var msg = new IdentityMessage();
                    msg.Destination = developer.Email;
                    msg.Subject     = "Bug Tracker Update: " + tickets.Title;
                    msg.Body        = ("The following changes have been made to Ticket ID: " + tickets.Id + " - " + tickets.Title + ": " + updateMessage);
                    await svc.SendAsync(msg);
                }

                {
                    return(RedirectToAction("Index"));
                }
            }
            ViewBag.AssignedToUserId = new SelectList(db.Users, "Id", "FirstName", tickets.AssignedToUserId);
            ViewBag.OwnerUserId      = new SelectList(db.Users, "Id", "FirstName", tickets.OwnerUserId);
            ViewBag.ProjectId        = new SelectList(db.Projects, "Id", "Name", tickets.ProjectId);
            ViewBag.TicketPriorityId = new SelectList(db.TicketPriorities, "Id", "Name", tickets.TicketPrioritiesId);
            ViewBag.TicketStatusId   = new SelectList(db.TicketStatuses, "Id", "Name", tickets.TicketStatusId);
            ViewBag.TicketTypeId     = new SelectList(db.TicketTypes, "Id", "Name", tickets.TicketTypeId);
            return(View(tickets));
        }
Пример #5
0
        public async Task <ActionResult> Edit([Bind(Include = "Id,title,description,Created,Updated,ProjectId,TicketPriorityId,TicketStatusId,TicketTypeId,OwnerUserId,AssignedToUserId")] Ticket ticket)
        {
            if (ModelState.IsValid)
            {
                // begin update history section
                var oldTicketInfo = db.Tickets.AsNoTracking().FirstOrDefault(t => t.Id == ticket.Id);

                string notificationString = ""; // string to hold notifications

                // update db
                ticket.Updated = DateTime.Now;
                if (ticket.TicketStatusId == 1)
                {
                    ticket.AssignedToUserId = null;
                }


                if (oldTicketInfo.title != ticket.title)
                {
                    historyHelper.AddHistory(ticket.Id, "Title", oldTicketInfo.title, ticket.title, User.Identity.GetUserId());
                    sb.AppendFormat("Ticket Title: changed from {0} to {1} <br />", oldTicketInfo.title, ticket.title);
                }

                if (oldTicketInfo.description != ticket.description)
                {
                    historyHelper.AddHistory(ticket.Id, "Description", oldTicketInfo.description, ticket.description, User.Identity.GetUserId());
                    sb.AppendFormat("Description: changed from {0} to {1} <br />", oldTicketInfo.description, ticket.description);
                }

                if (oldTicketInfo.AssignedToUserId != ticket.AssignedToUserId &&
                    oldTicketInfo.AssignedToUserId != null)
                {
                    var oldAssignedUser = db.Users.Find(oldTicketInfo.AssignedToUserId).FirstName
                                          + " " + db.Users.Find(ticket.AssignedToUserId).LastName;
                    var newAssignedUser = db.Users.Find(ticket.AssignedToUserId).FirstName
                                          + " " + db.Users.Find(ticket.AssignedToUserId).LastName;
                    historyHelper.AddHistory(ticket.Id, "Assigned User", oldAssignedUser, newAssignedUser, User.Identity.GetUserId());
                }

                if (oldTicketInfo.AssignedToUserId == null && oldTicketInfo.AssignedToUserId != ticket.AssignedToUserId)
                {
                    var oldAssignedUser = "******";
                    var newAssignedUser = db.Users.Find(ticket.AssignedToUserId).FirstName
                                          + " " + db.Users.Find(ticket.AssignedToUserId).LastName;
                    historyHelper.AddHistory(ticket.Id, "Assigned User", oldAssignedUser, newAssignedUser, User.Identity.GetUserId());
                }

                if (oldTicketInfo.ProjectId != ticket.ProjectId)
                {
                    var oldProject = db.Projects.Find(oldTicketInfo.ProjectId).Name;
                    var newProject = db.Projects.Find(ticket.ProjectId).Name;
                    historyHelper.AddHistory(ticket.Id, "Project", oldProject, newProject, User.Identity.GetUserId());
                    sb.AppendFormat("Project: changed from {0} to {1} <br />", oldProject, newProject);
                }

                if (oldTicketInfo.TicketPriorityId != ticket.TicketPriorityId)
                {
                    var oldPriority = db.TicketPriorities.Find(oldTicketInfo.TicketPriorityId).Name;
                    var newPriority = db.TicketPriorities.Find(ticket.TicketPriorityId).Name;
                    historyHelper.AddHistory(ticket.Id, "Priority", oldPriority, newPriority, User.Identity.GetUserId());
                    sb.AppendFormat("Priority: changed from {0} to {1} <br />", oldPriority, newPriority);
                }

                if (oldTicketInfo.TicketStatusId != ticket.TicketStatusId)
                {
                    var oldStatus = db.TicketStatuses.Find(oldTicketInfo.TicketStatusId).Name;
                    var newStatus = db.TicketStatuses.Find(ticket.TicketStatusId).Name;
                    historyHelper.AddHistory(ticket.Id, "Status", oldStatus, newStatus, User.Identity.GetUserId());
                    sb.AppendFormat("Status: changed from {0} to {1} <br />", oldStatus, newStatus);
                }

                if (oldTicketInfo.TicketTypeId != ticket.TicketTypeId)
                {
                    var oldTicketType = db.TicketTypes.Find(oldTicketInfo.TicketTypeId).Name;
                    var newTicketType = db.TicketTypes.Find(ticket.TicketTypeId).Name;
                    historyHelper.AddHistory(ticket.Id, "Ticket Type", oldTicketType, newTicketType, User.Identity.GetUserId());
                    sb.AppendFormat("Type: changed from {0} to {1} <br />", oldTicketType, newTicketType);
                }


                db.Tickets.Attach(ticket);
                db.Entry(ticket).Property("title").IsModified            = true;
                db.Entry(ticket).Property("description").IsModified      = true;
                db.Entry(ticket).Property("Created").IsModified          = false;
                db.Entry(ticket).Property("Updated").IsModified          = true;
                db.Entry(ticket).Property("ProjectId").IsModified        = true;
                db.Entry(ticket).Property("TicketPriorityId").IsModified = true;
                db.Entry(ticket).Property("TicketStatusId").IsModified   = false;
                db.Entry(ticket).Property("TicketTypeId").IsModified     = true;
                db.Entry(ticket).Property("OwnerUserId").IsModified      = false;
                db.Entry(ticket).Property("AssignedToUserId").IsModified = false;
                db.SaveChanges();

                // notification
                var assignedUserId = ticket.AssignedToUserId;
                var editor         = db.Users.Find(User.Identity.GetUserId()).FirstName + " " + db.Users.Find(User.Identity.GetUserId()).LastName;
                if (assignedUserId != null)
                {
                    await notificationHelper.EditNotification(ticket.Id, assignedUserId, sb, editor);
                }

                return(RedirectToAction("Details", "Tickets", new { id = ticket.Id }));
            }

            return(View(ticket));
        }