public ActionResult Index(string SelectFilter, int?page, string searchString)
        {
            //SortViewModel sortModel = new SortViewModel();
            ViewBag.SelectFilter = new SelectList(sortModel.Options);


            var projects = ProjectHelper.GetProjects();

            if (SelectFilter == "Creation Date")
            {
                projects = ProjectHelper.SortTicketsByTitle(projects);
            }
            else if (SelectFilter == "Title")
            {
                projects = ProjectHelper.SortTicketsByTitle(projects);
            }

            return(View(PaginateList(projects, page)));
        }
        public ActionResult AssignUserToProject(string Id, int projectId)
        {
            var project = ProjectHelper.GetProject(projectId);

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

            if (ProjectHelper.AssignUserToProject(Id, projectId))
            {
                return(RedirectToAction("ShowAllUsers", new { projectId }));
            }

            var users = ProjectHelper.UsersOutOfTheProject(projectId);

            ViewBag.ProjectId   = projectId;
            ViewBag.ProjectName = project.Name;
            ViewBag.UserId      = new SelectList(users, "Id", "UserName");

            return(RedirectToAction("ShowAllUsers", new { projectId }));
        }
        public async Task <ActionResult> EditUsers([Bind(Include = "Users,Project,SelectedUsers")] ProjectViewModel model, TicketNotification ticketNotification)
        {
            ProjectHelper helper = new ProjectHelper();

            foreach (var user in db.Users)
            {
                if (helper.IsUserOnProject(user.Id, model.Project.Id))
                {
                    helper.RemoveUserFromProject(user.Id, model.Project.Id);
                }
            }
            foreach (var user in model.SelectedUsers)
            {
                if (!helper.IsUserOnProject(user, model.Project.Id))
                {
                    helper.AddUserToProject(user, model.Project.Id);
                    //userManager.SendEmailAsync(user, "Notification", "You have been added to project " + model.Project.Name);
                    var callbackUrl = Url.Action("Details", "Projects", new { id = model.Project.Id }, protocol: Request.Url.Scheme);
                    try
                    {
                        EmailService    ems = new EmailService();
                        IdentityMessage msg = new IdentityMessage();
                        ApplicationUser usr = db.Users.Find(user);
                        msg.Body        = "You have been added to a Project." + Environment.NewLine + "Please click the following link to view the details" + "<a href=\"" + callbackUrl + "\">PROJECT</a>";
                        msg.Destination = usr.Email;
                        msg.Subject     = "BugTracker";
                        await ems.SendMailAsync(msg);
                    }
                    catch (Exception ex)
                    {
                        await Task.FromResult(0);
                    }
                }
            }
            return(RedirectToAction("Index"));
        }
 // GET: ProjectUsers/Create
 public ActionResult Create()
 {
     ViewBag.ProjectId = new SelectList(ProjectHelper.GetProjects(), "Id", "Name");
     ViewBag.UserId    = new SelectList(UserHelper.GetAllUsers(), "Id", "Email");
     return(View());
 }
        public ActionResult Index(int?filterState, bool?includeClosed)
        {
            IEnumerable <Ticket> tickets = new List <Ticket>();

            if (includeClosed == true)
            {
                tickets = db.Tickets
                          .Include(t => t.AssignedUser)
                          .Include(t => t.OwnerUser)
                          .Include(t => t.Priority)
                          .Include(t => t.Project)
                          .Include(t => t.Status)
                          .Include(t => t.Type)
                          .ToList();
                ViewBag.includeClosedTkts = true;
            }
            else
            {
                tickets = db.Tickets
                          .Include(t => t.AssignedUser)
                          .Include(t => t.OwnerUser)
                          .Include(t => t.Priority)
                          .Include(t => t.Project)
                          .Include(t => t.Status)
                          .Include(t => t.Type)
                          .ToList()
                          .Where(t => t.Closed == false);
                ViewBag.includeClosedTkts = false;
            }

            var userid = User.Identity.GetUserId();

            switch (filterState)
            {
            //DEFAULTS. All tickets shown
            case null:
                ViewBag.Filtered = false;
                return(View(tickets));

            case 0:
                ViewBag.Filtered = false;
                return(View(tickets));

            //PROJECT FILTER. only tickets that belong to projects user is assigned to are returned
            case 1:
                ViewBag.Filtered = true;
                ProjectHelper helper = new ProjectHelper();
                var           projs  = helper.ListUserProjects(User.Identity.GetUserId());
                return(View(tickets.Where(t => projs.Select(p => p.Id).Contains(t.ProjectId))));

            //DEV FILTER. only tickets user assigned to are returned
            case 2:
                ViewBag.Filtered = true;
                return(View(tickets.Where(t => t.AssignedUserId == userid)));

            //SUBMITTER FILTER. only tickets user owns are returned
            case 3:
                ViewBag.Filtered = true;
                return(View(tickets.Where(t => t.OwnerUserId == userid)));
            }
            return(HttpNotFound());
        }
Esempio n. 6
0
 public ProjectController()
 {
     db            = new ApplicationDbContext();
     userHelper    = new UserHelper(db);
     projectHelper = new ProjectHelper(db);
 }