Пример #1
0
        public ActionResult AddResolution(ResolutionViewModel resolutionVM)
        {
            if (ModelState.IsValid)
            {
                // get the backing ticket
                var ticket = db.Tickets.AsNoTracking().Single(t => t.ID == resolutionVM.TicketID);

                // if ticket already has a resolution then do nothing and redirect to details
                var HasResolution = !(ticket.Resolution == null || ticket.Resolution == "");
                if (HasResolution)
                {
                    return(RedirectToAction("Details", new { id = resolutionVM.TicketID }));
                }

                // get the user's id for the history
                var userName = HttpContext.User.Identity.Name;
                var userID   = db.Users.Single(u => u.ASPUserName == userName).ID;

                // this should add the resolutino and update the status to RESOLVED.
                ticket.Resolution     = resolutionVM.resolutionText;
                ticket.TicketStatusID = db.TicketStatuses.Single(s => s.Status == "Resolved").ID;


                // update ticket and history
                HistoryUtilities.UpdateTicketAndLog(ticket, userID);

                // return to the details page of the ticket
                return(RedirectToAction("Details", new { id = resolutionVM.TicketID }));
            }

            // model wasn't valid, return it for fixing.
            ViewBag.TicketID = resolutionVM.TicketID;
            return(View(resolutionVM));
        }
Пример #2
0
        public ActionResult Edit(TicketViewModel ticketVM)
        {
            // create ticket from ticketViewmodel
            Ticket ticket = new Ticket(ticketVM);

            // check your inputs
            if (ModelState.IsValid)
            {
                //db.Entry(ticket).State = EntityState.Modified;
                //await db.SaveChangesAsync();

                var currentUser = HttpContext.User.Identity.Name;
                var userID      = db.Users.Single(u => u.ASPUserName == currentUser).ID;

                // save and update history
                HistoryUtilities.UpdateTicketAndLog(ticket, userID);


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

            ViewBag.ProjectID        = new SelectList(db.Projects, "ID", "ProjectName", ticket.ProjectID);
            ViewBag.TicketPriorityID = new SelectList(db.TicketPriorities, "ID", "Priority", ticket.TicketPriorityID);
            ViewBag.TicketStatusID   = new SelectList(db.TicketStatuses, "ID", "Status", ticket.TicketStatusID);
            ViewBag.TicketTypeID     = new SelectList(db.TicketTypes, "ID", "Type", ticket.TicketTypeID);
            ViewBag.RelatedTicketID  = new SelectList(db.Tickets, "ID", "Title", ticket.RelatedTicketID);

            // fix the view to display info on the tickets using the ticket1 item.
            // and disable fields that shouldn't be edited.
            var aspUserDb      = new ApplicationDbContext();
            var developerRole  = aspUserDb.Roles.Single(r => r.Name == "Developer");
            var listOfDevNames = aspUserDb.Users.Where(u => u.Roles.Any(r => r.RoleId == developerRole.Id)).Select(u => u.UserName).ToList();
            var allDevelopers  = db.Users.Where(u => listOfDevNames.Any(d => d == u.ASPUserName));

            // Limit Items in the Submitter to just the submitter!
            ViewBag.TicketSubmitterID = new SelectList(db.Users.Where(u => u.ID == ticket.TicketSubmitterID), "ID", "ASPUserName", ticket.TicketSubmitterID);
            ViewBag.AssignedToID      = new SelectList(allDevelopers, "ID", "ASPUserName", ticket.AssignedToID);
            return(View(ticket));
        }