Beispiel #1
0
        public ActionResult BulkAssign(int Id, List <PMAssignUsersTicketVM> model, string selector1)
        {
            //HelperMethod for Histories/Notifications
            var ticketCustomHelper = new TicketCustomHelper();

            var selectedTickets = model.Where(m => m.IsChecked == true);
            var project         = db.Projects.Find(Id);
            var currentUser     = db.Users.Find(User.Identity.GetUserId());
            var selectedUser    = db.Users.Find(selector1);
            var timeStamp       = DateTimeOffset.UtcNow;

            if (User.IsInRole("DemoAcc") || selectedTickets == null || currentUser == null)
            {
                return(RedirectToAction("PMDashboard", "BT"));
            }

            if (project.Users.Contains(currentUser))
            {
                foreach (var item in selectedTickets)
                {
                    var currentTicket = db.TicketPosts.FirstOrDefault(t => t.Id == item.TicketId);
                    var editedTicket  = db.TicketPosts.AsNoTracking().FirstOrDefault(t => t.Id == item.TicketId);
                    editedTicket.AssignedToUserID = selectedUser.Id;

                    //Create Ticket Assignment History, Create Ticket Assignment Notifications
                    ticketCustomHelper.AssignmentHistory(currentTicket, editedTicket, timeStamp, currentUser, "Assignment"); //History
                    ticketCustomHelper.AssignmentNotification(currentTicket, editedTicket, timeStamp, currentUser);          //Notification

                    //Set ticket property changes/updates
                    db.TicketPosts.Attach(currentTicket);
                    currentTicket.AssignedToUserID = selectedUser.Id;
                    currentTicket.UpdatedByUserID  = currentUser.Id;
                    currentTicket.Updated          = timeStamp;
                    db.SaveChanges();
                }
            }

            return(RedirectToAction("PMDashboard", "BT"));
        }
Beispiel #2
0
        public ActionResult EditTicketForm([Bind(Include = "Id,Created,Updated,Title,Description,ProjectID,TicketStatusID,TicketTypeID,TicketPriorityID,OwnerUserID,AssignedToUserID")] TicketPost ticketPost)
        {
            if (ModelState.IsValid)
            {
                //HelperMethod for Histories/Notifications
                var ticketCustomHelper = new TicketCustomHelper();

                var currentTicket          = db.TicketPosts.Find(ticketPost.Id);       //Current Ticket from the database.
                var editedTicket           = ticketPost;                               //Changes that were submitted through Form Post
                var allUsers               = db.Users;
                var ticketEditor           = db.Users.Find(User.Identity.GetUserId()); //User that edited the ticket
                var ticketUpdatedTimeStamp = DateTimeOffset.UtcNow;                    //Used so ticket updated-date/history-time/notificaiton-time
                var changesMade            = false;                                    //is used to control one final saved of all ticket edits
                var updateNoftication      = false;                                    //is used to control & send one generic edit message
                db.TicketPosts.Attach(currentTicket);                                  //Sets currentTicket ready for changes.

                //####Start Access Control Section####
                var allowed = false;//Controls Access
                if (User.IsInRole("Admin"))
                {
                    allowed = true;
                }
                else if (User.IsInRole("Project Manager") && currentTicket.Project.Users.Contains(ticketEditor))
                {
                    allowed = true;
                }
                else if (User.IsInRole("Developer") && currentTicket.AssignedToUser != null)
                {
                    if (currentTicket.AssignedToUser == ticketEditor)
                    {
                        allowed = true;
                    }
                }
                else if (User.IsInRole("Submitter") && currentTicket.OwnerUser == ticketEditor)
                {
                    allowed = true;
                }
                if (User.IsInRole("DemoAcc"))
                {
                    allowed = false;
                }
                //####End Access Control Section####

                //ONLY Editable Items   - Details/Overview of each section.
                //  AssignedToUserID    - PM Only, Creates History Entry, Sends Notification to new asignee & old assignee.
                //  TicketPriorityID    -  Creates History Entry, Sends generic Notification
                //  TicketTypeID        -  Creates History Entry, Sends generic Notification
                //  TicketStatusID      -  Creates History Entry, Sends generic Notification
                //  Description         -  Creates History Entry, Sends generic Notification
                //  Title               -  Creates History Entry, Sends generic Notification

                if (allowed)
                {
                    if (currentTicket.AssignedToUserID != editedTicket.AssignedToUserID && User.IsInRole("Project Manager"))
                    {
                        //Create Ticket Assignment History, Create Ticket Assignment Notifications, Set ticket property change
                        ticketCustomHelper.AssignmentHistory(currentTicket, editedTicket, ticketUpdatedTimeStamp, ticketEditor, "Assignment"); //History
                        ticketCustomHelper.AssignmentNotification(currentTicket, editedTicket, ticketUpdatedTimeStamp, ticketEditor);          //Notification
                        currentTicket.AssignedToUserID = editedTicket.AssignedToUserID;                                                        //set ticket edit change
                        changesMade = true;
                    }

                    if (currentTicket.TicketPriorityID != editedTicket.TicketPriorityID)
                    {
                        //Create Ticket History, Set Ticket Edit Change
                        var editedPropertyName = ticketCustomHelper.GetPriorityName(editedTicket.TicketPriorityID); //Get ticket priority name
                        ticketCustomHelper.GenericHistory(currentTicket, currentTicket.TicketPriority.Name, editedPropertyName, ticketUpdatedTimeStamp, ticketEditor, "Ticket Priority");
                        currentTicket.TicketPriorityID = editedTicket.TicketPriorityID;                             //Set Ticket Edit Change
                        changesMade       = true;
                        updateNoftication = true;
                    }
                    if (currentTicket.TicketTypeID != editedTicket.TicketTypeID)
                    {
                        //Create Ticket History, Set Ticket Edit Change
                        var editedPropertyName = ticketCustomHelper.GetTypeName(editedTicket.TicketTypeID);                                                                       //Get ticket type name
                        ticketCustomHelper.GenericHistory(currentTicket, currentTicket.TicketType.Name, editedPropertyName, ticketUpdatedTimeStamp, ticketEditor, "Ticket Type"); //History
                        currentTicket.TicketTypeID = editedTicket.TicketTypeID;                                                                                                   //Set Ticket Edit Change
                        changesMade       = true;
                        updateNoftication = true;
                    }
                    if (currentTicket.TicketStatusID != editedTicket.TicketStatusID)
                    {
                        //Create Ticket History, Set Ticket Edit Change
                        var editedPropertyName = ticketCustomHelper.GetStatusName(editedTicket.TicketStatusID);                                                                       //Get ticket priority name
                        ticketCustomHelper.GenericHistory(currentTicket, currentTicket.TicketStatus.Name, editedPropertyName, ticketUpdatedTimeStamp, ticketEditor, "Ticket Status"); //History
                        currentTicket.TicketStatusID = editedTicket.TicketStatusID;                                                                                                   //Set Ticket Edit Change
                        changesMade       = true;
                        updateNoftication = true;
                    }
                    if (currentTicket.Description != editedTicket.Description)
                    {
                        //Create Ticket History, Set Ticket Edit Change
                        ticketCustomHelper.GenericHistory(currentTicket, currentTicket.Description, editedTicket.Description, ticketUpdatedTimeStamp, ticketEditor, "Ticket Description"); //History
                        currentTicket.Description = editedTicket.Description;                                                                                                              //Set Ticket Edit Change
                        changesMade       = true;
                        updateNoftication = true;
                    }
                    if (currentTicket.Title != editedTicket.Title)
                    {
                        //Create Ticket History, Set Ticket Edit Change
                        ticketCustomHelper.GenericHistory(currentTicket, currentTicket.Title, editedTicket.Title, ticketUpdatedTimeStamp, ticketEditor, "Ticket Title"); //History
                        currentTicket.Title = editedTicket.Title;                                                                                                        //Set Ticket Edit Change
                        changesMade         = true;
                        updateNoftication   = true;
                    }

                    if (changesMade)
                    {
                        //Sends Nofitication to Ticket Asignee. (Not when Assignee is changed)
                        //(Nofication for Asignee change is sent in the Assignment section above)
                        if (updateNoftication)
                        {
                            ticketCustomHelper.GenericTicketChangeNotification(currentTicket.AssignedToUserID, ticketEditor, currentTicket.Id, ticketUpdatedTimeStamp);
                        }
                        //Set time/editor, and save changes.
                        currentTicket.UpdatedByUserID = ticketEditor.Id;
                        currentTicket.Updated         = ticketUpdatedTimeStamp;
                        db.SaveChanges();
                    }
                    return(RedirectToAction("Ticket", "BT", new { id = currentTicket.Id }));
                }
                if (allowed == false)
                {
                    string errcode = User.Identity.Name + " Permission not granted, TicketEditForm, Ticket: " + currentTicket.Id;
                    return(RedirectToAction("Err403", "BT", new { errcode = errcode }));
                }
            }

            return(RedirectToAction("Ticket", "BT", new { id = ticketPost.Id }));
        }