Exemple #1
0
 public static SalaryReviewAnalysisViewModel Create(IRepository repository, bool isDepartmentUser, SalaryReviewAnalysisSearchParamsModel salaryReviewAnalysisSearchParamsModel)
 {
     return(Create(repository, false, null, salaryReviewAnalysisSearchParamsModel));
 }
Exemple #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);
        }
        public static SalaryReviewAnalysisSearchParamsModel Create(IRepository repository, SalaryReviewAnalysisSearchParamsModel salaryReviewAnalysisSearchParamsModel)
        {
            var viewModel = new SalaryReviewAnalysisSearchParamsModel();

            if (salaryReviewAnalysisSearchParamsModel != null)
            {
                viewModel.SalaryReviewAnalysisSearchExpression = PredicateBuilder.True <SalaryReviewAnalysis>();

                if (salaryReviewAnalysisSearchParamsModel.SelectedEmployee != null && String.IsNullOrEmpty(salaryReviewAnalysisSearchParamsModel.SelectedEmployee.id) == false)
                {
                    viewModel.SelectedEmployee  = salaryReviewAnalysisSearchParamsModel.SelectedEmployee;
                    viewModel.HasEmployee       = true;
                    viewModel.HasCreateDateOnly = false;

                    viewModel.SalaryReviewAnalysisSearchExpression =
                        viewModel.SalaryReviewAnalysisSearchExpression.And(
                            p => p.Employee.PkEmployee == viewModel.SelectedEmployee.id);
                }

                if (String.IsNullOrEmpty(salaryReviewAnalysisSearchParamsModel.SelectedEmployeeId) == false)
                {
                    viewModel.SelectedEmployeeId = salaryReviewAnalysisSearchParamsModel.SelectedEmployeeId;
                    viewModel.HasEmployeeId      = true;
                    viewModel.HasCreateDateOnly  = false;

                    viewModel.SelectedEmployee = repository.OfType <Employee>()
                                                 .Queryable.Where(r => r.id == viewModel.SelectedEmployeeId)
                                                 .FirstOrDefault();

                    viewModel.SalaryReviewAnalysisSearchExpression =
                        viewModel.SalaryReviewAnalysisSearchExpression.And(
                            p => p.Employee.PkEmployee == viewModel.SelectedEmployeeId);
                }

                if (salaryReviewAnalysisSearchParamsModel.SelectedUser != null && salaryReviewAnalysisSearchParamsModel.SelectedUser.Id != 0)
                {
                    viewModel.SelectedUser      = salaryReviewAnalysisSearchParamsModel.SelectedUser;
                    viewModel.HasUser           = true;
                    viewModel.HasCreateDateOnly = false;

                    viewModel.SalaryReviewAnalysisSearchExpression =
                        viewModel.SalaryReviewAnalysisSearchExpression.And(
                            p => p.InitiatedByReviewerName.Equals(viewModel.SelectedUser.FullName));
                }

                if (salaryReviewAnalysisSearchParamsModel.SelectedUserId != null && salaryReviewAnalysisSearchParamsModel.SelectedUserId != 0)
                {
                    viewModel.SelectedUserId    = salaryReviewAnalysisSearchParamsModel.SelectedUserId;
                    viewModel.HasUserId         = true;
                    viewModel.HasCreateDateOnly = false;

                    viewModel.SelectedUser = repository.OfType <User>()
                                             .Queryable.Where(r => r.Id == viewModel.SelectedUserId)
                                             .FirstOrDefault();

                    viewModel.SalaryReviewAnalysisSearchExpression =
                        viewModel.SalaryReviewAnalysisSearchExpression.And(
                            p => p.InitiatedByReviewerName.Equals(viewModel.SelectedUser.FullName));
                }

                if (!String.IsNullOrEmpty(salaryReviewAnalysisSearchParamsModel.SelectedReferenceNumber))
                {
                    viewModel.SelectedReferenceNumber = salaryReviewAnalysisSearchParamsModel.SelectedReferenceNumber;
                    viewModel.HasReferenceNumber      = true;
                    viewModel.HasCreateDateOnly       = false;

                    viewModel.SalaryReviewAnalysisSearchExpression =
                        viewModel.SalaryReviewAnalysisSearchExpression.And(
                            p => p.ReferenceNumber.Equals(viewModel.SelectedReferenceNumber));
                }

                if (!String.IsNullOrEmpty(salaryReviewAnalysisSearchParamsModel.CreationDateString))
                {
                    // if createDate != today then true
                    var createDate = new DateTime();

                    if (DateTime.TryParse(salaryReviewAnalysisSearchParamsModel.CreationDateString, out createDate))
                    {
                        viewModel.CreationDateString = createDate.ToString("MM/dd/yyyy");
                    }

                    if (String.IsNullOrEmpty(viewModel.CreationDateString) == false && DateTime.Now.ToString("MM/dd/yyyy").Equals(viewModel.CreationDateString) == false)
                    {
                        viewModel.HasCreateDate = true;

                        createDate = Convert.ToDateTime(viewModel.CreationDateString);

                        viewModel.SalaryReviewAnalysisSearchExpression = viewModel.SalaryReviewAnalysisSearchExpression.And(p => p.DateInitiated == createDate);
                    }
                }
            }

            return(viewModel);
        }