예제 #1
0
        public ActionResult Details(int?id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }

            // TempData["UserPreferences"] is read in at Start of Action
            var userPref = (UserPreferencesViewModel)TempData["UserPreferences"];

            Ticket ticket = db.Tickets.Find(id);

            if (ticket == null)
            {
                return(HttpNotFound());
            }

            var myUserId = User.Identity.GetUserId();

            bool mySubTicket = false;

            if (User.IsInRole("Submitter") && (ticket.OwnerUserId == myUserId))
            {
                mySubTicket       = true;
                ViewBag.MyEditSub = mySubTicket;
            }

            bool myDevTicket = false;

            if (User.IsInRole("Developer") && (ticket.AssignedToUserId == myUserId))
            {
                myDevTicket       = true;
                ViewBag.MyEditDev = myDevTicket;
            }

            bool myPMTicket = false;

            if (User.IsInRole("ProjectManager"))
            {
                ProjectAssignHelper projecthelper = new ProjectAssignHelper();
                myPMTicket        = projecthelper.IsUserTheProjectManager(myUserId, ticket.ProjectId);
                ViewBag.MyEditSub = myPMTicket;
            }

            ViewBag.MyEditTicket = false;
            if (User.IsInRole("Admin") || myPMTicket == true || myDevTicket == true || mySubTicket == true)
            {
                ViewBag.MyEditTicket = true;
            }

            // TempData["UserPreferences"] is rewritten at End of Action
            TempData["UserPreferences"] = userPref;

            ViewBag.FilterByTickets = userPref.FilterByTickets;
            ViewBag.FilterByStatus  = userPref.FilterByStatus;

            return(View(ticket));
        }
예제 #2
0
        public ActionResult Edit(int?id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }

            // TempData["UserPreferences"] is read in at Start of Action
            var userPref = (UserPreferencesViewModel)TempData["UserPreferences"];

            Ticket ticket = db.Tickets.Find(id);

            if (ticket == null)
            {
                return(HttpNotFound());
            }

            var devRoleId        = db.Roles.First(r => r.Name == "Developer").Id;
            var projectuserslist = projecthelper.ListUsersOnProject(ticket.ProjectId).Where(p => p.Roles.Any(d => d.RoleId == devRoleId));

            ViewBag.AssignedToUserId = new SelectList(projectuserslist, "Id", "DisplayName", ticket.AssignedToUserId);

            /* SelectList(IEnumerable, String, String, Object)
             * Initializes a new instance of the SelectList class by using the specified items for the list,
             * the data value field, the data text field, and a selected value. */

            ViewBag.ProjectId        = new SelectList(db.Projects, "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);
            ViewBag.OwnerUserId      = new SelectList(db.Users, "Id", "DisplayName", ticket.OwnerUserId);

            var myUserId = User.Identity.GetUserId();

            bool mySubTicket = false;

            if (User.IsInRole("Submitter") && (ticket.OwnerUserId == myUserId))
            {
                mySubTicket       = true;
                ViewBag.MyEditSub = mySubTicket;
            }

            bool myDevTicket = false;

            if (User.IsInRole("Developer") && (ticket.AssignedToUserId == myUserId))
            {
                myDevTicket       = true;
                ViewBag.MyEditSub = myDevTicket;
            }

            bool myPMTicket = false;

            if (User.IsInRole("ProjectManager"))
            {
                ProjectAssignHelper projecthelper = new ProjectAssignHelper();
                myPMTicket        = projecthelper.IsUserTheProjectManager(myUserId, ticket.ProjectId);
                ViewBag.MyEditSub = myPMTicket;
            }

            ViewBag.MyEditTicket = false;
            if (User.IsInRole("Admin") || myPMTicket == true || myDevTicket == true || mySubTicket == true)
            {
                ViewBag.MyEditTicket = true;
            }

            // TempData["UserPreferences"] is rewritten at End of Action
            TempData["UserPreferences"] = userPref;

            ViewBag.FilterByTickets = userPref.FilterByTickets;
            ViewBag.FilterByStatus  = userPref.FilterByStatus;

            return(View(ticket));
        }