ViewModel for the SalaryReviewAnalysis class
Inheritance: EsraBaseViewModel
Exemplo n.º 1
0
        public static SalaryReviewAnalysisViewModel Create(IRepository repository, bool isDepartmentUser, User user, SalaryReviewAnalysisSearchParamsModel salaryReviewAnalysisSearchParamsModel)
        {
            Check.Require(repository != null, "Repository must be supplied");

            //bool isDepartmentUserBool =
            // Boolean.TryParse(isDepartmentUser, out isDepartmentUserBool) ? isDepartmentUserBool : false;

            var viewModel = new SalaryReviewAnalysisViewModel
            {
                SalaryReviewAnalysisSearchParamsModel =
                    SalaryReviewAnalysisSearchParamsModel.Create(repository,
                                                                 salaryReviewAnalysisSearchParamsModel),
                SelectedEmployee        = salaryReviewAnalysisSearchParamsModel.SelectedEmployee,
                SelectedUser            = salaryReviewAnalysisSearchParamsModel.SelectedUser,
                SelectedReferenceNumber =
                    salaryReviewAnalysisSearchParamsModel.SelectedReferenceNumber,
                CreationDateString = salaryReviewAnalysisSearchParamsModel.CreationDateString,
                SalaryReviewAnalysisSearchExpression =
                    salaryReviewAnalysisSearchParamsModel.SalaryReviewAnalysisSearchExpression,

                SalaryReviewAnalysis = new SalaryReviewAnalysis(),

                IsDepartmentUser = isDepartmentUser,

                FilteredEmployees = new List <Employee>(),

                FilteredUsers = User.GetAll(repository, user, isDepartmentUser),

                ProposedTitles = repository.OfType <Title>()
                                 .Queryable
                                 .OrderBy(t => t.TitleCode)
                                 .ToList()
            };

            var            allSchoolDepartments = Department.GetAllForUser(repository, user, false, "Name", true);
            IList <String> usersDepartmentsList;

            if (isDepartmentUser)
            {
                var usersUnits = user.Units.Select(u => u.PPSCode).ToArray();

                usersDepartmentsList = allSchoolDepartments
                                       .Where(x => usersUnits.Contains(x.Id))
                                       .Select(u => u.Id)
                                       .ToArray();
            }
            else
            {
                usersDepartmentsList = allSchoolDepartments.Select(x => x.Id).ToArray();
            }

            // This will return a list of employees with their IsDepartmentEmployee set appropriately if isDepartmentUser == true.
            var allSchoolEmployees = Employee.GetAllForEmployeeTable(repository, user, isDepartmentUser, "FullName", true, null, null, allSchoolDepartments.Select(x => x.Id).ToArray());

            // Assign only those with IsDepartmentEmployee == true to Employees select list or ALL school employees is non-department user, i.e. deans office.
            viewModel.FilteredEmployees = isDepartmentUser ? allSchoolEmployees.Where(x => x.IsDepartmentEmployee == true).ToList() : allSchoolEmployees;

            //------------------------------------------------------------------------------------
            // viewModel.FilteredSalaryReviewAnalysis should only contain reference numbers for
            // Analysis that are visible to the User, meaning created by someone in the user's units:

            // Returns a list of reviewers that are within the Catbert user's units:
            var reviewerNames = viewModel.FilteredUsers.Select(x => x.FullName).ToArray();

            // This query will get those salary review analysis created by anyone in the filtered users list,
            // but we probably want a list of those salary review analysis created that have an originating
            // department in the usersDepartmentsList
            //viewModel.FilteredSalaryReviewAnalysis = repository.OfType<SalaryReviewAnalysis>()
            //    .Queryable
            //    .Where(x => reviewerNames.Contains(x.InitiatedByReviewerName))
            //    .OrderBy(y => y.ReferenceNumber)
            //    .ToList();

            // This query will get those salary review analysis created that have an originating
            // department in the usersDepartmentsList
            viewModel.FilteredSalaryReviewAnalysis = repository.OfType <SalaryReviewAnalysis>()
                                                     .Queryable
                                                     .Where(x => usersDepartmentsList.Contains(x.OriginatingDepartment.Id))
                                                     .OrderBy(y => y.ReferenceNumber)
                                                     .ToList();

            //------------------------------------------------------------------------------------
            var searchParamsModel = viewModel.SalaryReviewAnalysisSearchParamsModel;

            if (searchParamsModel.SalaryReviewAnalysisSearchExpression == null ||
                (searchParamsModel.HasCreateDateOnly && !searchParamsModel.HasCreateDate))
            {
                // Load all based on viewModel.FilteredSalaryReviewAnalysis reference numbers:
                var referenceNumbers = viewModel.FilteredSalaryReviewAnalysis.Select(x => x.ReferenceNumber).ToArray();

                //TODO: Figure out how to make this a Linq query that does an inner join instead calling the db SELECT N+1 times:  FIXED by adding .Fetch(y => y.Employee) and container.Register(Component.For<IQueryExtensionProvider>().ImplementedBy<NHibernateQueryExtensionProvider>().Named("queryExtensions")); to the ComponentRegstrar class.

                viewModel.SalaryReviewAnalysisResults = repository.OfType <SalaryReviewAnalysis>()
                                                        .Queryable.Fetch(y => y.Employee)
                                                        .Where(x => referenceNumbers.Contains(x.ReferenceNumber))
                                                        .OrderBy(t => t.Employee.FullName)
                                                        .ToList();
            }
            else
            {
                // Load all based on search criteria:
                viewModel.SalaryReviewAnalysisResults = repository.OfType <SalaryReviewAnalysis>()
                                                        .Queryable.Fetch(x => x.Employee)
                                                        .Where(viewModel.SalaryReviewAnalysisSearchParamsModel.SalaryReviewAnalysisSearchExpression)
                                                        .OrderBy(t => t.Employee.FullName)
                                                        .ToList();
            }

            return(viewModel);
        }
Exemplo n.º 2
0
        public static SalaryReviewAnalysisViewModel Create(IRepository repository, bool isDepartmentUser, User user, SalaryReviewAnalysisSearchParamsModel salaryReviewAnalysisSearchParamsModel)
        {
            Check.Require(repository != null, "Repository must be supplied");

            //bool isDepartmentUserBool =
            // Boolean.TryParse(isDepartmentUser, out isDepartmentUserBool) ? isDepartmentUserBool : false;

            var viewModel = new SalaryReviewAnalysisViewModel
                                {
                                    SalaryReviewAnalysisSearchParamsModel =
                                        SalaryReviewAnalysisSearchParamsModel.Create(repository,
                                                                                     salaryReviewAnalysisSearchParamsModel),
                                    SelectedEmployee = salaryReviewAnalysisSearchParamsModel.SelectedEmployee,
                                    SelectedUser = salaryReviewAnalysisSearchParamsModel.SelectedUser,
                                    SelectedReferenceNumber =
                                        salaryReviewAnalysisSearchParamsModel.SelectedReferenceNumber,
                                    CreationDateString = salaryReviewAnalysisSearchParamsModel.CreationDateString,
                                    SalaryReviewAnalysisSearchExpression =
                                        salaryReviewAnalysisSearchParamsModel.SalaryReviewAnalysisSearchExpression,

                                    SalaryReviewAnalysis = new SalaryReviewAnalysis(),

                                    IsDepartmentUser = isDepartmentUser,

                                    FilteredEmployees = new List<Employee>(),

                                    FilteredUsers = User.GetAll(repository, user, isDepartmentUser),

                                    ProposedTitles = repository.OfType<Title>()
                                    .Queryable
                                    .OrderBy(t => t.TitleCode)
                                    .ToList()
                                };

            var allSchoolDepartments = Department.GetAllForUser(repository, user, false, "Name", true);
            IList<String> usersDepartmentsList;

            if (isDepartmentUser)
            {
                var usersUnits = user.Units.Select(u => u.PPSCode).ToArray();

                usersDepartmentsList = allSchoolDepartments
                    .Where(x => usersUnits.Contains(x.Id))
                    .Select(u => u.Id)
                    .ToArray();
            }
            else
            {
                usersDepartmentsList = allSchoolDepartments.Select(x => x.Id).ToArray();
            }

            // This will return a list of employees with their IsDepartmentEmployee set appropriately if isDepartmentUser == true.
            var allSchoolEmployees = Employee.GetAllForEmployeeTable(repository, user, isDepartmentUser, "FullName", true, null, null, allSchoolDepartments.Select(x => x.Id).ToArray());

            // Assign only those with IsDepartmentEmployee == true to Employees select list or ALL school employees is non-department user, i.e. deans office.
            viewModel.FilteredEmployees = isDepartmentUser ? allSchoolEmployees.Where(x => x.IsDepartmentEmployee == true).ToList() : allSchoolEmployees;

            //------------------------------------------------------------------------------------
            // viewModel.FilteredSalaryReviewAnalysis should only contain reference numbers for
            // Analysis that are visible to the User, meaning created by someone in the user's units:

            // Returns a list of reviewers that are within the Catbert user's units:
            var reviewerNames = viewModel.FilteredUsers.Select(x => x.FullName).ToArray();

            // This query will get those salary review analysis created by anyone in the filtered users list,
            // but we probably want a list of those salary review analysis created that have an originating
            // department in the usersDepartmentsList
            //viewModel.FilteredSalaryReviewAnalysis = repository.OfType<SalaryReviewAnalysis>()
            //    .Queryable
            //    .Where(x => reviewerNames.Contains(x.InitiatedByReviewerName))
            //    .OrderBy(y => y.ReferenceNumber)
            //    .ToList();

            // This query will get those salary review analysis created that have an originating
            // department in the usersDepartmentsList
            viewModel.FilteredSalaryReviewAnalysis = repository.OfType<SalaryReviewAnalysis>()
                .Queryable
                .Where(x => usersDepartmentsList.Contains(x.OriginatingDepartment.Id))
                .OrderBy(y => y.ReferenceNumber)
                .ToList();

            //------------------------------------------------------------------------------------
            var searchParamsModel = viewModel.SalaryReviewAnalysisSearchParamsModel;

            if (searchParamsModel.SalaryReviewAnalysisSearchExpression == null
               || (searchParamsModel.HasCreateDateOnly && !searchParamsModel.HasCreateDate))
            {
                // Load all based on viewModel.FilteredSalaryReviewAnalysis reference numbers:
                var referenceNumbers = viewModel.FilteredSalaryReviewAnalysis.Select(x => x.ReferenceNumber).ToArray();

                //TODO: Figure out how to make this a Linq query that does an inner join instead calling the db SELECT N+1 times:  FIXED by adding .Fetch(y => y.Employee) and container.Register(Component.For<IQueryExtensionProvider>().ImplementedBy<NHibernateQueryExtensionProvider>().Named("queryExtensions")); to the ComponentRegstrar class.

                viewModel.SalaryReviewAnalysisResults = repository.OfType<SalaryReviewAnalysis>()
                    .Queryable.Fetch(y => y.Employee)
                    .Where(x => referenceNumbers.Contains(x.ReferenceNumber))
                    .OrderBy(t => t.Employee.FullName)
                    .ToList();
            }
            else
            {
                // Load all based on search criteria:
                viewModel.SalaryReviewAnalysisResults = repository.OfType<SalaryReviewAnalysis>()
                                                            .Queryable.Fetch(x => x.Employee)
                                                            .Where(viewModel.SalaryReviewAnalysisSearchParamsModel.SalaryReviewAnalysisSearchExpression)
                                                            .OrderBy(t => t.Employee.FullName)
                                                            .ToList();
            }

            return viewModel;
        }