public ActionResult AssignUsersToProjects(int projectId, string[] userIdArr)
        {
            var project = projectManager.FindProject(projectId);

            if (project == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            if (userIdArr != null && userIdArr.Count() > 0)
            {
                foreach (var userId in userIdArr)
                {
                    var user = userManagerHelper.FindUser(userId);
                    if (user != null)
                    {
                        ProjectUsers newProjectUsers = new ProjectUsers {
                            ProjectId = project.Id, ApplicationUserId = userId
                        };
                        db.ProjectUsers.Add(newProjectUsers);
                        db.SaveChanges();
                    }
                }
            }
            return(RedirectToAction("Index"));
        }
Exemplo n.º 2
0
        public ActionResult CreateTicket([Bind(Include = "Id, Title, Description, ProjectId, TicketPriorityId, TicketTypeId")] Ticket newTicket)
        {
            var userId       = User.Identity.GetUserId();
            var user         = userManagerHelper.FindUser(userId);
            var ticketStatus = db.TicketStatuses.FirstOrDefault(ts => ts.Name == "Created");

            newTicket.Created = DateTime.Now;
            if (user == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            newTicket.OwnerUserId    = user.Id;
            newTicket.TicketStatusId = ticketStatus.Id;
            db.Tickets.Add(newTicket);
            db.SaveChanges();
            return(RedirectToAction("AddAttachment", new { ticketId = newTicket.Id }));
        }
Exemplo n.º 3
0
        public ActionResult AssignToRoles(string userId, string roleName)
        {
            var           user           = userManagerHelper.FindUser(userId);
            StringBuilder returnedString = new StringBuilder();

            if (user != null)
            {
                if (userManagerHelper.AddToRole(userId, roleName))
                {
                    returnedString.Append(string.Format("{0} was added to {1} role!", user.UserName, roleName));
                    ViewBag.Message = returnedString.ToString();
                }
                else
                {
                    returnedString.Append(string.Format("{0} was not added to {1} role!", user.UserName, roleName));
                    ViewBag.Message = returnedString.ToString();
                }
                return(View());
            }
            return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
        }
Exemplo n.º 4
0
        public List <Ticket> GetTickets(List <string> input)
        {
            var    ticketList = db.Tickets.ToList();
            String userId     = "";
            String role       = "";
            int    index      = 0;

            foreach (var item in input)
            {
                if (index == 0)
                {
                    userId = item;
                }
                else
                {
                    role = item;
                }
                index++;
            }
            var user = userManagerHelper.FindUser(userId);

            if (userManager.IsInRole(userId, "Admin") || user.UserName == "*****@*****.**")
            {
                return(ticketList);
            }
            else if (userManager.IsInRole(userId, "Project Manager"))
            {
                var myProjects = (from projectUser in db.ProjectUsers
                                  where projectUser.ApplicationUserId == userId
                                  select projectUser).ToList();
                var tickets = (from ticket in ticketList
                               join project in myProjects
                               on ticket.ProjectId equals project.Id
                               select ticket).ToList();
                return(tickets);
            }
            else if (userManager.IsInRole(userId, "Developer"))
            {
                var myProjects = (from projectUser in db.ProjectUsers
                                  where projectUser.ApplicationUserId == userId
                                  select projectUser).ToList();
                var tickets = (from ticket in ticketList
                               join project in myProjects
                               on ticket.ProjectId equals project.Id
                               select ticket).ToList();
                return(tickets);
            }
            else if (userManager.IsInRole(userId, "Submitter"))
            {
                var submitter = userManagerHelper.FindUser(userId);
                if (submitter == null)
                {
                    return(null);
                }
                var tickets = user.OwnedTickets.ToList();
                return(tickets);
            }
            else
            {
                return(null);
            }
        }