public List <Tickets> GetUserTickets(string userId) { var user = db.Users.Find(userId); UserRoleAssignHelper userHelper = new UserRoleAssignHelper(db); ProjectsHelper projectHelper = new ProjectsHelper(db); var userRoles = userHelper.ListMyRoles(userId); var tickets = new List <Tickets>(); if (userRoles.Contains("Admin")) { tickets = user.Projects.SelectMany(p => p.Tickets).ToList(); } else if (userRoles.Contains("ProjectManager")) { tickets = user.Projects.SelectMany(p => p.Tickets).ToList(); } else if (userRoles.Contains("Developer") && userRoles.Contains("Submitter")) { tickets = db.Tickets.Where(t => t.AssignedUserId == userId || t.OwnerId == userId).Include(t => t.AssignedUser).Include(t => t.Owner).Include(t => t.Project).ToList(); } else if (userRoles.Contains("Developer")) { tickets = db.Tickets.Where(t => t.AssignedUserId == userId).Include(t => t.AssignedUser).Include(t => t.Owner).Include(t => t.Project).ToList(); } else if (userRoles.Contains("Submitter")) { tickets = db.Tickets.Where(t => t.OwnerId == userId).Include(t => t.AssignedUser).Include(t => t.Owner).Include(t => t.Project).ToList(); } return(tickets); }
public List <string> ListProjectManagers(int?projectId) { var projectManagers = new List <string>(); var project = db.Projects.Find(projectId); var projectUsers = project.Users.ToList(); UserRoleAssignHelper helper = new UserRoleAssignHelper(db); foreach (var user in projectUsers) { if (helper.IsUserInRole(user.Id, "ProjectManager")) { projectManagers.Add(user.Email); } } return(projectManagers); }
public ActionResult UserProfile(string userId) { var user = manager.FindById(User.Identity.GetUserId()); userId = User.Identity.GetUserId(); UserViewModel model = new UserViewModel(); UserRoleAssignHelper helper = new UserRoleAssignHelper(db); model.Name = user.FullName; model.Roles = helper.ListMyRoles(userId); model.ProjectCount = db.Projects.Count(); model.Email = user.Email; var tickets = user.Projects.SelectMany(p => p.Tickets).ToList(); model.TicketsAssigned = tickets.Where(t => t.AssignedUserId == user.Id).Count(); model.TicketsSubmitted = tickets.Where(t => t.OwnerId == user.Id).Count(); return(View(model)); }
public bool HasTicketPermission(string userId, int ticketId) { var user = db.Users.Find(userId); var ticket = db.Tickets.Find(ticketId); UserRoleAssignHelper helper = new UserRoleAssignHelper(); var userRoles = helper.ListMyRoles(userId); if (userRoles.Contains("Admin")) { return(true); } else if (userRoles.Contains("ProjectManager") && user.Projects.SelectMany(p => p.Tickets).ToList().Contains(ticket)) { return(true); } else if (userRoles.Contains("Submitter") && userRoles.Contains("Developer")) { if (ticket.AssignedUserId == userId || ticket.OwnerId == userId) { return(true); } else { return(false); } } else if (userRoles.Contains("Developer") && ticket.AssignedUserId == userId) { return(true); } else if (userRoles.Contains("Submitter") && ticket.OwnerId == userId) { return(true); } else { return(false); } }
public async Task <ActionResult> Create([Bind(Include = "Id,Title,Body,ProjectId,OwnerId,PriorityId,TypeId,AssignedUserId,Type,Priority")] Tickets ticket) { if (ModelState.IsValid) { ticket.Created = DateTimeOffset.Now; ticket.OwnerId = User.Identity.GetUserId(); ticket.StatusId = db.TicketStatus.SingleOrDefault(s => s.Status == "Open").Id; ticket.AssignedUserId = User.Identity.GetUserId(); ticket.OwnerId = User.Identity.GetUserId(); TicketHistory history = new TicketHistory(); history.Date = ticket.Created; var historyBody = "Ticket created Title: " + ticket.Title + " Body: " + ticket.Body + " Priority: " + ticket.Priority + " Type: " + ticket.Type; history.Body = historyBody; history.Body = historyBody.ToString(); history.TicketId = ticket.Id; db.Tickets.Add(ticket); db.TicketHistory.Add(history); db.SaveChanges(); var user = db.Users.Find(ticket.OwnerId); TicketNotify notify = new TicketNotify(); notify.TicketId = ticket.Id; notify.NotifyUserId = ticket.OwnerId; db.Notifications.Add(notify); UserRoleAssignHelper helper = new UserRoleAssignHelper(); var manager = db.ProjectUsers.Where(p => p.ProjectId == ticket.ProjectId).ToList(); foreach (var item in manager) { if (helper.IsUserInRole(item.ProjectUserId, "ProjectManager")) { TicketNotify notify2 = new TicketNotify(); notify2.TicketId = ticket.Id; notify.NotifyUserId = item.ProjectUserId; db.Notifications.Add(notify2); } } var emails = db.Notifications.Where(t => t.TicketId == ticket.Id).Select(u => u.NotifyUser.Email).ToList(); var apiKey = ConfigurationManager.AppSettings["SendGridAPIkey"]; var from = ConfigurationManager.AppSettings["ContactEmail"]; foreach (var email in emails) { SendGridMessage myMessage = new SendGridMessage(); myMessage.AddTo(email); myMessage.From = new MailAddress(from); myMessage.Subject = "Notification for Ticket #" + ticket.Id; myMessage.Html = "Ticket #" + ticket.Id + " has been created"; var credentials = new NetworkCredential(apiKey, from); var transportWeb = new Web(credentials); await transportWeb.DeliverAsync(myMessage); } return(RedirectToAction("Index")); } ViewBag.OwnerId = new SelectList(db.Tickets, "Id", "Owner", ticket.OwnerId); ViewBag.ProjectId = new SelectList(db.Projects, "Id", "Project", ticket.ProjectId); ViewBag.PriorityId = new SelectList(db.TicketPriorities, "Id", "Priority", ticket.Priority); ViewBag.TypeId = new SelectList(db.TicketTypes, "Id", "Type", ticket.Type); return(View()); }