Пример #1
0
        public ActionResult SidebarPartial2()
        {
            var currentuser = db.Users.Find(User.Identity.GetUserId());

            if (currentuser != null)
            {
                ProjectAssignHelper ph = new ProjectAssignHelper();
                UserRolesHelper     uh = new UserRolesHelper(db);
                UsersRolesViewModel vm = new UsersRolesViewModel();
                var userId             = User.Identity.GetUserId();
                var user = db.Users.Find(userId);
                vm.User  = db.Users.Find(User.Identity.GetUserId());
                vm.Roles = uh.ListUserRoles(vm.User.Id);
                if (uh.IsUserInRole(userId, "Admin") || uh.IsUserInRole(userId, "Administrator") || uh.IsUserInRole(userId, "Project Manager1") || uh.IsUserInRole(userId, "Project Manager2") || uh.IsUserInRole(userId, "Project Manager3"))
                {
                    vm.Projectsb = db.Projects.ToList();
                }
                else
                {
                    vm.Projectsb = ph.ListProjectsForAUser(userId);
                }

                return(PartialView("~/Areas/BugTracker/Views/Projects/_SidebarPartial2.cshtml", vm));
            }
            return(RedirectToAction("Index", "Home"));
        }
Пример #2
0
        //GET
        public ActionResult Details(string Id)


        {
            ProjectAssignHelper ph = new ProjectAssignHelper();
            UserRolesHelper     UH = new UserRolesHelper(db);
            var userId             = User.Identity.GetUserId();
            var user = db.Users.Find(userId);

            if (UH.IsUserInRole(userId, "Admin") || UH.IsUserInRole(userId, "Administrator") || userId == Id)
            {
                if (Id != null)
                {
                    UsersRolesViewModel userRoleViewModel2 = new UsersRolesViewModel();
                    userRoleViewModel2.User      = db.Users.Find(Id);
                    userRoleViewModel2.Roles     = helper.ListUserRoles(Id);
                    userRoleViewModel2.Tickets   = db.Tickets.ToList();
                    userRoleViewModel2.Projectsb = db.Projects.ToList();

                    //userRoleViewModel.Projects = helper.
                    var SubmitterlessRolesList = db.Roles.Where(r => r.Name != "Submitter");
                    ViewBag.Roles = new MultiSelectList(SubmitterlessRolesList, "Name", "Name");

                    //ViewBag.Roles = new MultiSelectList(db.Topics, "Id", "TopicName");

                    return(View(userRoleViewModel2));
                }
                else
                {
                    UsersRolesViewModel userRoleViewModel = new UsersRolesViewModel();
                    userRoleViewModel.User    = db.Users.Find(userId);
                    userRoleViewModel.Roles   = helper.ListUserRoles(userId);
                    userRoleViewModel.Tickets = db.Tickets.ToList();
                    List <Project> UserProjects = new List <Project>();
                    foreach (var project in db.Projects)
                    {
                        if (ph.IsUserOnAProject(userId, project.Id))
                        {
                            UserProjects.Add(project);
                        }
                    }
                    userRoleViewModel.Projectsb = UserProjects;
                    //userRoleViewModel.Projects = helper.
                    var SubmitterlessRolesList = db.Roles.Where(r => r.Name != "Submitter");
                    ViewBag.Roles = new MultiSelectList(SubmitterlessRolesList, "Name", "Name");

                    //ViewBag.Roles = new MultiSelectList(db.Topics, "Id", "TopicName");

                    return(View(userRoleViewModel));
                }
            }
            var Temporary = "You cannot view Details of this User.  Please revisit your role assignment.  You may view your own user details, but other user's details can only be viewed by Administrators. ";

            TempData["message"] = Temporary;
            return(RedirectToAction("Index", "Users"));
        }
Пример #3
0
        // GET: Projects
        public ActionResult Index()
        {
            var myUserId      = User.Identity.GetUserId();
            var myProjects    = new List <Project>();
            var myProjectsVMs = new List <ProjectVM>();

            ViewBag.CardTitle = "My Projects";


            if (roleHelper.IsUserInRole(myUserId, "ProjectManager"))
            {
                myProjects = db.Projects.Where(p => p.ProjectManagerId == myUserId).ToList();
            }
            else
            {
                myProjects = projHelper.ListUserProjects(myUserId).ToList();
            }

            foreach (var project in myProjects)
            {
                myProjectsVMs.Add(new ProjectVM
                {
                    id          = project.Id,
                    name        = project.Name,
                    pmId        = project.ProjectManagerId,
                    pmName      = project.ProjectManagerId != null ? db.Users.Find(project.ProjectManagerId).Fullname : "Unassigned",
                    description = project.Description
                });
            }

            return(View(myProjectsVMs));
        }
Пример #4
0
        public ActionResult Leaving()
        {
            var userId    = User.Identity.GetUserId();
            var user      = db.Users.Find(userId);
            var household = db.Households.Find(user.HouseholdId);

            if (User.IsInRole("User"))
            {
                userRolesHelper.RemoveUserFromRole(userId, "User");
                user.HouseholdId = null;

                db.SaveChanges();
            }

            if (userRolesHelper.IsUserInRole(userId, "HoH"))
            {
                if (HouseholdHelper.AnyUsersInHousehold(household.Id))
                {
                    HouseholdHelper.AssignRandomHoH(household.Id);
                }

                userRolesHelper.RemoveUserFromRole(userId, "HoH");
                user.HouseholdId = null;

                db.Households.Remove(household);
                db.SaveChanges();
            }

            return(RedirectToAction("Index", "Home"));
        }
        public ActionResult AssignUser(int?id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            Ticket ticket = db.Tickets.Find(id);

            if (ticket == null)
            {
                return(HttpNotFound());
            }
            AssignTicketUserViewModel AssignModel = new AssignTicketUserViewModel();

            AssignModel.TicketId    = ticket.Id;
            AssignModel.TicketTitle = ticket.Title;
            ProjectUsersHelper helper     = new ProjectUsersHelper(db);
            UserRolesHelper    userHelper = new UserRolesHelper(db);
            var projectUsers      = helper.ListUsers(ticket.ProjectId);
            var projectDevelopers = new List <ApplicationUser>();

            foreach (var user in projectUsers)
            {
                if (userHelper.IsUserInRole(user.Id, "Developer"))
                {
                    projectDevelopers.Add(user);
                }
            }
            if (ticket.Assignee != null)
            {
                AssignModel.TicketAssignedTo = ticket.Assignee.FullName;
            }
            AssignModel.UsersList = new SelectList(projectDevelopers, "Id", "FullName");
            return(View(AssignModel));
        }
Пример #6
0
        public ActionResult Edit(int?id)
        {
            var developers = new List <ApplicationUser>();

            //Get the project for this Ticket
            foreach (var user in projhelp.UsersOnProject(db.Tickets.Find(id).ProjectID).ToList())
            {
                if (helprole.IsUserInRole(user.Id, "Developer"))
                {
                    developers.Add(user);
                }
            }

            //Get all Developers on the Project


            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            Ticket ticket  = db.Tickets.Find(id);
            var    project = ticket.ProjectID;

            if (ticket == null)
            {
                return(HttpNotFound());
            }
            ViewBag.AssignedToUserID = new SelectList(developers, "ID", "FirstName", ticket.AssignedToUserID);
            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.TicketStatus, "ID", "Name", ticket.TicketStatusID);
            ViewBag.TicketTypeID     = new SelectList(db.TicketTypes, "ID", "Name", ticket.TicketTypeID);
            return(View(ticket));
        }
Пример #7
0
        public ActionResult RoleAssignment(string UserId, string RoleId, bool Delete)
        {
            if (string.IsNullOrEmpty(UserId) || string.IsNullOrEmpty(RoleId))
            {
                return(View());
            }

            if (Delete)
            {
                foreach (var role in UserRolesHelper.ListUserRoles(UserId))
                {
                    UserRolesHelper.RemoveUserFromRole(UserId, role);
                }

                return(RedirectToAction("RoleAssignment"));
            }

            if (UserRolesHelper.IsUserInRole(UserId, RoleId))
            {
                return(RedirectToAction("RoleAssignment"));
            }

            UserRolesHelper.AddUserToRole(UserId, RoleId);

            return(RedirectToAction("RoleAssignment"));
        }
Пример #8
0
        // GET: Projects/Edit/5
        public ActionResult Edit(int?id)
        {
            UserRolesHelper     helper = new UserRolesHelper(db);
            ProjectAssignHelper ph     = new ProjectAssignHelper();

            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            Project project = db.Projects.Find(id);

            if (project == null)
            {
                return(HttpNotFound());
            }
            if (!helper.IsUserInRole(User.Identity.GetUserId(), "Administrator") || !helper.IsUserInRole(User.Identity.GetUserId(), "Admin") || !helper.IsUserInRole(User.Identity.GetUserId(), "Project Manager1") || !helper.IsUserInRole(User.Identity.GetUserId(), "Project Manager2") || !helper.IsUserInRole(User.Identity.GetUserId(), "Project Manager3"))
            {
                if (!db.Users.Find(User.Identity.GetUserId()).Projects.Contains(project))
                {
                    return(RedirectToAction("Index"));
                }
            }
            List <ApplicationUser> PMList = new List <ApplicationUser>();

            var PM1 = helper.UsersInRole("Project Manager1");
            var PM2 = helper.UsersInRole("Project Manager2");
            var PM3 = helper.UsersInRole("Project Manager3");

            PM1.Concat(PM2).Concat(PM3);
            List <string> Statuses = new List <string>();

            foreach (var statusname in db.Projects)
            {
                if (!Statuses.Contains(statusname.ProjectStatus))
                {
                    Statuses.Add(statusname.ProjectStatus);
                }
            }


            ViewBag.ProjectStatusId  = new SelectList(db.ProjectStatuses, "Id", "Name");
            ViewBag.ProjectManagerId = new SelectList(PM1, "Id", "FirstName");

            return(View(project));
        }
Пример #9
0
        public ActionResult FixProfilePictures()
        {
            var users = db.Users;

            foreach (var user in users)
            {
                if (roleHelper.IsUserInRole(user.Id, "Developer"))
                {
                    user.AvatarPath = "img/devprofilepic.png";
                    db.Users.Attach(user);
                    db.Entry(user).Property(u => u.AvatarPath).IsModified = true;
                }
                else if (roleHelper.IsUserInRole(user.Id, "Project Manager"))
                {
                    user.AvatarPath = "img/pmprofilepic.png";
                    db.Users.Attach(user);
                    db.Entry(user).Property(u => u.AvatarPath).IsModified = true;
                }
                else if (roleHelper.IsUserInRole(user.Id, "Submitter"))
                {
                    user.AvatarPath = "img/subprofilepic.png";
                    db.Users.Attach(user);
                    db.Entry(user).Property(u => u.AvatarPath).IsModified = true;
                }
                else if (roleHelper.IsUserInRole(user.Id, "Admin"))
                {
                    user.AvatarPath = "img/adminprofilepic.png";
                    db.Users.Attach(user);
                    db.Entry(user).Property(u => u.AvatarPath).IsModified = true;
                }
                else if (user.AvatarPath == null)
                {
                    user.AvatarPath = "img/defaultprofilepic.jpg";
                    db.Users.Attach(user);
                    db.Entry(user).Property(u => u.AvatarPath).IsModified = true;
                }
            }
            db.SaveChanges();
            TempData["Message"] = "Null Profile Images replaced with Default Image!";
            return(RedirectToAction("Index", "Users"));
        }
        public ActionResult Edit(int?id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            Project project = db.Projects.Find(id);

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

            if (projHelper.IsUserOnProject(User.Identity.GetUserId(), project.Id) || User.IsInRole("Admin"))
            {
                //var projectManager = UserRolesHelper.UsersInRole("Project Manager");
                //ViewBag.ProjectManager = new SelectList(projectManager, "Id", "DisplayName");
                var projUsers = projHelper.UsersOnProject(id ?? 0);

                string        assignedPM   = "";
                string        assignedSub  = "";
                List <string> assignedDevs = new List <string>();

                var pms = roleHelper.UsersInRole("Project Manager");
                foreach (var user in projUsers)
                {
                    if (roleHelper.IsUserInRole(user.Id, "Project Manager"))
                    {
                        assignedPM = user.Id;
                    }
                }
                ViewBag.ProjectManager = new SelectList(pms, "Id", "Email", assignedPM);

                var subs = roleHelper.UsersInRole("Submitter");
                foreach (var user in projUsers)
                {
                    if (roleHelper.IsUserInRole(user.Id, "Submitter"))
                    {
                        assignedSub = user.Id;
                    }
                }
                ViewBag.Submitter = new SelectList(subs, "Id", "Email", assignedSub);

                var devs = roleHelper.UsersInRole("Developer");
                foreach (var user in projUsers)
                {
                    if (roleHelper.IsUserInRole(user.Id, "Developer"))
                    {
                        assignedDevs.Add(user.Id);
                    }
                }
                ViewBag.Developers = new MultiSelectList(devs, "Id", "Email", assignedDevs);

                ViewBag.ProjectStat = new SelectList(db.ProjectStatuses.Where(s => s.Status != "New").Where(s => s.Status != "Past Due!"), "Id", "Status");

                return(View(project));
            }

            return(RedirectToAction("InvalidAttempt", "Home"));
        }
Пример #11
0
        public ActionResult EditUserRoles(/*[Bind(Include = "User, Roles, SelectedRoles, Id, Name")]*/ AdminUserViewModel AdminUserViewModel)
        {
            UserRolesHelper helper            = new UserRolesHelper(db);
            string          userId            = AdminUserViewModel.Id;
            var             editedUserAccount = db.Users.Find(userId);
            var             currentUser       = db.Users.Find(User.Identity.GetUserId());

            if (User.IsInRole("DemoAcc"))
            {
                string errcode = User.Identity.Name + " Permission not granted, EditUserRoles, Edited User: "******"Err403", "BT", new { errcode = errcode }));
            }
            if (ModelState.IsValid)
            {
                var      selectedRoleList = AdminUserViewModel.SelectedRoles;
                string[] currentRoleList  = helper.ListUserRoles(userId).ToArray();
                int      counter          = 0; //Counter for currentRoleList.
                                               //Spins through currentRoleList and removes roles that are nolonger selected
                foreach (var item in currentRoleList)
                {
                    bool present  = false;
                    int  counter2 = 0;   //Counter for SelectedRolesList
                    while (present == false && counter2 < selectedRoleList.Length)
                    {
                        if (currentRoleList[counter] == selectedRoleList[counter2])
                        {
                            present = true;
                        }
                        counter2++;
                        if (present == false && counter2 == selectedRoleList.Length)
                        {
                            helper.RemoveUserFromRole(userId, currentRoleList[counter]);
                        }
                    }
                    counter++;
                }
                counter = 0;
                //Adds only roles that were selected.
                foreach (var item in selectedRoleList)
                {
                    string toBeAdded = selectedRoleList[counter];
                    if (!helper.IsUserInRole(userId, toBeAdded))
                    {
                        var result = helper.AddUserToRole(userId, toBeAdded);
                    }
                    counter += 1;
                }
                return(RedirectToAction("EditUserRoles", "Admin", userId));
            }

            return(RedirectToAction("EditUserRoles", "Admin", userId));
        }
Пример #12
0
        // GET: Tickets/Details/5
        public ActionResult Details(int?id)
        {
            var userId = User.Identity.GetUserId();

            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            Ticket ticket = db.Tickets.Find(id);

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

            var project    = ticket.Project;
            var pms        = roleHelper.UsersInRole("Project Manager");
            var assignedPM = "";
            var pmId       = "";

            foreach (var user in ticket.Project.Users)
            {
                if (roleHelper.IsUserInRole(user.Id, "Project Manager"))
                {
                    assignedPM = user.FullName;
                    pmId       = user.Id;
                }
            }
            ViewBag.ProjectManagerName = assignedPM;
            var priorities      = db.Priorities;
            var currentPriority = ticket.PriorityId;

            ViewBag.Priorities = new SelectList(priorities, "Id", "Name", currentPriority);
            var statuses      = db.Statuses.Where(s => s.Name != "Unassigned");
            var currentStatus = ticket.StatusId;

            ViewBag.Statuses = new SelectList(statuses, "Id", "Name", currentStatus);
            var types       = db.Types;
            var currentType = ticket.TypeId;

            ViewBag.Types = new SelectList(types, "Id", "Name", currentType);
            if (User.IsInRole("Admin") || userId == pmId || userId == ticket.AssignedUserId || userId == ticket.OwnerUserId)
            {
                return(View(ticket));
            }
            else
            {
                return(RedirectToAction("Index", "Profile"));
            }
        }
Пример #13
0
        public ActionResult Edit(int?id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }

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

            var userId = User.Identity.GetUserId();

            //This is usually a students first attempt at kicking people out that are not suppose to be editing
            // see who this is and compare it with the owner user id or assigned to user id and then kick them out if they dont match.
            if ((User.IsInRole("Submitter") && ticket.OwnerUserId != userId) ||
                (User.IsInRole("Developer") && ticket.AssignedToUserId != userId))
            {
                return(RedirectToAction("UnauthorizedTicketEdit", "Admin", new { id = ticket.Id }));
            }



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

            var developers     = new List <ApplicationUser>();
            var usersOnProject = projectHelper.UsersOnProject(ticket.ProjectId);

            foreach (var user in usersOnProject)
            {
                if (roleHelper.IsUserInRole(user.Id, "Developer"))
                {
                    developers.Add(user);
                }
            }



            if (User.IsInRole("Admin") || User.IsInRole("ProjectManager"))
            {
                ViewBag.AssignedToUserId = new SelectList(developers, "Id", "Email", ticket.AssignedToUserId);
            }

            ViewBag.ProjectId        = new SelectList(projectHelper.ListUserProjects(userId), "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));
        }
        public ActionResult Edit(int projectId)
        {
            var project = db.Projects.Find(projectId);

            if (!projHelper.IsUserOnProject(User.Identity.GetUserId(), projectId) && !roleHelper.IsUserInRole(User.Identity.GetUserId(), "Admin"))
            {
                return(RedirectToAction("Index"));
            }

            var devs         = roleHelper.UsersInRole("Developer");
            var AssignedDevs = new List <string>();

            foreach (var user in project.Users)
            {
                if (roleHelper.IsUserInRole(user.Id, "Developer"))
                {
                    AssignedDevs.Add(user.Id);
                }
            }

            ViewBag.Developers = new MultiSelectList(devs, "Id", "FullName", AssignedDevs);

            return(View(project));
        }
Пример #15
0
 public ActionResult ChangeUserRole(string userId, List <string> roleName, bool add)
 {
     if (add)
     {
         foreach (string role in roleName)
         {
             if (!rolesHelper.IsUserInRole(userId, role))
             {
                 rolesHelper.AddUserToRole(userId, role);
             }
         }
     }
     else
     {
         foreach (var role in roleName)
         {
             if (rolesHelper.IsUserInRole(userId, role))
             {
                 rolesHelper.RemoveUserFromRole(userId, role);
             }
         }
     }
     return(RedirectToAction("Personnel"));
 }
Пример #16
0
        public ActionResult UserProjects()
        {
            var usr = db.Users.Find(User.Identity.GetUserId());

            var rolesHelper = new UserRolesHelper(db);

            if (rolesHelper.IsUserInRole(usr.Id, "PM"))
            {
                var dbproject = db.Project.Include(p => p.ApplicationUsers).Where(x => x.UserId == usr.Id);



                return(View(dbproject));
            }
            else
            {
                return(View("Create"));
            }
        }
        public ActionResult Edit(int?id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }

            Ticket ticket = db.Tickets.Find(id);
            var    userId = User.Identity.GetUserId();

            if ((User.IsInRole("Submitter") && ticket.OwnerUserId != userId) ||
                (User.IsInRole("Developer") && ticket.AssignedToUserId != userId))
            {
                return(RedirectToAction("Oops", "Admin", new { id = ticket.Id }));
            }

            if (ticket == null)
            {
                return(HttpNotFound());
            }
            var developers = new List <ApplicationUser>();

            var usersOnProject = projectHelper.UsersOnProject(ticket.ProjectId);

            foreach (var user in usersOnProject)
            {
                if (roleHelper.IsUserInRole(user.Id, "Developer"))
                {
                    developers.Add(user);
                }
            }

            ViewBag.AssignedToUserId = new SelectList(developers, "Id", "FullContactinfo", ticket.AssignedToUserId);
            ViewBag.TicketPriorityId = new SelectList(db.TicketPriorities, "Id", "Name", ticket.TicketPriorityId);
            //ViewBag.Developers = new SelectList(db.Users, "Id", "FirstName", ticket.AssignedToUserId);
            //ViewBag.Submitters = new SelectList(db.Users, "Id", "FirstName", ticket.OwnerUserId);
            ViewBag.ProjectId      = new SelectList(db.Projects, "Id", "Name", ticket.ProjectId);
            ViewBag.TicketStatusId = new SelectList(db.TicketStatuses, "Id", "Name", ticket.TicketStatusId);
            ViewBag.TicketTypeId   = new SelectList(db.TicketTypes, "Id", "Name", ticket.TicketTypeId);
            return(View(ticket));
        }
Пример #18
0
        public ActionResult Edit(int?id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            Ticket ticket = db.Tickets.Find(id);

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

            //Here we only want the project manager to be able to assign users
            if (User.IsInRole("ProjectManager"))
            {
                //We also only want developers that are on the project to be able to be assigned
                //First we need a list of all the developers on the ticket's project
                var listDevs  = new List <ApplicationUser>();
                var projUsers = projHelper.UsersOnProject(ticket.ProjectsId);
                foreach (var user in projUsers)
                {
                    if (rolesHelper.IsUserInRole(user.Id, "Developer"))
                    {
                        listDevs.Add(user);
                    }
                }
                //now we set the drop down equal to that list
                ViewBag.AssignedToUserId = new SelectList(listDevs, "Id", "FirstName", ticket.AssignedToUserId);
            }



            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));
        }
        public ActionResult Create([Bind(Include = "Id,Name,Description,Deleted")] Household household)
        {
            if (ModelState.IsValid)
            {
                var userId  = User.Identity.GetUserId();
                var isGuest = roleHelper.IsUserInRole(userId, "Guest");
                if (isGuest == true)
                {
                    roleHelper.RemoveUserFromRole(userId, "Guest");
                }
                roleHelper.AddUserToRole(userId, "HOH");

                db.Households.Add(household);
                db.SaveChanges();

                var user = db.Users.Find(userId);
                user.HouseholdId = household.Id;
                db.SaveChanges();

                return(RedirectToAction("MyDashboard", "Dashboard", new { houseId = user.HouseholdId }));
            }

            return(View(household));
        }
Пример #20
0
        public ActionResult Index(int?page)
        {
            string userId         = User.Identity.GetUserId();
            bool   usrIsAdmiNOrPM = helper.IsUserInAnyRole(userId, "Admin", "PM");


            foreach (var item in db.Project.ToList())
            {
                ApplicationUser usr = db.Users.Find(item.UserId);

                projectslist.Add(new Project
                {
                    Id    = item.Id,
                    Title = item.Title,
                    Body  = item.Body,
                    //Owner = item.Owner,
                    Created = item.Created,
                    Updated = item.Updated,
                    //Priority =item.Priority,
                    //Status = item.Status,
                    UserId = item.UserId,
                });
            }



            if (usrIsAdmiNOrPM) // if logged in user is admin
            {
                return(View(projectslist.OrderBy(x => x.Id).ToList()));
                //all projects
            }
            else
            {
                // ApplicationUser usr = db.Users.Find(userId);


                //var dbproject = db.Project.Include(p => p.ApplicationUsers);
                //var list = projectslist.Where(x => x.UserId == usr.Id)

                //    .OrderBy(x => x.Id).ToList();
                var usr = db.Users.Find(User.Identity.GetUserId());

                var rolesHelper = new UserRolesHelper(db);
                if (rolesHelper.IsUserInRole(usr.Id, "Developer"))
                {
                    //projectslist.Clear();


                    var dbproject = db.Project.Include(p => p.ApplicationUsers).Where(x => x.UserId == usr.Id).ToList();

                    foreach (var item in dbproject)
                    {
                        projectslist.Add(new Project
                        {
                            Id    = item.Id,
                            Title = item.Title,
                            Body  = item.Body,
                            //Owner = item.Owner,
                            Created = item.Created,
                            Updated = item.Updated,
                            //Priority =item.Priority,
                            //Status = item.Status,
                            UserId = item.UserId
                        });
                    }

                    //string userselected = null;
                    //projectslist.Clear();

                    //foreach (var item in dbproject)
                    //{
                    //    var sss = item.ApplicationUsers.Where(x => x.Id == usr.Id);

                    //    foreach (var itemuser in sss)
                    //    {
                    //        userselected = itemuser.Id;
                    //    }

                    //    if (userselected != null)
                    //    {
                    //        projectslist.Add(new Project
                    //        {
                    //            Id = item.Id,
                    //            Title = item.Title,
                    //            Body = item.Body,
                    //            //Owner = item.Owner,
                    //            Created = item.Created,
                    //            Updated = item.Updated,
                    //            //Priority =item.Priority,
                    //            //Status = item.Status,
                    //            UserId = userselected


                    //        });

                    //    }
                    //}
                    return(View(projectslist));//user's projects.
                }
                else
                {
                    return(View());
                }
            }
        }
Пример #21
0
        public async Task <ActionResult> Create([Bind(Include = "Id,TicketId,Comment")] TicketComment ticketComment, int Id)
        {
            if (ModelState.IsValid)
            {
                UserRolesHelper     helper = new UserRolesHelper(db);
                ProjectAssignHelper ph     = new ProjectAssignHelper();
                var userId = User.Identity.GetUserId();
                var user   = db.Users.Find(userId);
                var ticket = db.Tickets.Find(Id);


                TicketNotification TN = new TicketNotification();
                TN.TicketId = ticket.Id;
                TN.UserId   = ticket.AssignedToUserId;
                TN.User     = ticket.AssignedToUser;
                db.TicketNotifications.Add(TN);

                var message = new IdentityMessage
                {
                    Body = "The ticket" + " " + ticket.Title + " " + "from project" + " " + ticket.Project.Name + " " + "has been commented on by" + " " + user.FirstName + user.LastName + "." + "  " +
                           "Please see your ticket comments to view the comment.",
                    Subject     = "Your ticket has been commented on.",
                    Destination = TN.User.Email
                };
                EmailService email = new EmailService();
                await email.SendAsync(message);



                var userroleAdmin           = helper.IsUserInRole(userId, "Admin") || helper.IsUserInRole(userId, "Administrator");
                var userroleProjectManager1 = helper.IsUserInRole(userId, "Project Manager1");
                var userroleProjectManager2 = helper.IsUserInRole(userId, "Project Manager2");
                var userroleProjectManager3 = helper.IsUserInRole(userId, "Project Manager3");
                var userroleDeveloper1      = helper.IsUserInRole(userId, "Developer1");
                var userroleDeveloper2      = helper.IsUserInRole(userId, "Developer2");
                var userroleDeveloper3      = helper.IsUserInRole(userId, "Developer3");
                var userroleDeveloper4      = helper.IsUserInRole(userId, "Developer4");
                var userroleSubmitter       = helper.IsUserInRole(userId, "Submitter");

                int ticketid  = Id;
                int projectid = ticket.Project.Id;

                if (userroleAdmin || userroleProjectManager1 && ph.IsUserOnAProject(userId, projectid) || userroleProjectManager2 && ph.IsUserOnAProject(userId, projectid) || userroleProjectManager3 && ph.IsUserOnAProject(userId, projectid) ||
                    userroleDeveloper1 && ticket.AssignedToUserId == userId || userroleDeveloper2 && ticket.AssignedToUserId == userId || userroleDeveloper3 && ticket.AssignedToUserId == userId ||
                    userroleDeveloper4 && ticket.AssignedToUserId == userId || userroleSubmitter && ticket.SubmitterUserId == userId)
                {
                    ticketComment.Ticket   = ticket;
                    ticketComment.UserId   = userId;
                    ticketComment.User     = user;
                    ticketComment.TicketId = ticket.Id;
                    string y = "";
                    ticketComment.CreatedDate = DateTime.UtcNow;
                    TimeSpan elapsed = DateTime.UtcNow - ticketComment.CreatedDate;



                    double hours   = elapsed.TotalHours;
                    double minutes = elapsed.TotalMinutes;
                    string s       = elapsed.ToString();

                    db.TicketComments.Add(ticketComment);
                    db.SaveChanges();
                    return(RedirectToAction("Details", "Tickets", new { id = Id }));
                }



                else
                {
                    var Temporary = "You cannot add comments to this ticket.  Please revisit your role assignment.  Tickets can only be commented on by their creator, a developer assigned to the ticket, a project manager, or an administrator.";
                    TempData["message"] = Temporary;
                }
            }
            return(RedirectToAction("Details", "Tickets", new { id = Id }));
        }
Пример #22
0
        // GET: Tickets/Edit/5
        public ActionResult Edit(int id) {

            TicketsModel ticketsModel = db.TicketsData.Find(id);
            if (ticketsModel == null) {
                return HttpNotFound();
            }
            var projectId = db.ProjectsData.Find(ticketsModel.ProjectId);
            var projectUser = projectId.Users.ToList();
            var projUserList = new List<ApplicationUser>();

            List<ApplicationUser> projdevs = new List<ApplicationUser>();
            UserRolesHelper helper = new UserRolesHelper();

            foreach (var user in projectId.Users) {
                if ((helper.IsUserInRole(user.Id, "Developer")) || (helper.IsUserInRole(user.Id, "ProjectManager"))) {
                    projdevs.Add(user);
                }
            }

            ViewBag.ProjectId = new SelectList(db.ProjectsData, "Id", "Name", ticketsModel.ProjectId);
            ViewBag.TicketPriorityId = new SelectList(db.TicketPrioritiesData, "Id", "Name", ticketsModel.TicketPriorityId);
            ViewBag.TicketStatusId = new SelectList(db.TicketStatusesData, "Id", "Name", ticketsModel.TicketStatusId);
            ViewBag.TicketTypeId = new SelectList(db.TicketTypesData, "Id", "Name", ticketsModel.TicketTypeId);
            ViewBag.OwnerUserId = new SelectList(db.Users, "Id", "DisplayName", ticketsModel.OwnerUserId);
            ViewBag.AssignedToUserId = new SelectList(projectUser.ToList(), "Id", "DisplayName", ticketsModel.AssignedToUserId);
            ViewBag.Comments = new SelectList(db.Users, "Id", "Comment", ticketsModel.Comments);
            ViewBag.Historys = new SelectList(db.TicketHistoriesData, "Id", "Property", ticketsModel.History);

            return View(ticketsModel);
        }
        public ActionResult Edit(int?id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            Ticket ticket = db.Tickets.Find(id);

            if (ticket == null)
            {
                return(HttpNotFound());
            }
            var userId         = User.Identity.GetUserId();
            var myProjects     = projectsHelper.ListUserProjects(userId);
            var developers     = new List <ApplicationUser>();
            var usersOnProject = projectsHelper.UsersOnProject(ticket.ProjectId);

            foreach (var user in usersOnProject)
            {
                if (roleHelper.IsUserInRole(user.Id, "Developer"))
                {
                    developers.Add(user);
                }
            }

            ViewBag.AssignedToUserId = new SelectList(developers, "Id", "FullName", ticket.AssignedToUserId);
            ViewBag.OwnerUserId      = new SelectList(db.Users, "Id", "FullName", 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);

            //authorization
            var userRole   = roleHelper.ListUserRoles(userId).FirstOrDefault();
            var authorized = false;

            switch (userRole)
            {
            case "Submitter":
                authorized = ticket.OwnerUserId == userId;
                break;

            case "Developer":
                authorized = ticket.AssignedToUserId == userId;
                break;

            case "Admin":
                authorized = true;
                break;

            case "Project Manager":
                var projectIds = db.Users.Find(userId).Projects.Select(p => p.Id).ToList();
                authorized = projectIds.Contains(ticket.ProjectId);
                break;
            }
            if (authorized == true)
            {
                return(View(ticket));
            }
            else
            {
                return(RedirectToAction("Permissions", "Admin"));
            }
        }
Пример #24
0
        public ActionResult Create([Bind(Include = "Id,TicketId,FilePath")] TicketAttachment ticketAttachment, string AttachmentDescription, HttpPostedFileBase file)
        {
            var userId = User.Identity.GetUserId();
            var ticket = db.Tickets.Find(ticketAttachment.TicketId);
            var pmId   = projHelper.GetProjectUsersInRole("Project Manager", ticket.ProjectId).FirstOrDefault().Id;

            if (!ticketHelper.IsUserAssignedToTicket(userId, ticket.Id) && !ticketHelper.IsUserTicketOwner(userId, ticket.Id) && !roleHelper.IsUserInRole(userId, "Admin") && userId != pmId)
            {
                return(RedirectToAction("Index", "Profile"));
            }
            if (ModelState.IsValid)
            {
                if (AttachmentHelper.IsWebFriendlyFile(file))
                {
                    var fileName = Path.GetFileName(file.FileName);
                    file.SaveAs(Path.Combine(Server.MapPath("~/Attachments/"), fileName));
                    ticketAttachment.FilePath = "/Attachments/" + fileName;
                }
                else
                {
                    return(RedirectToAction("Details", "Tickets", new { id = ticketAttachment.TicketId }));
                }
                ticketAttachment.Created     = DateTime.Now;
                ticketAttachment.Description = AttachmentDescription;
                ticketAttachment.UserId      = userId;
                db.Attachments.Add(ticketAttachment);

                var comment = new TicketComment
                {
                    CommentBody = $"<small>Uploaded an Attachment titled: <i>{Path.GetFileName(file.FileName)}</i> at {DateTime.Now.ToString("h:mm tt")}" +
                                  $"<br />Attachment Description: <i>{ticketAttachment.Description}</i></small>",
                    Created  = DateTime.Now,
                    TicketId = ticketAttachment.TicketId,
                    UserId   = ticketAttachment.UserId
                };
                db.Comments.Add(comment);
                db.SaveChanges();
                notifyHelper.attachmentNotify(comment);
                return(RedirectToAction("Details", "Tickets", new { id = ticketAttachment.TicketId }));
            }

            ViewBag.TicketId = new SelectList(db.Tickets, "Id", "OwnerUserId", ticketAttachment.TicketId);
            ViewBag.UserId   = new SelectList(db.Users, "Id", "FirstName", ticketAttachment.UserId);
            return(View(ticketAttachment));
        }
Пример #25
0
        public ActionResult LayoutPartial()
        {
            var currentuser = db.Users.Find(User.Identity.GetUserId());

            if (currentuser != null)
            {
                UserRolesHelper     uh = new UserRolesHelper(db);
                UsersRolesViewModel vm = new UsersRolesViewModel();
                vm.User  = db.Users.Find(User.Identity.GetUserId());
                vm.Roles = uh.ListUserRoles(vm.User.Id);

                UserRolesHelper     helper                    = new UserRolesHelper(db);
                ProjectAssignHelper ph                        = new ProjectAssignHelper();
                var                    userId                 = User.Identity.GetUserId();
                var                    user                   = db.Users.Find(userId);
                var                    userroleAdmin          = helper.IsUserInRole(userId, "Admin") || helper.IsUserInRole(userId, "Administrator");
                var                    userroleDeveloper      = helper.IsUserInRole(userId, "Developer1") || helper.IsUserInRole(userId, "Developer2") || helper.IsUserInRole(userId, "Developer3") || helper.IsUserInRole(userId, "Developer4");
                var                    userroleProjectManager = helper.IsUserInRole(userId, "Project Manager1") || helper.IsUserInRole(userId, "Project Manager2") || helper.IsUserInRole(userId, "Project Manager3");
                var                    userroleSubmitter      = helper.IsUserInRole(userId, "Submitter");
                List <Project>         DeveloperProjects      = new List <Project>();
                List <ApplicationUser> Developers             = helper.UsersInRole("Developer1").Concat(helper.UsersInRole("Developer2")).Concat(helper.UsersInRole("Developer3")).Concat(helper.UsersInRole("Developer4")).ToList();



                List <Project> userprojects = new List <Project>();
                foreach (var project in db.Projects)
                {
                    if (ph.IsUserOnAProject(userId, project.Id))
                    {
                        userprojects.Add(project);
                    }
                }

                ViewBag.projectcount = userprojects.Count();


                List <Ticket> usertickets = new List <Ticket>();

                if (helper.IsUserInRole(userId, "Admin") || helper.IsUserInRole(userId, "Administrator"))
                {
                    foreach (var ticket in db.Tickets)
                    {
                        usertickets.Add(ticket);
                    }
                    ViewBag.ticketcount = usertickets.Count();
                }

                else if (userroleProjectManager)
                {
                    List <Project> UserProjects = new List <Project>();
                    foreach (var x in db.Projects)
                    {
                        if (ph.IsUserOnAProject(userId, x.Id))
                        {
                            UserProjects.Add(x);
                        }
                    }

                    foreach (var project in UserProjects)
                    {
                        foreach (var ticket in project.Tickets)
                        {
                            usertickets.Add(ticket);
                        }
                    }
                    var nonarchivedtickets = usertickets.Where(t => t.TicketStatus.Name != "Archived");
                    var urgenttickets      = nonarchivedtickets.Where(t => t.TicketPriority.Name == "Urgent");
                    ViewBag.ticketcount       = nonarchivedtickets.Count();
                    ViewBag.urgentticketcount = urgenttickets.Count();
                }


                else if (userroleDeveloper)
                {
                    List <Project> UserProjects = new List <Project>();
                    foreach (var x in db.Projects)
                    {
                        if (ph.IsUserOnAProject(userId, x.Id))
                        {
                            UserProjects.Add(x);
                        }
                    }

                    foreach (var project in UserProjects)
                    {
                        foreach (var ticket in project.Tickets)
                        {
                            usertickets.Add(ticket);
                        }
                    }
                    var nonarchivedtickets = usertickets.Where(t => t.TicketStatus.Name != "Archived");

                    ViewBag.ticketcount = nonarchivedtickets.Count();
                }

                else if (userroleSubmitter)
                {
                    var tickets = db.Tickets.Where(t => t.SubmitterUserId == userId).ToList();

                    var nonarchivedtickets = tickets.Where(t => t.TicketStatus.Name != "Archived");
                    ViewBag.ticketcount = nonarchivedtickets.Count();
                }

                return(PartialView("~/Areas/BugTracker/Views/Shared/_LayoutPartial.cshtml", vm));
            }

            return(RedirectToAction("Index", "Home", new { area = "BugTracker" }));
        }
Пример #26
0
        public ActionResult Landing()
        {
            List <TicketData> TicketChartList = new List <TicketData>();



            TicketData TicketData1 = new TicketData();

            var dateago  = DateTime.Now.Date.AddDays(-7).ToString("d");
            var dateago2 = DateTime.Now.Date.AddDays(-6).ToString("d");
            var dateago3 = DateTime.Now.Date.AddDays(-5).ToString("d");
            var dateago4 = DateTime.Now.Date.AddDays(-4).ToString("d");
            var dateago5 = DateTime.Now.Date.AddDays(-3).ToString("d");
            var dateago6 = DateTime.Now.Date.AddDays(-2).ToString("d");
            var dateago7 = DateTime.Now.Date.AddDays(-1).ToString("d");
            var tickets  = new List <Ticket>();

            foreach (var ticket in db.Tickets)
            {
                if (ticket.CreatedDate.ToString("d") == dateago)
                {
                    tickets.Add(ticket);
                }
            }

            TicketData1.DayofWeek = DateTime.Now.Date.AddDays(-7).DayOfWeek.ToString();
            if (tickets.Count() != 0)
            {
                TicketData1.StatusA = tickets.Where(t => t.TicketPriority.Name == "Urgent").Count();
                TicketData1.StatusB = tickets.Where(t => t.TicketPriority.Name == "Normal").Count();
                TicketData1.StatusC = tickets.Where(t => t.TicketPriority.Name == "Low").Count();
                TicketChartList.Add(TicketData1);
            }
            else
            {
                TicketData1.StatusA = 0;
                TicketData1.StatusB = 0;     //makes sense go ahead and apply this to every case ok
                TicketData1.StatusC = 0;
                TicketChartList.Add(TicketData1);
            }

            var tickets2 = new List <Ticket>();

            foreach (var ticket in db.Tickets)
            {
                if (ticket.CreatedDate.ToString("d") == dateago2)
                {
                    tickets2.Add(ticket);
                }
            }

            TicketData TicketData3 = new TicketData();

            TicketData3.DayofWeek = DateTime.Now.Date.AddDays(-6).DayOfWeek.ToString();
            if (tickets2.Count() != 0)
            {
                TicketData3.StatusA = tickets2.Where(t => t.TicketPriority.Name == "Urgent").Count();
                TicketData3.StatusB = tickets2.Where(t => t.TicketPriority.Name == "Normal").Count();
                TicketData3.StatusC = tickets2.Where(t => t.TicketPriority.Name == "Low").Count();
                TicketChartList.Add(TicketData3);
            }
            else
            {
                TicketData3.StatusA = 0;
                TicketData3.StatusB = 0;
                TicketData3.StatusC = 0;
                TicketChartList.Add(TicketData3);
            }

            var tickets3 = new List <Ticket>();

            foreach (var ticket in db.Tickets)
            {
                if (ticket.CreatedDate.ToString("d") == dateago3)
                {
                    tickets3.Add(ticket);
                }
            }

            TicketData TicketData4 = new TicketData();

            TicketData4.DayofWeek = DateTime.Now.Date.AddDays(-5).DayOfWeek.ToString();

            if (tickets3.Count() != 0)
            {
                TicketData4.StatusA = tickets3.Where(t => t.TicketPriority.Name == "Urgent").Count();
                TicketData4.StatusB = tickets3.Where(t => t.TicketPriority.Name == "Normal").Count();
                TicketData4.StatusC = tickets3.Where(t => t.TicketPriority.Name == "Low").Count();
                TicketChartList.Add(TicketData4);
            }
            else
            {
                TicketData4.StatusA = 0;
                TicketData4.StatusB = 0;
                TicketData4.StatusC = 0;
                TicketChartList.Add(TicketData4);
            }


            var tickets4 = new List <Ticket>();

            foreach (var ticket in db.Tickets)
            {
                if (ticket.CreatedDate.ToString("d") == dateago4)
                {
                    tickets4.Add(ticket);
                }
            }


            TicketData TicketData5 = new TicketData();

            TicketData5.DayofWeek = DateTime.Now.Date.AddDays(-4).DayOfWeek.ToString();
            if (tickets4.Count() != 0)
            {
                TicketData5.StatusA = tickets4.Where(t => t.TicketPriority.Name == "Urgent").Count();
                TicketData5.StatusB = tickets4.Where(t => t.TicketPriority.Name == "Normal").Count();
                TicketData5.StatusC = tickets4.Where(t => t.TicketPriority.Name == "Low").Count();
                TicketChartList.Add(TicketData5);
            }
            else
            {
                TicketData5.StatusA = 0;
                TicketData5.StatusB = 0;
                TicketData5.StatusC = 0;
                TicketChartList.Add(TicketData5);
            }


            var tickets5 = new List <Ticket>();

            foreach (var ticket in db.Tickets)
            {
                if (ticket.CreatedDate.ToString("d") == dateago5)
                {
                    tickets5.Add(ticket);
                }
            }

            TicketData TicketData6 = new TicketData();

            TicketData6.DayofWeek = DateTime.Now.Date.AddDays(-3).DayOfWeek.ToString();
            if (tickets5.Count() != 0)
            {
                TicketData6.StatusA = tickets5.Where(t => t.TicketPriority.Name == "Urgent").Count();
                TicketData6.StatusB = tickets5.Where(t => t.TicketPriority.Name == "Normal").Count();
                TicketData6.StatusC = tickets5.Where(t => t.TicketPriority.Name == "Low").Count();
                TicketChartList.Add(TicketData6);
            }
            else
            {
                TicketData6.StatusA = 0;
                TicketData6.StatusB = 0;
                TicketData6.StatusC = 0;
                TicketChartList.Add(TicketData6);
            }

            var tickets6 = new List <Ticket>();

            foreach (var ticket in db.Tickets)
            {
                if (ticket.CreatedDate.ToString("d") == dateago6)
                {
                    tickets6.Add(ticket);
                }
            }

            TicketData TicketData7 = new TicketData();

            TicketData7.DayofWeek = DateTime.Now.Date.AddDays(-2).DayOfWeek.ToString();
            if (tickets6.Count() != 0)
            {
                TicketData7.StatusA = tickets6.Where(t => t.TicketPriority.Name == "Urgent").Count();
                TicketData7.StatusB = tickets6.Where(t => t.TicketPriority.Name == "Normal").Count();
                TicketData7.StatusC = tickets6.Where(t => t.TicketPriority.Name == "Low").Count();
                TicketChartList.Add(TicketData7);
            }
            else
            {
                TicketData7.StatusA = 0;
                TicketData7.StatusB = 0;
                TicketData7.StatusC = 0;
                TicketChartList.Add(TicketData7);
            }

            var tickets7 = new List <Ticket>();

            foreach (var ticket in db.Tickets)
            {
                if (ticket.CreatedDate.ToString("d") == dateago7)
                {
                    tickets7.Add(ticket);
                }
            }

            TicketData TicketData8 = new TicketData();

            TicketData8.DayofWeek = DateTime.Now.Date.AddDays(-1).DayOfWeek.ToString();
            if (tickets7.Count() != 0)
            {
                TicketData8.StatusA = tickets7.Where(t => t.TicketPriority.Name == "Urgent").Count();
                TicketData8.StatusB = tickets7.Where(t => t.TicketPriority.Name == "Normal").Count();
                TicketData8.StatusC = tickets7.Where(t => t.TicketPriority.Name == "Low").Count();
                TicketChartList.Add(TicketData8);
            }
            else
            {
                TicketData8.StatusA = 0;
                TicketData8.StatusB = 0;
                TicketData8.StatusC = 0;
                TicketChartList.Add(TicketData8);
            }


            List <UserData2> UserChartList = new List <UserData2>();
            UserRolesHelper  UH            = new UserRolesHelper(db);

            UserData2 User1      = new UserData2();
            var       AdminCount = UH.UsersInRole("Admin").Count();

            User1.label = "Administrator";
            User1.value = AdminCount;
            UserChartList.Add(User1);

            UserData2 User2     = new UserData2();
            var       DevCount1 = UH.UsersInRole("Developer1").Count();
            var       DevCount2 = UH.UsersInRole("Developer2").Count();
            var       DevCount3 = UH.UsersInRole("Developer3").Count();
            var       DevCount4 = UH.UsersInRole("Developer4").Count();

            User2.label = "Developers";
            User2.value = DevCount1 + DevCount2 + DevCount3 + DevCount4;
            UserChartList.Add(User2);

            UserData2 User3    = new UserData2();
            var       PMCount1 = UH.UsersInRole("Project Manager1").Count();
            var       PMCount2 = UH.UsersInRole("Project Manager2").Count();
            var       PMCount3 = UH.UsersInRole("Project Manager3").Count();


            User3.label = "Project Managers";
            User3.value = PMCount1 + PMCount2 + PMCount3;
            UserChartList.Add(User3);


            UserData2 User4          = new UserData2();
            var       SubmitterCount = UH.UsersInRole("Submitter").Count();

            User4.label = "Submitter";
            User4.value = SubmitterCount;
            UserChartList.Add(User4);



            ViewBag.ArrData2 = UserChartList.ToArray();
            ViewBag.ArrData  = TicketChartList.ToArray();

            UserRolesHelper     helper                    = new UserRolesHelper(db);
            ProjectAssignHelper ph                        = new ProjectAssignHelper();
            var                    userId                 = User.Identity.GetUserId();
            var                    user                   = db.Users.Find(userId);
            var                    userroleAdmin          = helper.IsUserInRole(userId, "Admin") || helper.IsUserInRole(userId, "Administrator");
            var                    userroleDeveloper      = helper.IsUserInRole(userId, "Developer1") || helper.IsUserInRole(userId, "Developer2") || helper.IsUserInRole(userId, "Developer3") || helper.IsUserInRole(userId, "Developer4");
            var                    userroleProjectManager = helper.IsUserInRole(userId, "Project Manager1") || helper.IsUserInRole(userId, "Project Manager2") || helper.IsUserInRole(userId, "Project Manager3");
            var                    userroleSubmitter      = helper.IsUserInRole(userId, "Submitter");
            List <Project>         DeveloperProjects      = new List <Project>();
            List <ApplicationUser> Developers             = helper.UsersInRole("Developer1").Concat(helper.UsersInRole("Developer2")).Concat(helper.UsersInRole("Developer3")).Concat(helper.UsersInRole("Developer4")).ToList();



            List <Ticket>  usertickets  = new List <Ticket>();
            List <Project> userprojects = new List <Project>();

            if (helper.IsUserInRole(userId, "Admin") || helper.IsUserInRole(userId, "Administrator"))
            {
                foreach (var project in db.Projects)
                {
                    if (ph.IsUserOnAProject(userId, project.Id))
                    {
                        userprojects.Add(project);
                    }
                }


                foreach (var ticket in db.Tickets)
                {
                    usertickets.Add(ticket);
                }
                var nonarchivedtickets = usertickets.Where(t => t.TicketStatus.Name != "Archived");
                var urgenttickets      = nonarchivedtickets.Where(t => t.TicketPriority.Name == "Urgent");
                var unassignedtickets  = nonarchivedtickets.Where(t => t.TicketStatus.Name == "Unassigned");
                ViewBag.unassignedticketcount = unassignedtickets.Count();
                ViewBag.ticketcount           = nonarchivedtickets.Count();
                ViewBag.urgentticketcount     = urgenttickets.Count();
                ViewBag.projectcount          = userprojects.Count();
                ViewBag.message           = "in the Bug Tracker system currently.";
                ViewBag.ticketmessage     = "in the Bug Tracker system currently.";
                ViewBag.unassignedmessage = "Unassigned tickets in the Bug Tracker system";
                if (urgenttickets.Count() == 0)
                {
                    ViewBag.urgentmessage = "There are no urgent tickets.";
                }
                else
                {
                    ViewBag.urgentmessage = "Please attend to these tickets if you are assigned to them.";
                }
                return(View(userprojects));
            }

            else if (userroleProjectManager)
            {
                foreach (var x in db.Projects)
                {
                    if (ph.IsUserOnAProject(userId, x.Id))
                    {
                        userprojects.Add(x);
                    }
                }

                foreach (var project in userprojects)
                {
                    foreach (var ticket in project.Tickets)
                    {
                        usertickets.Add(ticket);
                    }
                }
                var nonarchivedtickets = usertickets.Where(t => t.TicketStatus.Name != "Archived");
                var urgenttickets      = nonarchivedtickets.Where(t => t.TicketPriority.Name == "Urgent");
                var unassignedtickets  = nonarchivedtickets.Where(t => t.TicketStatus.Name == "Unassigned");
                ViewBag.unassignedticketcount = unassignedtickets.Count();
                ViewBag.ticketcount           = nonarchivedtickets.Count();
                ViewBag.urgentticketcount     = urgenttickets.Count();
                ViewBag.projectcount          = userprojects.Count();
                ViewBag.ticketmessage         = "for projects that you're working on.";
                ViewBag.message           = "that you're working on.";
                ViewBag.unassignedmessage = "Unassigned tickets in the Bug Tracker system";
                if (urgenttickets.Count() == 0)
                {
                    ViewBag.urgentmessage = "There are no urgent tickets.";
                }
                else
                {
                    ViewBag.urgentmessage = "Please attend to these tickets if you are assigned to them.";
                }

                return(View(userprojects));
            }


            else if (userroleDeveloper)
            {
                foreach (var x in db.Projects)
                {
                    if (ph.IsUserOnAProject(userId, x.Id))
                    {
                        userprojects.Add(x);
                    }
                }

                foreach (var project in userprojects)
                {
                    foreach (var ticket in project.Tickets)
                    {
                        usertickets.Add(ticket);
                    }
                }

                var nonarchivedtickets = usertickets.Where(t => t.TicketStatus.Name != "Archived");
                var urgenttickets      = nonarchivedtickets.Where(t => t.TicketPriority.Name == "Urgent");

                var unassignedtickets = nonarchivedtickets.Where(t => t.TicketStatus.Name == "Unassigned");
                ViewBag.unassignedticketcount = unassignedtickets.Count();
                ViewBag.ticketcount           = nonarchivedtickets.Count();
                ViewBag.urgentticketcount     = urgenttickets.Count();
                var urgentticketscount = urgenttickets.Count();
                ViewBag.projectcount      = userprojects.Count();
                ViewBag.unassignedmessage = "Unassigned tickets in the Bug Tracker system";
                ViewBag.ticketmessage     = "for projects that you're working on.";
                ViewBag.message           = "that you're working on.";
                if (urgentticketscount == 0)
                {
                    ViewBag.urgentmessage = "There are no urgent tickets.";
                }
                else
                {
                    ViewBag.urgentmessage = "Please attend to these tickets if you are assigned to them.";
                }
                return(View(userprojects));
            }

            else if (userroleSubmitter)
            {
                var submittertickets = db.Tickets.Where(t => t.SubmitterUserId == userId).ToList();

                var nonarchivedtickets = submittertickets.Where(t => t.TicketStatus.Name != "Archived");
                var urgenttickets      = nonarchivedtickets.Where(t => t.TicketPriority.Name == "Urgent");
                var unassignedtickets  = nonarchivedtickets.Where(t => t.TicketStatus.Name == "Unassigned");
                ViewBag.unassignedticketcount = unassignedtickets.Count();
                ViewBag.ticketcount           = nonarchivedtickets.Count();
                ViewBag.urgentticketcount     = urgenttickets.Count();
                ViewBag.projectcount          = userprojects.Count();
                ViewBag.ticketmessage         = "that you've submitted.";
                ViewBag.projectmessage        = "N/A";
                ViewBag.urgentmessage         = "N/A";
                ViewBag.unassignedmessage     = "Unassigned tickets in the Bug Tracker system";

                var projects = db.Projects.ToList();
                return(View(projects));
            }
            return(RedirectToAction("Index", "Home"));
        }
        public ActionResult Create(int TicketId, [ModelBinder(typeof(AllowHtmlBinder))] string CommentBody)
        {
            var userId = User.Identity.GetUserId();
            var ticket = db.Tickets.Find(TicketId);
            var pmId   = projHelper.GetProjectUsersInRole("Project Manager", ticket.ProjectId).FirstOrDefault().Id;

            if (!ticketHelper.IsUserAssignedToTicket(userId, TicketId) && !ticketHelper.IsUserTicketOwner(userId, TicketId) && !roleHelper.IsUserInRole(userId, "Admin") && userId != pmId)
            {
                return(RedirectToAction("Index", "Profile"));
            }
            var newComment = new TicketComment()
            {
                CommentBody = CommentBody,
                TicketId    = TicketId,
                UserId      = User.Identity.GetUserId(),
                Created     = DateTime.Now
            };

            db.Comments.Add(newComment);
            db.SaveChanges();
            notifyHelper.commentNotify(newComment);
            return(RedirectToAction("Details", "Tickets", new { id = TicketId }));
        }
Пример #28
0
        // GET: Projects
        public ActionResult Index()

        {
            UserRolesHelper     helper                    = new UserRolesHelper(db);
            ProjectAssignHelper ph                        = new ProjectAssignHelper();
            var                    userId                 = User.Identity.GetUserId();
            var                    user                   = db.Users.Find(userId);
            var                    userroleAdmin          = helper.IsUserInRole(userId, "Admin") || helper.IsUserInRole(userId, "Administrator");
            var                    userroleDeveloper      = helper.IsUserInRole(userId, "Developer1") || helper.IsUserInRole(userId, "Developer2") || helper.IsUserInRole(userId, "Developer3") || helper.IsUserInRole(userId, "Developer4");
            var                    userroleProjectManager = helper.IsUserInRole(userId, "Project Manager1") || helper.IsUserInRole(userId, "Project Manager2") || helper.IsUserInRole(userId, "Project Manager3");
            var                    userroleSubmitter      = helper.IsUserInRole(userId, "Submitter");
            List <Project>         DeveloperProjects      = new List <Project>();
            List <ApplicationUser> Developers             = helper.UsersInRole("Developer1").Concat(helper.UsersInRole("Developer2")).Concat(helper.UsersInRole("Developer3")).Concat(helper.UsersInRole("Developer4")).ToList();
            var                    projects               = db.Projects.Include(p => p.Users).ToList();



            ViewBag.user = user.FirstName + " " + user.LastName;



            List <Ticket>  usertickets  = new List <Ticket>();
            List <Project> userprojects = new List <Project>();

            if (helper.IsUserInRole(userId, "Admin") || helper.IsUserInRole(userId, "Administrator"))
            {
                foreach (var project in db.Projects)
                {
                    userprojects.Add(project);
                }


                foreach (var ticket in db.Tickets)
                {
                    usertickets.Add(ticket);
                }
                var nonarchivedtickets = usertickets.Where(t => t.TicketStatus.Name != "Archived");
                var urgenttickets      = nonarchivedtickets.Where(t => t.TicketPriority.Name == "Urgent");
                var unassignedtickets  = nonarchivedtickets.Where(t => t.TicketStatus.Name == "Unassigned");
                ViewBag.unassignedticketcount = unassignedtickets.Count();
                ViewBag.ticketcount           = nonarchivedtickets.Count();
                ViewBag.urgentticketcount     = urgenttickets.Count();
                ViewBag.projectcount          = userprojects.Count();
                ViewBag.message           = "in the Bug Tracker system currently.";
                ViewBag.ticketmessage     = "in the Bug Tracker system currently.";
                ViewBag.unassignedmessage = "Unassigned tickets in the Bug Tracker system";
                if (urgenttickets.Count() == 0)
                {
                    ViewBag.urgentmessage = "There are no urgent tickets.";
                }
                else
                {
                    ViewBag.urgentmessage = "Please attend to these tickets if you are assigned to them.";
                }
                return(View(userprojects));
            }

            else if (userroleProjectManager)
            {
                foreach (var x in db.Projects)
                {
                    if (ph.IsUserOnAProject(userId, x.Id))
                    {
                        userprojects.Add(x);
                    }
                }

                foreach (var project in userprojects)
                {
                    foreach (var ticket in project.Tickets)
                    {
                        usertickets.Add(ticket);
                    }
                }
                var nonarchivedtickets = usertickets.Where(t => t.TicketStatus.Name != "Archived");
                var urgenttickets      = nonarchivedtickets.Where(t => t.TicketPriority.Name == "Urgent");
                var unassignedtickets  = nonarchivedtickets.Where(t => t.TicketStatus.Name == "Unassigned");
                ViewBag.unassignedticketcount = unassignedtickets.Count();
                ViewBag.ticketcount           = nonarchivedtickets.Count();
                ViewBag.urgentticketcount     = urgenttickets.Count();
                ViewBag.projectcount          = userprojects.Count();
                ViewBag.ticketmessage         = "for projects that you're working on.";
                ViewBag.message           = "that you're working on.";
                ViewBag.unassignedmessage = "Unassigned tickets in the Bug Tracker system";
                if (urgenttickets.Count() == 0)
                {
                    ViewBag.urgentmessage = "There are no urgent tickets.";
                }
                else
                {
                    ViewBag.urgentmessage = "Please attend to these tickets if you are assigned to them.";
                }

                return(View(userprojects));
            }


            else if (userroleDeveloper)
            {
                foreach (var x in db.Projects)
                {
                    if (ph.IsUserOnAProject(userId, x.Id))
                    {
                        userprojects.Add(x);
                    }
                }

                foreach (var project in userprojects)
                {
                    foreach (var ticket in project.Tickets)
                    {
                        usertickets.Add(ticket);
                    }
                }

                var nonarchivedtickets = usertickets.Where(t => t.TicketStatus.Name != "Archived");
                var urgenttickets      = nonarchivedtickets.Where(t => t.TicketPriority.Name == "Urgent");

                var unassignedtickets = nonarchivedtickets.Where(t => t.TicketStatus.Name == "Unassigned");
                ViewBag.unassignedticketcount = unassignedtickets.Count();
                ViewBag.ticketcount           = nonarchivedtickets.Count();
                ViewBag.urgentticketcount     = urgenttickets.Count();
                var urgentticketscount = urgenttickets.Count();
                ViewBag.projectcount      = userprojects.Count();
                ViewBag.unassignedmessage = "Unassigned tickets in the Bug Tracker system";
                ViewBag.ticketmessage     = "for projects that you're working on.";
                ViewBag.message           = "that you're working on.";
                if (urgentticketscount == 0)
                {
                    ViewBag.urgentmessage = "There are no urgent tickets.";
                }
                else
                {
                    ViewBag.urgentmessage = "Please attend to these tickets if you are assigned to them.";
                }
                return(View(userprojects));
            }

            else if (userroleSubmitter)
            {
                var tickets = db.Tickets.Where(t => t.SubmitterUserId == userId).ToList();

                foreach (var x in db.Projects)
                {
                    if (ph.IsUserOnAProject(userId, x.Id))
                    {
                        userprojects.Add(x);
                    }
                }



                var nonarchivedtickets = tickets.Where(t => t.TicketStatus.Name != "Archived");
                var urgenttickets      = nonarchivedtickets.Where(t => t.TicketPriority.Name == "Urgent");
                var unassignedtickets  = nonarchivedtickets.Where(t => t.TicketStatus.Name == "Unassigned");
                ViewBag.unassignedticketcount = unassignedtickets.Count();
                ViewBag.ticketcount           = nonarchivedtickets.Count();
                ViewBag.urgentticketcount     = urgenttickets.Count();
                ViewBag.projectcount          = userprojects.Count();
                ViewBag.ticketmessage         = "that you've submitted.";
                ViewBag.projectmessage        = "N/A";
                ViewBag.urgentmessage         = "N/A";
                ViewBag.unassignedmessage     = "Unassigned tickets in the Bug Tracker system";

                return(View(userprojects));
            }
            return(RedirectToAction("Index", "Home"));
        }
Пример #29
0
        public async Task <ActionResult> Create([Bind(Include = "Id,UserId,Description,CreatedDate")] TicketAttachment ticketAttachment, HttpPostedFileBase File, int Id)
        {
            UserRolesHelper     helper = new UserRolesHelper(db);
            ProjectAssignHelper ph     = new ProjectAssignHelper();
            var userId = User.Identity.GetUserId();
            var user   = db.Users.Find(userId);

            var ticket = db.Tickets.Find(Id);


            if (ModelState.IsValid)
            {
                if (helper.IsUserInRole(userId, "Administrator") || helper.IsUserInRole(userId, "Admin") || helper.IsUserInRole(userId, "Project Manager1") && ph.IsUserOnAProject(userId, ticket.Project.Id) ||
                    helper.IsUserInRole(userId, "Project Manager2") && ph.IsUserOnAProject(userId, ticket.Project.Id) || helper.IsUserInRole(userId, "Project Manager3") && ph.IsUserOnAProject(userId, ticket.Project.Id) ||
                    helper.IsUserInRole(userId, "Developer1") && ticket.AssignedToUserId == userId || helper.IsUserInRole(userId, "Developer2") && ticket.AssignedToUserId == userId || helper.IsUserInRole(userId, "Developer3") && ticket.AssignedToUserId == userId ||
                    helper.IsUserInRole(userId, "Developer4") && ticket.AssignedToUserId == userId || helper.IsUserInRole(userId, "Submitter") && ticket.SubmitterUserId == userId)
                {
                    if (File != null)
                    {
                        TicketNotification TN = new TicketNotification();
                        TN.TicketId = ticket.Id;
                        TN.UserId   = ticket.AssignedToUserId;
                        TN.User     = ticket.AssignedToUser;
                        db.TicketNotifications.Add(TN);

                        var message = new IdentityMessage
                        {
                            Body = "The ticket" + " " + ticket.Title + " " + "from project" + " " + ticket.Project.Name + " " + "has been edited by" + " " + user.FirstName + user.LastName + "." + "  " +
                                   "Please see the ticket history to view the specific change.",
                            Subject     = "Your ticket has been edited",
                            Destination = TN.User.Email
                        };
                        EmailService email = new EmailService();
                        await email.SendAsync(message);

                        if (FileUploadValidator.IsWebFriendlyFile(File))

                        {
                            var fileName   = Path.GetFileName(File.FileName);
                            var customName = string.Format(Guid.NewGuid() + fileName);
                            File.SaveAs(Path.Combine(Server.MapPath("~/Uploads/"), customName));
                            ticketAttachment.FilePath = "/Uploads/" + customName;


                            string filename      = ticketAttachment.FilePath.ToString();
                            string word          = ".docx";
                            string excel         = ".xls";
                            string excelx        = "xlsx";
                            string pdf           = ".pdf";
                            string jpeg          = ".jpeg";
                            string bmp           = ".bmp";
                            string gif           = ".gif";
                            string zip           = ".zip";
                            string rar           = ".rar";
                            string ticketmessage = "";
                            if (filename.Contains(word))
                            {
                                ticketmessage = "This is a Word Document";
                            }
                            else if (filename.Contains(excel))
                            {
                                ticketmessage = "This is an Excel File";
                            }
                            else if (filename.Contains(pdf))
                            {
                                ticketmessage = "This is an PDF File";
                            }
                            else if (filename.Contains(jpeg))
                            {
                                ticketmessage = "This is a JPEG File";
                            }
                            else if (filename.Contains(bmp))
                            {
                                ticketmessage = "This is a BMP File";
                            }
                            else if (filename.Contains(gif))
                            {
                                ticketmessage = "This is a .gif File";
                            }
                            else if (filename.Contains(zip))
                            {
                                ticketmessage = "This is an ZIP File";
                            }
                            else if (filename.Contains(rar))
                            {
                                ticketmessage = "This is a RAR File";
                            }
                            else if (filename.Contains(excelx))
                            {
                                ticketmessage = "This is an .xlsx File";
                            }



                            ticketAttachment.CreatedDate = DateTimeOffset.Now;
                            var ticketdatestring = ticketAttachment.CreatedDate.ToString("MM-dd-yyyy");
                            ticketAttachment.TicketId    = Id;
                            ticketAttachment.Description = ticketmessage + " " + "added by" + " " + user.FirstName + " " + user.LastName + " " + "on" + " " + ticketdatestring + ".";
                            ticketAttachment.UserId      = userId;

                            db.TicketAttachments.Add(ticketAttachment);
                            db.SaveChanges();
                        }
                        int id = Id;
                        return(RedirectToAction("Details", "Tickets", new { id = id }));
                    }
                    else
                    {
                        var Temporary = "Please select an image between 1KB - 2MB and in an approved format(.jpg, .bmp, .png, .gif)";
                        TempData["attachmentmessage"] = Temporary;
                    }
                }
                var Temporary3 = "You cannot edit this ticket.  Please revisit your role assignment.  Tickets can only be edited by their creator, a developer assigned to the ticket, a project manager, or an administrator.";
                TempData["message"] = Temporary3;
                return(RedirectToAction("Details", "Tickets", new { id = Id }));
            }

            ViewBag.TicketId = new SelectList(db.Tickets, "Id", "SubmitterUserId", ticketAttachment.TicketId);
            ViewBag.UserId   = new SelectList(db.Users, "Id", "FirstName", ticketAttachment.UserId);
            return(View(ticketAttachment));
        }
        public ActionResult TicketCreate(int projectId)
        {
            var project = db.Projects.Find(projectId);

            if (!projHelper.IsUserOnProject(User.Identity.GetUserId(), projectId) && !roleHelper.IsUserInRole(User.Identity.GetUserId(), "Admin"))
            {
                return(RedirectToAction("Index"));
            }
            var defaultPriority = db.Priorities.FirstOrDefault(m => m.Name == "Low");
            var newTicket       = new Ticket()
            {
                StatusId  = db.Statuses.FirstOrDefault(s => s.Name == "Unassigned").Id,
                TypeId    = db.Types.FirstOrDefault(t => t.Name == "Bug").Id,
                ProjectId = projectId
            };

            ViewBag.PriorityId  = new SelectList(db.Priorities, "Id", "Name", defaultPriority.Id);
            ViewBag.TypeId      = new SelectList(db.Types, "Id", "Name");
            ViewBag.ProjectName = project.Name;
            return(View(newTicket));
        }