예제 #1
0
 /// <summary>
 /// Give me the List of Projects to sort and the parameters to filter and sort and I will do the work and return
 /// </summary>
 /// <param name="title"></param>
 /// <param name="orderBy"></param>
 /// <param name="depID"></param>
 /// <param name="status"></param>
 /// <param name="data"></param>
 /// <returns></returns>
 public static List <Project> SortAndFilterProjects(string title, string orderBy, string depID, string status, List <Project> data)
 {
     if (!string.IsNullOrEmpty(title))
     {
         data = FilteringServices.FilterProjectByTitle(title, data);
     }
     if (!string.IsNullOrEmpty(orderBy))
     {
         data = SortingServices.SortProject(orderBy, data);
     }
     if (!string.IsNullOrEmpty(depID))
     {
         data = FilteringServices.FilterProjectsPerDepartment(int.Parse(depID), data);
     }
     if (!string.IsNullOrEmpty(status))
     {
         data = FilteringServices.StatusProject(status, data);
     }
     return(data);
 }
예제 #2
0
        public ActionResult ViewAllProjects(string title, string orderBy, string depID, string status)
        {
            ViewBag.Admin = User.IsInRole("Admin");

            ViewBag.Supervisor = User.IsInRole("Supervisor");

            var data = _data.Project.AllProjects();

            var userOnline = _data.ApplicationUser.FindUserByID(User.Identity.GetUserId());

            if (!ViewBag.Admin)
            {
                data = data.Where(w => w.WorkersInMe.Any(s => s.WorkerID == userOnline.Worker.ID)).ToList();
            }

            data = SortingAndFilteringData.SortAndFilterProjects(title, orderBy, depID, status, data);

            if (ViewBag.Supervisor)
            {
                data = FilteringServices.FilterProjectsPerDepartment(userOnline.Worker.DepartmentID, data);
            }
            else if (!ViewBag.Admin && !ViewBag.Supervisor)
            {
                data = FilteringServices.FilterProjectsPerDepartment(userOnline.Worker.DepartmentID, data);
            }

            ViewBag.SortOptions = _fillViewBag.GetProjectSortOptions();

            ViewBag.StatusOptions = _fillViewBag.StatusSortOptionsViewBag();

            ViewBag.DepartmentOptions = _fillViewBag.ProjectInDepartmentsSortViewBag();

            ViewBag.Names = _fillViewBag.GetProjectNamesForAutocomplete(data);

            return(View(data));
        }