public ActionResult Create([Bind(Include = "Id,Title,Description,Created,ProjectId,TicketTypeId,TicketPriorityId,TicketStatusId,OwnerId,AssignedId")] Ticket ticket, string Title, string Status, string Type, string Priority, string Project)
        {
            if (ModelState.IsValid)
            {
                var queryp = db.Priorities.AsQueryable();
                var querys = db.Status.AsQueryable();
                var querypr = db.Projects.AsQueryable();
                var queryty = db.Types.AsQueryable();
                if(!string.IsNullOrWhiteSpace(Priority))
                {
                    var queryt = queryp.Where(x => x.Priority == Priority).Select(y => y.Id).Single();
                    ticket.TicketPriorityId = queryt;
                }
                if(!string.IsNullOrWhiteSpace(Status))
                {
                    var queryt = querys.Where(x => x.Status == Status).Select(y => y.Id).Single();
                    ticket.TicketStatusId = queryt;
                }
                if(!string.IsNullOrWhiteSpace(Project))
                {
                    var queryt = querypr.Where(x => x.Project == Project).Select(y => y.Id).Single();
                    ticket.ProjectId = queryt;
                }
                if(!string.IsNullOrWhiteSpace(Type))
                {
                    var queryt = queryty.Where(x => x.Type == Type).Select(y => y.Id).Single();
                    ticket.TicketTypeId = queryt;
                }
                ticket.Title = Title;
                ticket.Created = System.DateTimeOffset.Now;
                ticket.OwnerId = User.Identity.GetUserId();

                TicketNotify note = new TicketNotify();
                note.TicketId = ticket.Id;
                note.NotifyUserId = ticket.OwnerId;
                db.Notifications.Add(note);

                UserRoleHelper helper = new UserRoleHelper();
                var manager = db.ProjectUsers.Where(x => x.ProjectId == ticket.ProjectId).ToList();
                foreach(var item in manager)
                {
                    if(helper.IsUserInRole(item.ProjectUserId, "ProjectManager"))
                    {
                        TicketNotify note2 = new TicketNotify();
                        note2.TicketId = ticket.Id;
                        note2.NotifyUserId = item.ProjectUserId;
                        db.Notifications.Add(note2);
                    }
                }

                var emails = db.Notifications.Where(x => x.TicketId == ticket.Id).Select(y => y.NotifyUser.Email).ToList();
                var username = ConfigurationManager.AppSettings["SendGridUserName"];
                var password = ConfigurationManager.AppSettings["SendGridPassword"];
                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(username, password);

                    var transportWeb = new Web(credentials);

                    transportWeb.DeliverAsync(myMessage);
                }

                db.Tickets.Add(ticket);
                db.SaveChanges();
                return RedirectToAction("Index");
            }

            return View(ticket);
        }
 // GET: Tickets/Edit/5
 public ActionResult Edit(int? id)
 {
     UserRoleHelper helper = new UserRoleHelper();
     if (id == null)
     {
         return new HttpStatusCodeResult(HttpStatusCode.BadRequest);
     }
     Ticket ticket = db.Tickets.Find(id);
     if (ticket == null)
     {
         return HttpNotFound();
     }
     var query = db.ProjectUsers.Where(x => x.Project.Project == ticket.Project.Project).ToList();
     bool found = false;
     foreach(var item in query)
     {
         var user = db.Users.Where(x => x.Id == item.ProjectUserId).Single();
         if (helper.IsUserInRole(user.Id, "Developer"))
         {
             userassign.Add(user);
             found = true;
         }
     }
     if (found)
     {
         if(!string.IsNullOrWhiteSpace(ticket.AssignedId))
         {
             ticketd.ticketassign = new SelectList(userassign, "UserName", "UserName", ticket.Assigned.UserName);
         }
         else
         {
             ticketd.ticketassign = new SelectList(userassign, "UserName", "UserName");
         }
     }
     ViewBag.TicketPriorityId = new SelectList(db.Priorities, "Id", "Priority", ticket.TicketPriorityId);
     ViewBag.TicketStatusId = new SelectList(db.Status, "Id", "Status", ticket.TicketStatusId);
     ViewBag.TicketTypeId = new SelectList(db.Types, "Id", "Type", ticket.TicketTypeId);
     ticketd.ticketdetails = ticket;
     return View(ticketd);
 }
Beispiel #3
0
 public ActionResult Report(string role, string type)
 {
     UserRoleHelper helperu = new UserRoleHelper();
     Reporthelper reporter = new Reporthelper();
     ReportInput rp = new ReportInput();
     var dbin = db.Tickets.Where(x => (x.TicketStatus.Status != "Fixed") ||
         (x.TicketStatus.Status != "Released") || (x.TicketStatus.Status != "NoBug")).ToList();
     IList<UserTicketList> access = helper.UserisOwnerorAssigned(User.Identity.GetUserId(), dbin);
     var selectlist = helperu.ListUserRoles(User.Identity.GetUserId());
     string selected = null;
     if (string.IsNullOrWhiteSpace(type))
     {
         if (string.IsNullOrWhiteSpace(role))
         {
             IList<ReportList> reports = reporter.createreport(db.Priorities.ToList());
             if (User.IsInRole("Admin"))
             {
                 reporter.popreport(dbin, reports);
                 selected = "Admin";
             }
             if (User.IsInRole("ProjectManager"))
             {
                 reporter.popreport(dbin, reports, access, false, false, true);
                 selected = "ProjectManager";
             }
             if (User.IsInRole("Developer"))
             {
                 reporter.popreport(dbin, reports, access, false, true, false);
                 selected = "Developer";
             }
             if (User.IsInRole("Submitter"))
             {
                 reporter.popreport(dbin, reports, access, true, false, false);
                 selected = "Submitter";
             }
             rp.reportin = reports;
             rp.projectreportin = null;
             rp.rolesin = new SelectList(selectlist, selected);
             rp.type = "All";
         }
     }
     else
     {
         if (!string.IsNullOrWhiteSpace(role))
         {
             if (type == "Projects")
             {
                 IList<ProjectReportList> reports = new List<ProjectReportList>();
                 if (role == "Admin")
                 {
                     reports = reporter.createreport(db.Priorities.ToList(), db.Projects.ToList());
                 }
                 else
                 {
                     reports = reporter.createreport(db.Priorities.ToList(), db.ProjectUsers.ToList(), User.Identity.GetUserId());
                 }
                 if (role == "Admin")
                 {
                     reporter.popreport(dbin, reports);
                 }
                 if (role == "ProjectManager")
                 {
                     reporter.popreport(dbin, reports, access, false, false, true);
                 }
                 if (role == "Developer")
                 {
                     reporter.popreport(dbin, reports, access, false, true, false);
                 }
                 if (role == "Submitter")
                 {
                     reporter.popreport(dbin, reports, access, true, false, false);
                 }
                 rp.reportin = null;
                 rp.projectreportin = reports;
                 rp.rolesin = new SelectList(selectlist, role);
                 rp.type = type;
             }
             if (type == "All")
             {
                 IList<ReportList> reports = reporter.createreport(db.Priorities.ToList());
                 if (role == "Admin")
                 {
                     reporter.popreport(dbin, reports);
                 }
                 if (role == "ProjectManager")
                 {
                     reporter.popreport(dbin, reports, access, false, false, true);
                 }
                 if (role == "Developer")
                 {
                     reporter.popreport(dbin, reports, access, false, true, false);
                 }
                 if (role == "Submitter")
                 {
                     reporter.popreport(dbin, reports, access, true, false, false);
                 }
                 rp.reportin = reports;
                 rp.projectreportin = null;
                 rp.rolesin = new SelectList(selectlist, role);
                 rp.type = type;
             }
         }
     }
     return View(rp);
 }
        public ActionResult UserRolePageSub(string id, string Username, string[] Roles)
        {
            UserRoleHelper helper = new UserRoleHelper();
            IList<string> temp = helper.ListUserRoles(id);
            var remove = true;
            IList<string> response = new List<string>();
            foreach(var item in Roles)
            {
                if(!helper.IsUserInRole(id, item))
                {
                    helper.AddUserToRole(id, item);
                    response.Add("Added Role " + item + " to User " + Username);
                }
            }
            foreach(var tempitem in temp)
            {
                remove = true;
                foreach(var item in Roles)
                {
                    if(tempitem == item)
                    {
                        remove = false;
                    }
                }
                if(remove)
                {
                    helper.RemoveUserFromRole(id, tempitem);
                    response.Add("Removed Role " + tempitem + " from User " + Username);
                }
            }
            assign.User = db.Users.Find(id);
            var selected = helper.ListUserRoles(id);
            assign.RoleInput = new MultiSelectList(db.Roles, "Name", "Name", selected);
            assign.response = response;

            return View(assign);
        }
 public ActionResult UserRolePageSub(string id)
 {
     if (id == null)
     {
         return new HttpStatusCodeResult(HttpStatusCode.BadRequest);
     }
     assign.User = db.Users.Find(id);
     UserRoleHelper helper = new UserRoleHelper();
     var selected = helper.ListUserRoles(id);
     assign.RoleInput = new MultiSelectList(db.Roles, "Name", "Name", selected);
     if (assign.User == null)
     {
         return HttpNotFound();
     }
     return View(assign);
 }
 public ActionResult UserRolePage()
 {
     assign.master = db.Users.OrderBy(g => g.LastName).OrderBy(p => p.FirstName).ToList();
     UserRoleHelper helper = new UserRoleHelper();
     assign.helper = helper;
     return View(assign);
 }