public static QuestionViewModel Create(IRepository repository, int? templateId, int? callForProposalId) { Check.Require(repository != null, "Repository must be supplied"); var viewModel = new QuestionViewModel { Question = new Question(), QuestionTypes = repository.OfType<QuestionType>().GetAll(), Validators = repository.OfType<Validator>().GetAll() }; if (templateId != null && templateId != 0) { viewModel.IsTemplate = true; viewModel.TemplateId = templateId; } else if (callForProposalId != null && callForProposalId != 0) { viewModel.IsCallForProposal = true; viewModel.CallForProposalId = callForProposalId; } Check.Require(viewModel.IsTemplate || viewModel.IsCallForProposal, "Must have either a template or a call for proposal"); return viewModel; }
public static EmailTemplateListViewModel Create(IRepository repository, int? templateId, int? callForProposalId) { Check.Require(repository != null, "Repository must be supplied"); var viewModel = new EmailTemplateListViewModel(); if (templateId != null && templateId != 0) { viewModel.IsTemplate = true; viewModel.EmailTemplateList = repository.OfType<EmailTemplate>().Queryable.Where(a => a.Template != null && a.Template.Id == templateId); viewModel.TemplateId = templateId; } else if (callForProposalId != null && callForProposalId != 0) { viewModel.IsCallForProposal = true; viewModel.EmailTemplateList = repository.OfType<EmailTemplate>().Queryable.Where(a => a.CallForProposal != null && a.CallForProposal.Id == callForProposalId); viewModel.CallForProposalId = callForProposalId; } viewModel.DescriptionDict = new Dictionary<EmailTemplateType, string>(7); viewModel.DescriptionDict.Add(EmailTemplateType.InitialCall, StaticValues.InitialCall); viewModel.DescriptionDict.Add(EmailTemplateType.ProposalApproved, StaticValues.ProposalApproved); viewModel.DescriptionDict.Add(EmailTemplateType.ProposalConfirmation, StaticValues.ProposalConfirmation); viewModel.DescriptionDict.Add(EmailTemplateType.ProposalDenied, StaticValues.ProposalDenied); viewModel.DescriptionDict.Add(EmailTemplateType.ReadyForReview, StaticValues.ReadyForReview); viewModel.DescriptionDict.Add(EmailTemplateType.ReminderCallIsAboutToClose, StaticValues.ReminderCallIsAboutToClose); viewModel.DescriptionDict.Add(EmailTemplateType.ProposalUnsubmitted, StaticValues.ProposalUnsubmitted); return viewModel; }
private static void LoadEmployees(IRepository repository) { if (Employees == null) { Employees = new Dictionary <string, IList <Employee> >(); } var schoolCodes = repository.OfType <Unit>().Queryable.Select(x => x.DeansOfficeSchoolCode).Distinct().ToArray(); SchoolCodes = schoolCodes; // For future use in checking what schools employees have been loaded for. var deptCodes = repository.OfType <Department>().Queryable.Where( x => schoolCodes.Contains(x.DeansOfficeSchoolCode)).Select(y => y.Id).ToList(); var allEmployees = repository.OfType <Employee>().GetAll(); //MaxLastChangeDate = allEmployees.Select(x => x.LastChangeDate).Max(); //LastRefreshed = DateTime.Now; foreach (var code in schoolCodes) { // Add all employees who have a home department within the school: Employees.Add(code, allEmployees.Where(d => deptCodes.Contains(d.HomeDepartmentID)).OrderBy(x => x.FullName).ToList()); } }
public static NotificationTrackingViewModel Create(IRepository repository, string siteId, NotificationTracking notificationTracking = null, Person person = null, MailingList mailingList = null) { Check.Require(repository != null, "Repository is required."); var seminar = SiteService.GetLatestSeminar(siteId); var viewModel = new NotificationTrackingViewModel() { NotificationTracking = notificationTracking ?? new NotificationTracking(), NotificationMethods = repository.OfType <NotificationMethod>().GetAll(), NotificationTypes = repository.OfType <NotificationType>().GetAll(), People = new List <Person>(), AllPeople = SiteService.GetLatestSeminar(siteId).SeminarPeople.Select(a => a.Person).ToList(), //seminarService.GetCurrent().SeminarPeople.Select(a=>a.Person).ToList(), SitePeople = SiteService.LoadSite(siteId).People, Seminar = seminar, MailingLists = seminar.MailingLists, MailingList = mailingList }; if (person != null) { viewModel.People.Add(person); } return(viewModel); }
/// <summary> /// Given a title code and date, /// return the salary scale that would have been in effect for the date provided. /// This is necessary when there are several salary scales for a given title code, /// and you do not know the salary scale's actual effective date. /// </summary> /// <param name="repository"></param> /// <param name="titleCode"></param> /// <param name="effectiveDate"></param> /// <returns>SalaryScale in effect for title code and date provided</returns> public static SalaryScale GetEffectiveSalaryScale(IRepository repository, string titleCode, DateTime effectiveDate) { SalaryScale salaryScale = null; var queryable = repository.OfType <SalaryScale>().Queryable; var count = queryable.Where(x => x.TitleCode.Equals(titleCode)).Count(); // Get the corresponding salary scale only if there's salary data available; otherwise, return null // and let the view handle displaying the "No Data Found" message. if (count > 0) { if (count == 1) { // If there's only 1 salary scale set the return value to it: salaryScale = queryable.Where(x => x.TitleCode.Equals(titleCode)).SingleOrDefault(); } else { if (effectiveDate.Equals(new DateTime())) { effectiveDate = DateTime.Now; } // If there's multiple salary scales for the same title code, get the one // whose effective date is equal to or less than the effectiveDate provided: // First find the max effective date for the given title code that is equal to or less than the effectiveDate, i.e. date provided: var maxEffectiveDateForDate = queryable.Where(x => x.TitleCode.Equals(titleCode) && x.EffectiveDate <= effectiveDate).Max(x => x.EffectiveDate); // Set the return value to the one whose effectiveDate matches the maximum effective date determined // in the previous statement: salaryScale = queryable .Where(x => x.TitleCode.Equals(titleCode) && x.EffectiveDate == maxEffectiveDateForDate) .FirstOrDefault(); // var conjunction = Restrictions.Conjunction(); // var criteria = NHibernateSessionManager.Instance.GetSession().CreateCriteria(typeof(SalaryScale)); // criteria.CreateAlias("SalarySteps", "SalarySteps") //.AddOrder(Order.Asc("SalarySteps.Annual")) //.SetFetchMode("SalarySteps", FetchMode.Eager); // conjunction.Add(Restrictions.Eq("TitleCode", titleCode)); // conjunction.Add(Restrictions.Eq("EffectiveDate", maxEffectiveDateForDate)); // criteria.Add(conjunction); // var ss = criteria.List<SalaryScale>().FirstOrDefault(); } if (salaryScale != null) { salaryScale.SalarySteps = repository.OfType <SalaryStep>() .Queryable .Where(s => s.TitleCode == salaryScale.TitleCode && s.EffectiveDate == salaryScale.EffectiveDate) .OrderBy(x => x.Annual) .ToList(); } } // Return the corresponding salary scale (or null if none were available for that title code). return(salaryScale); }
/// <summary> /// Set the lookups efficiently which are in the userLookupModel /// </summary> private static void SetLookups(UserLookupModel model, IRepository repository) { model.Applications = repository.OfType <Application>().Queryable.OrderBy(x => x.Name).Select( x => new KeyValuePair <int, string>(x.Id, x.Name)).ToList(); model.Units = repository.OfType <Unit>().Queryable.OrderBy(x => x.ShortName).Select( x => new KeyValuePair <int, string>(x.Id, x.ShortName)).ToList(); }
public static WorkgroupAccountModel Create(IRepository repository, Workgroup workgroup, WorkgroupAccount workgroupAccount = null) { Check.Require(repository != null, "repo null"); Check.Require(workgroup != null, "workgroup null"); var viewModel = new WorkgroupAccountModel { Workgroup = workgroup, WorkgroupAccount = workgroupAccount ?? new WorkgroupAccount() }; viewModel.WorkGroupPermissions = repository.OfType <WorkgroupPermission>().Queryable.Where(a => a.Workgroup == workgroup && (!a.IsAdmin || (a.IsAdmin && a.IsFullFeatured))).ToList(); viewModel.Accounts = workgroup.Organizations.SelectMany(x => x.Accounts).Distinct().ToList(); viewModel.Approvers = viewModel.WorkGroupPermissions.Where(x => x.Role.Id == Role.Codes.Approver).Select(x => x.User).Distinct().ToList(); viewModel.AccountManagers = viewModel.WorkGroupPermissions.Where(x => x.Role.Id == Role.Codes.AccountManager).Select(x => x.User).Distinct().ToList(); viewModel.Purchasers = viewModel.WorkGroupPermissions.Where(x => x.Role.Id == Role.Codes.Purchaser).Select(x => x.User).Distinct().ToList(); if (viewModel.WorkgroupAccount.Approver == null) { var approver = repository.OfType <WorkgroupPermission>().Queryable.SingleOrDefault( a => a.Workgroup == workgroup && a.Role.Id == Role.Codes.Approver && !a.IsAdmin && a.IsDefaultForAccount); if (approver != null) { viewModel.WorkgroupAccount.Approver = approver.User; } } if (viewModel.WorkgroupAccount.AccountManager == null) { var approver = repository.OfType <WorkgroupPermission>().Queryable.SingleOrDefault( a => a.Workgroup == workgroup && a.Role.Id == Role.Codes.AccountManager && !a.IsAdmin && a.IsDefaultForAccount); if (approver != null) { viewModel.WorkgroupAccount.AccountManager = approver.User; } } if (viewModel.WorkgroupAccount.Purchaser == null) { var approver = repository.OfType <WorkgroupPermission>().Queryable.SingleOrDefault( a => a.Workgroup == workgroup && a.Role.Id == Role.Codes.Purchaser && !a.IsAdmin && a.IsDefaultForAccount); if (approver != null) { viewModel.WorkgroupAccount.Purchaser = approver.User; } } return(viewModel); }
public static ReportViewModel Create(IRepository repository, string siteId) { Check.Require(repository != null, "Repository must be supplied"); var viewModel = new ReportViewModel { Seminars = repository.OfType <Seminar>().GetAll(), Seminar = SiteService.GetLatestSeminar(siteId), Site = siteId }; viewModel.Sites = repository.OfType <Site>().GetAll(); return(viewModel); }
public static QuestionViewModel Create(IRepository repository) { Check.Require(repository != null, "Repository is required."); var viewModel = new QuestionViewModel() { QuestionTypes = repository.OfType<QuestionType>().GetAll(), Validators = repository.OfType<Validator>().GetAll() }; return viewModel; }
public static WorkgroupAccountModel Create(IRepository repository, Workgroup workgroup, WorkgroupAccount workgroupAccount = null) { Check.Require(repository != null, "repo null"); Check.Require(workgroup != null, "workgroup null"); var viewModel = new WorkgroupAccountModel { Workgroup = workgroup, WorkgroupAccount = workgroupAccount ?? new WorkgroupAccount()}; viewModel.WorkGroupPermissions = repository.OfType<WorkgroupPermission>().Queryable.Where(a => a.Workgroup == workgroup && (!a.IsAdmin || (a.IsAdmin && a.IsFullFeatured))).ToList(); viewModel.Accounts = workgroup.Organizations.SelectMany(x => x.Accounts).Distinct().ToList(); viewModel.Approvers = viewModel.WorkGroupPermissions.Where(x => x.Role.Id == Role.Codes.Approver).Select(x => x.User).Distinct().ToList(); viewModel.AccountManagers = viewModel.WorkGroupPermissions.Where(x => x.Role.Id == Role.Codes.AccountManager).Select(x => x.User).Distinct().ToList(); viewModel.Purchasers = viewModel.WorkGroupPermissions.Where(x => x.Role.Id == Role.Codes.Purchaser).Select(x => x.User).Distinct().ToList(); if (viewModel.WorkgroupAccount.Approver == null) { var approver = repository.OfType<WorkgroupPermission>().Queryable.SingleOrDefault( a => a.Workgroup == workgroup && a.Role.Id == Role.Codes.Approver && !a.IsAdmin && a.IsDefaultForAccount); if (approver != null) { viewModel.WorkgroupAccount.Approver = approver.User; } } if (viewModel.WorkgroupAccount.AccountManager == null) { var approver = repository.OfType<WorkgroupPermission>().Queryable.SingleOrDefault( a => a.Workgroup == workgroup && a.Role.Id == Role.Codes.AccountManager && !a.IsAdmin && a.IsDefaultForAccount); if (approver != null) { viewModel.WorkgroupAccount.AccountManager = approver.User; } } if (viewModel.WorkgroupAccount.Purchaser == null) { var approver = repository.OfType<WorkgroupPermission>().Queryable.SingleOrDefault( a => a.Workgroup == workgroup && a.Role.Id == Role.Codes.Purchaser && !a.IsAdmin && a.IsDefaultForAccount); if (approver != null) { viewModel.WorkgroupAccount.Purchaser = approver.User; } } return viewModel; }
public static UnitViewModel Create(IRepository repository) { Check.Require(repository != null, "Repository must be supplied"); var viewModel = new UnitViewModel { Unit = new Unit(), Schools = repository.OfType <School>().Queryable.OrderBy(x => x.ShortDescription).ToList(), Units = repository.OfType <Unit>().Queryable.OrderBy(x => x.ShortName).ToList() }; return(viewModel); }
public static void BeginReportRequest(IRepository repository, HonorsPostModel honorsModel, string userId) { var parameters = new Dictionary<string, string>(); var reportName = "/Commencement/Honors"; parameters.Add("CollegeId", honorsModel.College.Id); parameters.Add("TermCode", honorsModel.TermCode); parameters.Add("Honors4590", honorsModel.Honors4590.ToString()); parameters.Add("HighHonors4590", honorsModel.HighHonors4590.ToString()); parameters.Add("HighestHonors4590", honorsModel.HighestHonors4590.ToString()); parameters.Add("Honors90135", honorsModel.Honors90135.ToString()); parameters.Add("HighHonors90135", honorsModel.HighHonors90135.ToString()); parameters.Add("HighestHonors90135", honorsModel.HighestHonors90135.ToString()); parameters.Add("Honors135", honorsModel.Honors135.ToString()); parameters.Add("HighHonors135", honorsModel.HighHonors135.ToString()); parameters.Add("HighestHonors135", honorsModel.HighestHonors135.ToString()); var hr = honorsModel.Convert(); hr.User = repository.OfType<vUser>().Queryable.FirstOrDefault(a => a.LoginId == userId); // start the transaction just so we can record the request using (var ts = new TransactionScope()) { // create the history object, plus this will also set the request date time repository.OfType<HonorsReport>().EnsurePersistent(hr); ts.CommitTransaction(); } // make the call to get the report, then save it and email the user using (var ts = new TransactionScope()) { // get the actual report itself hr.Contents = GetHonorsReport(parameters); //Get(reportName, parameters); // persist the object repository.OfType<HonorsReport>().EnsurePersistent(hr); ts.CommitTransaction(); // email the user //var message = new MailMessage(); //message.To.Add(hr.User.Email); //message.Subject = "Commencement - Honors Report Completed"; //message.Body = "Your honors report request has completed."; //message.IsBodyHtml = true; //// settings are set in the web.config //var client = new SmtpClient(); //client.Send(message); } }
public static AdminRegisterForStudentViewModel Create(IRepository repository, RegistrationModel registrationModel) { Check.Require(repository != null, "Repository is required."); Check.Require(registrationModel != null, "registrationModel is required."); var viewModel = new AdminRegisterForStudentViewModel() { RegistrationModel = registrationModel, Majors = repository.OfType<MajorCode>().GetAll(), Ceremonies = repository.OfType<Ceremony>().Queryable.Where(a=>a.TermCode == TermService.GetCurrent()).ToList(), }; return viewModel; }
public static SessionViewModel Create(IRepository repository, int seminarId, Session session = null) { Check.Require(repository != null, "Repository must be supplied"); var viewModel = new SessionViewModel { Session = session ?? new Session(), Seminar = repository.OfType <Seminar>().GetNullableById(seminarId), SessionTypes = repository.OfType <SessionType>().GetAll() }; viewModel.SessionTypesList = new SelectList(viewModel.SessionTypes, "Id", "Name", viewModel.Session.SessionType == null ? string.Empty : viewModel.Session.SessionType.Id); return(viewModel); }
public static AdminHomeViewModel Create(IRepository repository) { Check.Require(repository != null, "Repository is required."); var viewModel = new AdminHomeViewModel() { PendingApplications = repository.OfType <Application>().Queryable.Where(a => a.IsPending).Count(), PeopleMissingPicture = repository.OfType <Person>().Queryable.Where(a => a.OriginalPicture == null).Count(), FirmsRequiringReview = repository.OfType <Firm>().Queryable.Where(a => a.Review).Count() }; return(viewModel); }
public static AuthorizedViewModel Create(IRepository repository, string userId, string siteId) { Check.Require(repository != null, "Repository is required."); // load the user var user = repository.OfType <User>().Queryable.FirstOrDefault(a => a.LoweredUserName == userId.ToLower()); if (user == null) { throw new ArgumentException(string.Format("Unable to load user with id {0}", userId)); } var person = user.Person; // load seminar var seminar = SiteService.GetLatestSeminar(siteId); // has this person been invited to the current seminar? var invited = seminar.Invitations.Any(a => a.Person.User.LoweredUserName == userId.ToLower()); var viewModel = new AuthorizedViewModel() { Seminar = seminar, // only load application that applies to current seminar Application = user.Applications.FirstOrDefault(a => a.Seminar.Id == seminar.Id), SeminarPeople = person != null?person.SeminarPeople.Where(a => a.Seminar.Id != seminar.Id).ToList() : new List <SeminarPerson>(), SeminarPerson = person != null?person.SeminarPeople.FirstOrDefault(a => a.Seminar.Id == seminar.Id) : null, Person = person, Invited = invited }; return(viewModel); }
public static AdminExtraTicketPetitionViewModel Create(IRepository repository, ICeremonyService ceremonyService, IPetitionService petitionService, IPrincipal currentUser, TermCode termCode, int? ceremonyId, bool? viewAll) { Check.Require(repository != null, "Repository is required."); // set the default to false viewAll = viewAll ?? false; var ceremonies = ceremonyService.GetCeremonies(currentUser.Identity.Name, termCode); //var ceremonyIds = ceremonies.Select(a => a.Id).ToList(); var viewModel = new AdminExtraTicketPetitionViewModel() { Ceremonies = ceremonies, Ceremony = ceremonyId.HasValue ? repository.OfType<Ceremony>().GetNullableById(ceremonyId.Value) : null, ViewAll = viewAll.Value }; // has a ceremony been selected and does the current user have access if (ceremonyId.HasValue && ceremonyService.HasAccess(ceremonyId.Value, currentUser.Identity.Name)) { if (viewAll.Value) { viewModel.RegistrationParticipations = viewModel.Ceremony.RegistrationParticipations.Where(a => a.ExtraTicketPetition != null).ToList(); } else { viewModel.RegistrationParticipations = petitionService.GetPendingExtraTicket(currentUser.Identity.Name, ceremonyId.Value, termCode); } } return viewModel; }
public static AddEditorViewModel Create(IRepository repository, Template template, CallForProposal callForProposal) { Check.Require(repository != null, "Repository is required."); var viewModel = new AddEditorViewModel() { Template = template, CallForProposal = callForProposal, Users = repository.OfType<User>().Queryable.OrderBy(a => a.LastName).ToList() }; if (template != null) { viewModel.IsTemplate = true; viewModel.TemplateId = template.Id; } else if (callForProposal != null) { viewModel.IsCallForProposal = true; viewModel.CallForProposalId = callForProposal.Id; } Check.Require(viewModel.IsTemplate || viewModel.IsCallForProposal, "Must have either a template or a call for proposal"); return viewModel; }
public static RequirementViewModel Create(IRepository repository, Project project) { Check.Require(repository != null, "Repository must be supplied"); Check.Require(project != null, "project is required."); var viewModel = new RequirementViewModel { Requirement = new Requirement(), Project = project, RequirementTypes = repository.OfType<RequirementType>().GetAll(), PriorityTypes = repository.OfType<PriorityType>().GetAll(), RequirementCategories = project.RequirementCategories.Where(a => a.IsActive).ToList() }; return viewModel; }
public static IList <Department> GetAllForUser(IRepository repository, User user, bool isDepartmentUser, string sortPropertyName, bool isAscending) { Check.Require(repository != null, "Repository must be supplied"); var departments = new List <Department>(); if (isDepartmentUser) { /* * viewModel.SalaryReviewAnalysisResults = repository.OfType<SalaryReviewAnalysis>() * .Queryable.Fetch(y => y.Employee) * .Where(x => referenceNumbers.Contains(x.ReferenceNumber)) * .OrderBy(t => t.Employee.FullName) * .ToList(); * * depts = user.Units.Select(unit => unit.PPSCode).ToList(); */ // Works but accesses the database once for each department. //departments.AddRange(user.Units.Select(unit => repository.OfType<Department>() // .Queryable // .Where(d => d.Id.Equals(unit.PPSCode)) // .FirstOrDefault())); var units = user.Units.Select(u => u.PPSCode).ToArray(); departments = repository.OfType <Department>() .Queryable .Where(x => units.Contains(x.Id)) .ToList(); } else { var schoolsForUser = user.Units.Select(x => x.DeansOfficeSchoolCode).Distinct().ToArray(); departments = repository.OfType <Department>().Queryable.Where( x => schoolsForUser.Contains(x.DeansOfficeSchoolCode)).ToList(); } departments.Sort(); if (!isAscending) { departments.Reverse(); } return(departments); }
public static User GetByEmployeeId(IRepository repository, string employeeId) { Check.Require(repository != null, "Repository must be supplied"); return(repository.OfType <User>(). Queryable. Where(r => r.EmployeeID == employeeId) .FirstOrDefault()); }
public static EmailsForCallSendViewModel Create(IRepository repository, CallForProposal callForProposal) { Check.Require(repository != null, "Repository must be supplied"); var viewModel = new EmailsForCallSendViewModel {CallForProposal = callForProposal, Immediate = false}; viewModel.EmailsForCallList = repository.OfType<EmailsForCall>().Queryable.Where(a => a.CallForProposal != null && a.CallForProposal == callForProposal); return viewModel; }
public static EmailQueueListViewModel Create(IRepository repository, CallForProposal callForProposal) { Check.Require(repository != null, "Repository must be supplied"); var viewModel = new EmailQueueListViewModel{CallForProposal = callForProposal}; viewModel.EmailQueues = repository.OfType<EmailQueue>().Queryable.Where(a => a.CallForProposal == callForProposal); return viewModel; }
public static ActiveSurveyViewModel Create(IRepository repository, bool isPublic) { Check.Require(repository != null, "Repository must be supplied"); var viewModel = new ActiveSurveyViewModel { IsPublic = isPublic}; viewModel.Surveys = repository.OfType<Survey>().Queryable.Where(a => a.IsActive); return viewModel; }
public static AdminStudentViewModel Create(IRepository repository, IMajorService majorService, ICeremonyService ceremonyService, TermCode termCode, string studentid, string lastName, string firstName, string majorCode, string college, string userId) { Check.Require(repository != null, "Repository is required."); // build a list of majors that the current user has assigned to their ceremonies var ceremonies = ceremonyService.GetCeremonies(userId, TermService.GetCurrent()); var majors = ceremonies.SelectMany(a => a.Majors).Where(a => a.ConsolidationMajor == null && a.IsActive).ToList(); var colleges = ceremonies.SelectMany(a => a.Colleges).Distinct().ToList(); var viewModel = new AdminStudentViewModel() { MajorCodes = majors, studentidFilter = studentid, lastNameFilter = lastName, firstNameFilter = firstName, majorCodeFilter = majorCode, Colleges = colleges }; var query = repository.OfType<Student>().Queryable.Where(a => a.TermCode == termCode && (a.StudentId.Contains(string.IsNullOrEmpty(studentid) ? string.Empty : studentid.Trim())) && (a.LastName.Contains(string.IsNullOrEmpty(lastName) ? string.Empty : lastName.Trim())) && (a.FirstName.Contains(string.IsNullOrEmpty(firstName) ? string.Empty : firstName.Trim())) ); // get the list of students with optional filters var students = query.ToList(); if (colleges.Count == 1) { var coll = colleges.First(); students = students.Where(a => a.StrColleges.Contains(coll.Id)).ToList(); } if (!string.IsNullOrEmpty(majorCode)) students = students.Where(a => a.StrMajorCodes.Contains(majorCode)).ToList(); if (!string.IsNullOrEmpty(college)) students = students.Where(a => a.StrColleges.Contains(college)).ToList(); // get all active registrations var reg = repository.OfType<RegistrationParticipation>().Queryable.Where( a => a.Ceremony.TermCode == termCode).// && !a.Registration.Student.SjaBlock && !a.Registration.Cancelled). ToList(); var regStudents = reg.Select(a => a.Registration.Student); viewModel.StudentRegistrationModels = new List<StudentRegistrationModel>(); foreach(var s in students.Distinct().ToList()) { var reged = regStudents.Any(a => a == s); viewModel.StudentRegistrationModels.Add(new StudentRegistrationModel(s, reged)); } return viewModel; }
public static AutoApprovalViewModel Create(IRepository repository, string userName) { Check.Require(repository != null, "Repository must be supplied"); Check.Require(!string.IsNullOrWhiteSpace(userName), "user name"); var viewModel = new AutoApprovalViewModel { AutoApproval = new AutoApproval { IsActive = true, Expiration = DateTime.UtcNow.ToPacificTime().AddYears(1) } }; var workgroups = repository.OfType <WorkgroupPermission>().Queryable.Where(a => a.Role != null && a.Role.Id == Role.Codes.Approver && a.User != null && a.User.Id == userName && (!a.IsAdmin || (a.IsAdmin && a.IsFullFeatured))).Select(b => b.Workgroup).Distinct().ToList(); viewModel.Accounts = repository.OfType <WorkgroupAccount>().Queryable.Where(a => a.Approver != null && a.Approver.Id == userName && a.Account.IsActive).Select(b => b.Account).Distinct().ToList(); //workgroups.SelectMany(a => a.Accounts).Select(b => b.Account).Distinct().ToList(); viewModel.Users = workgroups.SelectMany(a => a.Permissions).Where(b => b.Role != null && b.Role.Id == Role.Codes.Requester).Select(c => c.User).Where(c => c.IsActive).Distinct().ToList(); return(viewModel); }
public static QuestionSetLinkViewModel Create(IRepository repository, string loginId) { Check.Require(repository != null, "Repository is required."); // get the user's colleges var user = repository.OfType<User>().Queryable.Where(x => x.LoginID == loginId).FirstOrDefault(); var colleges = (from x in user.Units select x.School).ToList(); var query = from x in repository.OfType<QuestionSet>().Queryable where (x.SystemReusable || colleges.Contains(x.School) || x.UserReusable && x.User.LoginID == loginId) && x.Name != StaticValues.QuestionSet_ContactInformation select x; var viewModel = new QuestionSetLinkViewModel() { QuestionSets = query }; return viewModel; }
public static MyTasksViewModel Create(IRepository repository, string loginId) { Check.Require(repository != null, "repository is required."); var tasks = repository.OfType<Task>().Queryable.Where(a => a.Worker.LoginId == loginId && !a.Complete); var projects = tasks.Where(a => !a.Complete ).Select(a => a.Project).Distinct(); var viewModel = new MyTasksViewModel() {Tasks = tasks, Projects = projects}; return viewModel; }
public static TransferRequestViewModel Create(IRepository repository, RegistrationParticipation registrationParticipation, string username, TransferRequest transferRequest = null) { var viewModel = new TransferRequestViewModel() { Ceremonies = repository.OfType<Ceremony>().Queryable.Where(a => a.TermCode == TermService.GetCurrent()), RegistrationParticipation = registrationParticipation, TransferRequest = transferRequest ?? new TransferRequest() }; return viewModel; }
public static EmailsForCallListViewModel Create(IRepository repository, int? templateId, int? callForProposalId) { Check.Require(repository != null, "Repository must be supplied"); var viewModel = new EmailsForCallListViewModel(); if (templateId != null && templateId != 0) { viewModel.IsTemplate = true; viewModel.EmailsForCallList = repository.OfType<EmailsForCall>().Queryable.Where(a => a.Template != null && a.Template.Id == templateId); viewModel.TemplateId = templateId; } else if (callForProposalId != null && callForProposalId != 0) { viewModel.IsCallForProposal = true; viewModel.EmailsForCallList = repository.OfType<EmailsForCall>().Queryable.Where(a => a.CallForProposal != null && a.CallForProposal.Id == callForProposalId); viewModel.CallForProposalId = callForProposalId; } return viewModel; }
public static CreateReportViewModel Create(IRepository repository, Item item) { Check.Require(repository != null, "Repository is required."); var viewModel = new CreateReportViewModel() {Item = item}; viewModel.QuestionTypeNoAnswer = repository.OfType<QuestionType>().Queryable.Where(a => a.Name == QuestionTypeText.STR_NoAnswer). FirstOrDefault(); return viewModel; }
public static TermcodeViewModel Create(IRepository Repository) { var viewModel = new TermcodeViewModel(); var termCodes = Repository.OfType<TermCode>().Queryable.OrderByDescending(a => a.IsActive).ThenBy(a => a.Id); viewModel.AllTermCodes = termCodes.Select(a => new TermCodeUnion {IsActive = a.IsActive, IsInTermCode = true, Name = a.Name, TermCodeId = a.Id, RegistrationBegin = a.RegistrationBegin, RegistrationDeadline = a.RegistrationDeadline}).ToList(); viewModel.VTermCodes = Repository.OfType<vTermCode>().Queryable.Where(a => a.StartDate >= DateTime.UtcNow.ToPacificTime()) .ToList(); var count = 0; foreach (var vTermCode in viewModel.VTermCodes.Where(vTermCode => !viewModel.AllTermCodes.AsQueryable().Where(a => a.TermCodeId == vTermCode.Id).Any())) { viewModel.AllTermCodes.Add(new TermCodeUnion(){IsActive = false, IsInTermCode = false, Name = vTermCode.Description, TermCodeId = vTermCode.Id}); count++; if (count >= 3) { break; } } return viewModel; }
public static ApplicationViewModel Create(IRepository repository) { Check.Require(repository != null, "Repository must be supplied"); var viewModel = new ApplicationViewModel { Application = new Application(), Roles = repository.OfType <Role>().Queryable.OrderBy(x => x.Name).ToList() }; return(viewModel); }
public static TemplateViewModel Create(IRepository repository, Template template = null) { Check.Require(repository != null, "Repository must be supplied"); var viewModel = new TemplateViewModel { Template = template ?? new Template(), NotificationTypes = repository.OfType <NotificationType>().GetAll() }; return(viewModel); }
public static EmailStudentsViewModel Create(IRepository repository, ICeremonyService ceremonyService, string userId, List<string> templateNames ) { Check.Require(repository != null, "Repository is required."); var viewModel = new EmailStudentsViewModel() { Ceremonies = ceremonyService.GetCeremonies(userId, TermService.GetCurrent()), TemplateTypes = repository.OfType<TemplateType>().Queryable.Where(a => templateNames.Contains(a.Name)).ToList() }; return viewModel; }
public static ExtendedPropertyViewModel Create(IRepository repository, ItemType itemType) { Check.Require(repository != null, "Repository is required."); var viewModel = new ExtendedPropertyViewModel() { QuestionTypes = repository.OfType<QuestionType>().Queryable.Where(a => a.ExtendedProperty).ToList(), ItemType = itemType }; return viewModel; }
public static MessageViewModel Create(IRepository repository) { Check.Require(repository != null, "Repository must be supplied"); var viewModel = new MessageViewModel { Message = new Message() }; viewModel.Applications = repository.OfType <Application>().Queryable.OrderBy(x => x.Name).ToList(); return(viewModel); }
public static SalaryScaleViewModel Create(IRepository repository, string titleCode, string effectiveDate, User user) { Check.Require(repository != null, "Repository must be supplied"); var viewModel = new SalaryScaleViewModel { SalaryScale = new SalaryScale(), Titles = repository.OfType <Title>() .Queryable .OrderBy(t => t.AbbreviatedName) // .ThenBy(t => t.TitleCode) .ToList() }; viewModel.TitleCodes = viewModel.Titles .OrderBy(t => t.TitleCode) .ToList(); if (!String.IsNullOrEmpty(titleCode)) { var searchDate = DateTime.Now; if (effectiveDate != null) { DateTime.TryParse(effectiveDate, out searchDate); } var salaryScale = SalaryScale.GetEffectiveSalaryScale(repository, titleCode, searchDate); if (salaryScale != null) { viewModel.SalaryScale = salaryScale; } viewModel.TitleCode = titleCode; var schoolsForUser = user.Units.Select(x => x.DeansOfficeSchoolCode).Distinct().ToArray(); viewModel.CollegeAverages = repository.OfType <CollegeAverage>().Queryable.Where(x => schoolsForUser.Contains(x.SchoolCode) && x.TitleCode == viewModel.TitleCode). ToList(); } return(viewModel); }
public static IList <User> GetAll(IRepository repository, User user, bool isDepartmentUser) { Check.Require(repository != null, "Repository must be supplied"); // var units = new List<Unit>(); List <int> unitIds; var users = new List <User>(); if (isDepartmentUser) { // Get list of all user's departments assigned in Catbert: //units = user.Units.ToList(); unitIds = user.Units.Select(unit => unit.Id).ToList(); } else { // Get distinct list of user's deans office schools based on Catbert school code(s): var schoolsForUser = user.Units.Select(x => x.DeansOfficeSchoolCode).Distinct().ToArray(); // Get list of all departments in the user's deans office school(s): //units = repository.OfType<Unit>().Queryable.Where(x => schoolsForUser.Contains(x.DeansOfficeSchoolCode)).ToList(); unitIds = repository.OfType <Unit>().Queryable.Where(x => schoolsForUser.Contains(x.DeansOfficeSchoolCode)).Select(x => x.Id).ToList(); } // we have to get the all users associated with those units: //TODO: Try implementing with LINQ and lambda expressions var criteria = NHibernateSessionManager.Instance.GetSession().CreateCriteria(typeof(User)); criteria.CreateAlias("Units", "Units") .AddOrder(Order.Asc("LastName")).AddOrder(Order.Asc("FirstName")) .SetResultTransformer(new DistinctRootEntityResultTransformer()); var conjunction = Restrictions.Conjunction(); conjunction.Add(Restrictions.In("Units.Id", unitIds)); criteria.Add(conjunction); return(criteria.List <User>().ToList()); //foreach (var unit in units) //{ // users.AddRange(unit.Users); // //departments.AddRange(user.Units.Select(unit => repository.OfType<Department>() // // .Queryable // // .Where(d => d.Id.Equals(unit.PPSCode)) // // .FirstOrDefault())); //} //return users.Distinct().OrderBy(x => x.FullName).ToList(); }
public static AdminEditStudentViewModel Create(IRepository repository, ICeremonyService ceremonyService, Student student, string userId) { Check.Require(repository != null, "Repository is required."); var viewModel = new AdminEditStudentViewModel() { Student = student, Majors = repository.OfType<MajorCode>().Queryable.Where(a => a.IsActive).OrderBy(a => a.Name).ToList(), Ceremonies = ceremonyService.GetCeremonies(userId, TermService.GetCurrent()) }; return viewModel; }
public static NotificationTrackingViewModel Create(IRepository repository, string siteId, NotificationTracking notificationTracking = null, Person person = null, MailingList mailingList = null) { Check.Require(repository != null, "Repository is required."); var seminar = SiteService.GetLatestSeminar(siteId); var viewModel = new NotificationTrackingViewModel(){ NotificationTracking = notificationTracking ?? new NotificationTracking(), NotificationMethods = repository.OfType<NotificationMethod>().GetAll(), NotificationTypes = repository.OfType<NotificationType>().GetAll(), People = new List<Person>(), AllPeople = SiteService.GetLatestSeminar(siteId).SeminarPeople.Select(a => a.Person).ToList(),//seminarService.GetCurrent().SeminarPeople.Select(a=>a.Person).ToList(), SitePeople = SiteService.LoadSite(siteId).People, Seminar = seminar, MailingLists = seminar.MailingLists, MailingList = mailingList }; if (person != null) viewModel.People.Add(person); return viewModel; }
public static AddEditorViewModel Create(IRepository repository, Ceremony ceremony) { Check.Require(repository != null, "Repository is required."); Check.Require(ceremony != null, "ceremony is required."); var viewModel = new AddEditorViewModel() { Ceremony = ceremony, Users = repository.OfType<vUser>().Queryable.OrderBy(a => a.LastName).ToList() }; return viewModel; }
public static HelpTopicViewModel Create(IRepository repository, IPrincipal currentUser) { Check.Require(repository != null, "Repository is required."); var viewModel = new HelpTopicViewModel(); viewModel.IsUserAuthorized = currentUser.IsInRole(RoleNames.Admin) || currentUser.IsInRole(RoleNames.User); viewModel.IsUserAdmin = currentUser.IsInRole(RoleNames.Admin); if(viewModel.IsUserAdmin) { viewModel.HelpTopics = repository.OfType<HelpTopic>().Queryable; } else if(viewModel.IsUserAuthorized) { viewModel.HelpTopics = repository.OfType<HelpTopic>().Queryable.Where(a => a.IsActive); } else { viewModel.HelpTopics = repository.OfType<HelpTopic>().Queryable.Where(a => a.AvailableToPublic && a.IsActive).OrderByDescending(a => a.NumberOfReads); } return viewModel; }
public static ProjectViewModel Create(IRepository repository, string login) { Check.Require(repository != null, "Repository must be supplied"); var worker = repository.OfType<Worker>().Queryable.Where(a => a.LoginId == login).First(); var viewModel = new ProjectViewModel { Project = new Project(), StatusCodes = repository.OfType<StatusCode>().GetAll(), ProjectTypes = repository.OfType<ProjectType>().Queryable.Where(a=>a.IsActive).OrderBy(a=>a.Order).ToList(), PriorityTypes = repository.OfType<PriorityType>().Queryable.OrderBy(a=>a.Order).ToList(), Workgroups = worker.WorkgroupWorkers.Where(a=>a.Workgroup.IsActive).Select(a=>a.Workgroup).ToList(), }; var workers = new List<Worker>(); foreach (var a in viewModel.Workgroups) { workers.AddRange(a.WorkgroupWorkers.Select(b=>b.Worker).ToList()); } viewModel.Workers = workers.Distinct().OrderBy(a => a.LastName).ToList(); return viewModel; }
public static AdminPersonViewModel Create(IRepository repository, IFirmService firmService, string siteId, int?seminarId, Person person = null, string email = null) { Check.Require(repository != null, "Repository is required."); var seminar = seminarId.HasValue ? repository.OfType <Seminar>().GetNullableById(seminarId.Value) : null; var viewModel = new AdminPersonViewModel() { PersonViewModel = PersonViewModel.Create(repository, firmService, siteId, seminar, person, email), SeminarRoles = repository.OfType <SeminarRole>().Queryable, RoomTypes = repository.OfType <RoomType>().Queryable.Where(a => a.IsActive), SeminarId = seminarId, Invited = SiteService.GetLatestSeminar(siteId).Invitations.Where(a => a.Person == person).Any(), SiteId = siteId }; // determine if last reg is the current seminar if (seminar != null) { viewModel.IsCurrentSeminar = seminar.Id == SiteService.GetLatestSeminar(siteId).Id; } return(viewModel); }
public static ChangeCeremonyViewModel Create(IRepository repository, Registration registration) { Check.Require(repository != null, "Repository is not required."); Check.Require(registration != null, "Registration is not required."); var viewModel = new ChangeCeremonyViewModel() { Ceremonies = repository.OfType<Ceremony>().Queryable.Where(a=>a.TermCode == TermService.GetCurrent()), Student = registration.Student, Registration = registration }; return viewModel; }
public static TemplateCreateViewModel Create(IRepository repository, Template template, Ceremony ceremony) { Check.Require(repository != null, "Repository is required."); Check.Require(ceremony != null, "ceremony is required."); var viewModel = new TemplateCreateViewModel() { TemplateTypes = repository.OfType<TemplateType>().Queryable.OrderBy(a => a.Name), Template = template, Ceremony = ceremony }; return viewModel; }
public static AdminPersonViewModel Create(IRepository repository, IFirmService firmService, string siteId, int? seminarId, Person person = null, string email = null) { Check.Require(repository != null, "Repository is required."); var seminar = seminarId.HasValue ? repository.OfType<Seminar>().GetNullableById(seminarId.Value) : null; var viewModel = new AdminPersonViewModel() { PersonViewModel = PersonViewModel.Create(repository, firmService, siteId, seminar, person, email), SeminarRoles = repository.OfType<SeminarRole>().Queryable, RoomTypes = repository.OfType<RoomType>().Queryable.Where(a=>a.IsActive), SeminarId = seminarId, Invited = SiteService.GetLatestSeminar(siteId).Invitations.Where(a => a.Person == person).Any(), SiteId = siteId }; // determine if last reg is the current seminar if (seminar != null) { viewModel.IsCurrentSeminar = seminar.Id == SiteService.GetLatestSeminar(siteId).Id; } return viewModel; }
public static SessionPersonViewModel Create(IRepository repository, Session session, SeminarPerson seminarPerson = null) { Check.Require(repository != null, "Repository is required."); var seminar = repository.OfType <Seminar>().GetNullableById(session.Seminar.Id); var viewModel = new SessionPersonViewModel() { SeminarPeople = seminar.SeminarPeople, Session = session, SeminarPerson = seminarPerson ?? new SeminarPerson() }; return(viewModel); }
public static SessionPersonViewModel Create(IRepository repository, Session session, SeminarPerson seminarPerson = null) { Check.Require(repository != null, "Repository is required."); var seminar = repository.OfType<Seminar>().GetNullableById(session.Seminar.Id); var viewModel = new SessionPersonViewModel() { SeminarPeople = seminar.SeminarPeople, Session = session, SeminarPerson = seminarPerson ?? new SeminarPerson() }; return viewModel; }
// This method contains the logic, which resolves the originating department // based on the user provided. Currently it's set to the user's home department. public static Department GetOriginatingDepartmentForUser(IRepository repository, string value) { Check.Require(repository != null, "Repository must be supplied"); Department retval = null; if (String.IsNullOrEmpty(value) == false) { var user = repository.OfType <UCDEmployee>().Queryable.Where(x => x.EmployeeID.Equals(value)).FirstOrDefault(); if (user != null) { retval = user.HomeDepartment; } } return(retval); }
/// <summary> /// This will populate an Employee drop-down list based on a user and if they're a department user. /// It will return all employees in the user's unit(s) if they're a department user, otherwise all /// employees in the user's deans office school(s). /// </summary> /// <param name="repository"></param> /// <param name="user"></param> /// <param name="isDepartmentUser"></param> /// <param name="sortPropertyName"></param> /// <param name="isAscending"></param> /// <returns>Employees list containing all employees in the user's unit(s) if they're a department user, otherwise all employees in the user's deans office school(s).</returns> public static IList <Employee> GetAllForUser(IRepository repository, User user, bool?isDepartmentUser, string sortPropertyName, bool isAscending) { List <String> depts; //employeeSalaryComparisonModel.DepartmentsList = Department.GetAllForUser(Repository, user, isDepartmentUser, "Name", true); // A null value for isDepartmentUser parameter defaults to false: if ((bool)(isDepartmentUser ?? false)) { // Get list of all user's departments assigned in Catbert: depts = user.Units.Select(unit => unit.PPSCode).ToList(); } else { // Get distinct list of user's deans office schools based on Catbert school code(s): var schoolsForUser = user.Units.Select(x => x.DeansOfficeSchoolCode).Distinct().ToArray(); // Get list of all departments in the user's deans office school(s): depts = repository.OfType <Department>().Queryable.Where(x => schoolsForUser.Contains(x.DeansOfficeSchoolCode)).Select(x => x.Id).ToList(); } return(GetAll(sortPropertyName, isAscending, null, null, depts.ToArray())); }
public static ProfileViewModel Create(IRepository repository, IFirmService firmService, string userId, string site) { Check.Require(repository != null, "Repository must be supplied"); Check.Require(firmService != null, "firmService is required."); var user = repository.OfType <User>().Queryable.Where(a => a.LoweredUserName == userId.ToLower()).FirstOrDefault(); Check.Require(user != null, "user is required."); var person = user.Person; Check.Require(person != null, "person is required."); var seminarPerson = person.GetLatestRegistration(site); var viewModel = new ProfileViewModel() { Firm = seminarPerson.Firm, SeminarPerson = seminarPerson, Person = person }; return(viewModel); }
//public IList<Title> TitleCodesList { get; set; } //public static EmployeeSalaryComparisonViewModel Create(IRepository repository) //{ // return EmployeeSalaryComparisonViewModel.Create(repository, null); //} public static EmployeeSalaryComparisonViewModel Create(IRepository repository, User user, bool isDepartmentUser, SalaryScaleViewModel salaryScaleViewModel) { Check.Require(repository != null, "Repository must be supplied"); var anyDepartment = new Department() { Name = "Any", DepartmentNumber = "Any" }; var anyTitle = new Title() { AbbreviatedName = "Any", PayrollTitle = "Any", TitleCode = "Any" }; var anyEmployee = new Employee() { FullName = "Any", EmployeeID = "0" }; if (salaryScaleViewModel == null) { salaryScaleViewModel = Models.SalaryScaleViewModel.Create(repository); } var viewModel = new EmployeeSalaryComparisonViewModel { IsDepartmentUser = isDepartmentUser, SalaryScaleViewModel = salaryScaleViewModel, Employee = new Employee(), Employees = new List <Employee>(), SelectedDepartments = new List <Department>(), SelectedTitles = new List <Title>(), SelectedDepartmentCodesString = string.Empty, SelectedTitleCodesString = string.Empty, SelectedEmployee = anyEmployee, SelectedEmployeeId = string.Empty }; if (salaryScaleViewModel.Titles.Count == 0) { viewModel.TitlesList = repository.OfType <Title>() .Queryable .OrderBy(t => t.TitleCode) .ToList(); } else { viewModel.TitlesList = salaryScaleViewModel.Titles; } if (user == null) { user = Core.Domain.User.GetByLoginId(repository, HttpContext.Current.User.Identity.Name); } viewModel.User = user; var allSchoolDepartments = Department.GetAllForUser(repository, user, false, "Name", true); IList <Department> usersDepartmentsList; if (isDepartmentUser) { var usersUnits = user.Units.Select(u => u.PPSCode).ToArray(); usersDepartmentsList = allSchoolDepartments .Where(x => usersUnits.Contains(x.Id)) .ToList(); } else { usersDepartmentsList = allSchoolDepartments; } viewModel.DepartmentsList = usersDepartmentsList; // 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()); //var allSchoolEmployees = SchoolEmployees.GetAllForSchoolCodes(repository, // allSchoolDepartments.Select( // x => x.DeansOfficeSchoolCode).Distinct(). // ToArray()); viewModel.AllSchoolEmployees = allSchoolEmployees; // Assign only those with IsDepartmentEmployee == true to Employees select list or ALL school employees is non-department user, i.e. deans office. viewModel.EmployeesList = isDepartmentUser ? allSchoolEmployees.Where(x => x.IsDepartmentEmployee == true).ToList() : allSchoolEmployees; viewModel.SelectedDepartments.Add(anyDepartment); viewModel.SelectedTitles.Add(anyTitle); return(viewModel); }
/// <summary> /// This is the main get employees method used for populating Employees data table: /// It takes into consideration IsDepartmentUser and the logged in user /// when building the Employees list. /// It will put the non-department employees at the bottom of the list /// if the sort order is FullName or HomeDepartment. /// It is also used by _ExportToExcel indirectly. /// </summary> /// <param name="repository"></param> /// <param name="user"></param> /// <param name="isDepartmentUser"></param> /// <param name="sortPropertyName"></param> /// <param name="isAscending"></param> /// <param name="titleCodes"></param> /// <param name="pkEmployee"></param> /// <param name="departmentIds"></param> /// <returns>Employees list with non-department employees at the bottom of the list if the sort order is FullName or HomeDepartment.</returns> public static IList <Employee> GetAllForEmployeeTable(IRepository repository, User user, bool isDepartmentUser, string sortPropertyName, bool isAscending, string[] titleCodes, string pkEmployee, string[] departmentIds) { Check.Require(repository != null, "Repository must be supplied"); if (isDepartmentUser && String.IsNullOrEmpty(sortPropertyName) == false && sortPropertyName.Equals("FullName")) { sortPropertyName = "FullName"; // Default sort by FullName } if (String.IsNullOrEmpty(sortPropertyName)) { sortPropertyName = "FullName"; } var depts = departmentIds; IList <Employee> employees; if (depts != null && !String.IsNullOrEmpty(depts[0])) { // Get employees list based on filter parameters provided: employees = GetAll(sortPropertyName, isAscending, titleCodes, pkEmployee, depts); } else { var schoolsForUser = user.Units.Select(x => x.DeansOfficeSchoolCode).Distinct().ToArray(); // Get list of all departments in the user's deans office school(s): depts = repository.OfType <Department>().Queryable.Where( x => schoolsForUser.Contains(x.DeansOfficeSchoolCode)). Select(x => x.Id).ToArray(); // Get employees based on deans office school departments and any other filter parameters provided: employees = GetAll(sortPropertyName, isAscending, titleCodes, pkEmployee, depts); } //// This will be the sorted employee list returned: //List<Employee> retval = null; //if (isDepartmentUser) //{ // // Then set the employee's IsDepartmentEmployee so that the View can determine // // how to display or blank out the Name, department and comments from non-departmental employees: // var nullList = new List<Employee>(); // retval = new List<Employee>(); // foreach (var employee in employees) // { // try // { // employee.IsDepartmentEmployee = true; // if (!ComputeIsDepartmentEmployee(user, employee)) // { // // Set the employee's IsDepartmentEmployee to // // allow view to decide how to "blank out" fields. // employee.IsDepartmentEmployee = false; // if (sortPropertyName.Equals("FullName") || sortPropertyName.Equals("HomeDepartment") || sortPropertyName.Equals("Title")) // { // // if sorted by FullName, add these employees to their own array. // nullList.Add(employee); // } // else // { // // otherwise just add them to the return array. // retval.Add(employee); // } // } // else // { // // add them as-is to the return array. // retval.Add(employee); // } // } // catch (System.Exception ex) // { // System.Console.Out.WriteLine(ex.InnerException); // } // } // if (sortPropertyName.Equals("FullName")) // { // // sort by FullName // retval.Sort(); // if (!isAscending) // { // retval.Reverse(); // } // retval.AddRange(nullList); // } // else if (sortPropertyName.Equals("HomeDepartment")) // { // // Sort by Departments, then by FullNames within individual departments: // retval.Sort(isAscending // ? Employee.sortHomeDepartmentAscending() // : Employee.sortHomeDepartmentDescending()); // retval.AddRange(nullList); // } // else if (sortPropertyName.Equals("Title")) // { // retval.Sort(isAscending ? Employee.sortTitleAscending() : Employee.sortTitleDescending()); // retval.AddRange(nullList); // } // else // { // retval.AddRange(nullList); // } //} //else //{ // // Otherwise, return the employees list as-is: // retval = employees as List<Employee>; //} //return retval; return(SetIsDepartmentEmployeeAndSort(employees, user, isDepartmentUser, sortPropertyName, isAscending)); }
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); }
/// <summary> /// Given a repository, employee ID, proposed title (optional) and user /// or repository, reference number, and user, /// Create a Salary Analysis Editor View model. /// </summary> /// <param name="repository">Database IRepository context</param> /// <param name="selectedEmployeeId">Employee ID of the employee for which to perform a new salary review analysis upon</param> /// <param name="proposedTitle">The proposed title to be used in conjunction with performing for a reclassification review; otherwise, null when performing an equity review</param> /// <param name="referenceNumber">The Salary Review Analysis reference number to be used for looking up an existing analysis</param> /// <param name="user">The logged in user either creating a new or viewing an existing analysis. Used for determining which college average(s) to display on the associated Salary Scale</param> /// <returns>A SalaryReviewAnalysisEditorViewModel populated according to the parameters provided</returns> public static SalaryReviewAnalysisEditorViewModel Create(IRepository repository, string selectedEmployeeId, string proposedTitle, string referenceNumber, User user) { Check.Require(repository != null, "Repository must be supplied"); var viewModel = new SalaryReviewAnalysisEditorViewModel { ProposedTitles = repository.OfType <Title>() .Queryable .OrderBy(t => t.AbbreviatedName) // .ThenBy(t => t.TitleCode) .ToList(), //SelectionTypes = repository.OfType<SelectionType>() //.Queryable //.Where(x => x.ShortType != "Step") //.OrderBy(s => s.SortOrder) //.ToList(), ReportDate = DateTime.Today }; var salaryScaleViewModel = new SalaryScaleViewModel(); SalaryReviewAnalysis salaryReviewAnalysis = null; SalaryScale salaryScale = null; string titleCode = null; // This title code is used in conjunction with determining colleges averages. if (!String.IsNullOrEmpty(referenceNumber) || !String.IsNullOrEmpty(selectedEmployeeId)) { // Assumes either an employee ID or reference number was provided. // We should always get here unless someone bypassed the menu page and entered a URL directly into // a web browser with some or all parameters missing. if (String.IsNullOrEmpty(referenceNumber)) { // Then an employee ID and proposed title for reclassification (optional) was provided viewModel.ReportDate = DateTime.Today; viewModel.SelectedEmployee = repository.OfType <Employee>() .Queryable .Where(e => e.id.Equals(selectedEmployeeId)) .FirstOrDefault(); salaryReviewAnalysis = new SalaryReviewAnalysis { DateInitiated = DateTime.Today }; var scenarios = new List <Scenario>(); var scenario = new Scenario { SalaryReviewAnalysis = salaryReviewAnalysis, ScenarioNumber = 1, SelectionType = "None", PercentIncrease = 0, Approved = false, SalaryAmount = viewModel.SelectedEmployee.PayRate }; scenarios.Add(scenario); salaryReviewAnalysis.Scenarios = scenarios; viewModel.SalaryReviewAnalysis = salaryReviewAnalysis; viewModel.SraEmployee = new SRAEmployee(viewModel.SelectedEmployee); salaryScale = new SalaryScale(); if (string.IsNullOrEmpty(proposedTitle) == false && !viewModel.SelectedEmployee.TitleCode.Equals(proposedTitle)) { // Then the optional proposed title was provided so this is a reclassification review. titleCode = proposedTitle; viewModel.SalaryReviewAnalysis.IsReclass = true; viewModel.ProposedTitle = repository.OfType <Title>() .Queryable .Where(p => p.TitleCode.Equals(proposedTitle)) .FirstOrDefault(); //salaryScale = repository.OfType<SalaryScale>() // .Queryable // .Where(r => r.TitleCode == proposedTitle) // .FirstOrDefault(); salaryScale = SalaryScale.GetEffectiveSalaryScale(repository, proposedTitle, DateTime.Today); viewModel.SalaryReviewAnalysis.Title = viewModel.ProposedTitle; } else { // Else this is a standard equity review. titleCode = viewModel.SelectedEmployee.TitleCode; //salaryScale = repository.OfType<SalaryScale>() // .Queryable // .Where(r => r.TitleCode == viewModel.SelectedEmployee.TitleCode) // .FirstOrDefault(); salaryScale = SalaryScale.GetEffectiveSalaryScale(repository, viewModel.SelectedEmployee.TitleCode, DateTime.Today); viewModel.SalaryReviewAnalysis.Title = viewModel.SelectedEmployee.Title; } } else if (!String.IsNullOrEmpty(referenceNumber)) { // Reference number is present so try getting existing review by reference number: viewModel.SalaryReviewAnalysis = repository.OfType <SalaryReviewAnalysis>() .Queryable .Where(x => x.ReferenceNumber.Equals(referenceNumber)) .FirstOrDefault(); if (viewModel.SalaryReviewAnalysis != null) { titleCode = viewModel.SalaryReviewAnalysis.SalaryScale.TitleCode; viewModel.SraEmployee = viewModel.SalaryReviewAnalysis.Employee; viewModel.ProposedTitle = (viewModel.SalaryReviewAnalysis.IsReclass ? viewModel.SalaryReviewAnalysis.Title : null); salaryScale = SalaryScale.GetEffectiveSalaryScale(repository, viewModel.SalaryReviewAnalysis.SalaryScale.TitleCode, viewModel.SalaryReviewAnalysis.SalaryScale.EffectiveDate); } } if (salaryScale != null) { // Determine the user's school(s) var schoolsForUser = user.Units.Select(x => x.DeansOfficeSchoolCode).Distinct().ToArray(); // and populate the corresponding college averages: salaryScaleViewModel.CollegeAverages = repository.OfType <CollegeAverage>().Queryable.Where(x => schoolsForUser.Contains(x.SchoolCode) && x.TitleCode == titleCode). ToList(); var employeesSchoolCode = viewModel.SraEmployee.HomeDepartment.SchoolCode; var collegeAverage = salaryScaleViewModel.CollegeAverages.Where(x => x.SchoolCode.Equals(employeesSchoolCode)).Select(x => x.CollegeAverageAnnual). FirstOrDefault(); viewModel.CriteriaList = SalaryReviewAnalysis.GetCriteriaList(repository, salaryScale, collegeAverage); salaryScaleViewModel.SalaryScale = salaryScale; } } viewModel.SalaryScaleViewModel = salaryScaleViewModel; 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); }
public static ApplicationViewModel Create(IRepository repository, IFirmService firmService, string userId, string siteId, Application application = null, bool seminarTerms = false) { Check.Require(repository != null, "Repository must be supplied"); var viewModel = new ApplicationViewModel { Application = application ?? new Application(), // always get the latest Seminar = SiteService.GetLatestSeminar(siteId), //Commodities = repository.OfType<Commodity>().Queryable.Where(a=>a.IsActive).OrderBy(a=>a.Name).ToList(), Countries = repository.OfType <Country>().GetAll(), CommunicationOptions = repository.OfType <CommunicationOption>().GetAll(), SeminarTerms = seminarTerms }; // load commodities var commodities = repository.OfType <Commodity>().Queryable.Where(a => a.IsActive).OrderBy(a => a.Name).ToList(); viewModel.Commodities = commodities; // load the firm types var firmTypes = repository.OfType <FirmType>().Queryable.Where(a => a.IsActive).OrderBy(a => a.Name).ToList(); viewModel.FirmTypes = firmTypes; var user = repository.OfType <User>().Queryable.FirstOrDefault(a => a.LoweredUserName == userId.ToLower()); if (user == null) { throw new ArgumentException(string.Format("Unable to load user with userid {0}.", userId)); } // populate the application with person info var person = user.Person; // if person is not null, there should be at least one registration (seminar person) if (person != null) { viewModel.PersonId = person.Id; viewModel.Application.FirstName = person.FirstName; viewModel.Application.MI = person.MI; viewModel.Application.LastName = person.LastName; viewModel.Application.BadgeName = person.BadgeName; viewModel.Application.CommunicationOption = person.CommunicationOption; viewModel.Application.ContactInformationRelease = person.ContactInformationRelease; // get latest seminar information var reg = person.GetLatestRegistration(siteId); if (reg != null) { viewModel.Application.JobTitle = reg.Title; } // copy assistant information var assistant = person.Contacts.FirstOrDefault(a => a.ContactType.Id == 'A'); if (assistant != null) { viewModel.Application.AssistantEmail = assistant.Email; viewModel.Application.AssistantFirstName = assistant.FirstName; viewModel.Application.AssistantLastName = assistant.LastName; viewModel.Application.AssistantPhone = assistant.Phone; } var seminarPeople = person.GetLatestRegistration(siteId); if (seminarPeople != null) { viewModel.Application.Firm = seminarPeople.Firm; } viewModel.Application.FirmPhone = person.Phone; viewModel.Application.FirmPhoneExt = person.PhoneExt; var address = person.Addresses.FirstOrDefault(a => a.AddressType.Id == 'B'); if (address != null) { viewModel.Application.FirmAddressLine1 = address.Line1; viewModel.Application.FirmAddressLine2 = address.Line2; viewModel.Application.FirmCity = address.City; viewModel.Application.FirmState = address.State; viewModel.Application.FirmZip = address.Zip; viewModel.Application.Country = address.Country; } } viewModel.HasPhoto = user.Person != null && user.Person.MainProfilePicture != null; // get the firms and add the "Other" option //var firms = new List<Firm>(firmService.GetAllFirms()); //firms = firms.Where(a=>!a.Review && a.Name != "Other (Not Listed)").OrderBy(a=>a.Name).ToList(); var tmpFirms = firmService.GetAllFirms(); var firms = new List <Firm>(); firms.Add(tmpFirms.First(a => a.Name == "Other (Not Listed)")); firms.AddRange(tmpFirms.Where(a => !a.Review && a.Name != "Other (Not Listed)").OrderBy(a => a.Name).ToList()); viewModel.Firms = firms; return(viewModel); }
public static PersonViewModel Create(IRepository repository, IFirmService firmService, string site, Seminar seminar = null, Person person = null, string email = null, Firm firm = null) { Check.Require(repository != null, "Repository must be supplied"); var viewModel = new PersonViewModel() { Person = person ?? new Person(), Addresses = repository.OfType <AddressType>().Queryable.Select(a => new Address() { AddressType = a }).ToList(), Contacts = repository.OfType <ContactType>().Queryable.Select(a => new Contact() { ContactType = a }).ToList(), Countries = repository.OfType <Country>().GetAll(), CommunicationOptions = repository.OfType <CommunicationOption>().GetAll(), SeminarPerson = person != null?person.GetLatestRegistration(site) : null, Email = email, Seminar = seminar, Commodities = repository.OfType <Commodity>().Queryable.Where(a => a.IsActive).ToList(), Firm = firm ?? new Firm() }; if (firm == null && viewModel.SeminarPerson != null) { viewModel.Firm = viewModel.SeminarPerson.Firm; } // find any addresses and replace them into the list if (person != null) { foreach (var a in person.Addresses) { var addr = viewModel.Addresses.Where(b => b.AddressType == a.AddressType).FirstOrDefault(); if (addr != null) { viewModel.Addresses.Remove(addr); } viewModel.Addresses.Add(a); } foreach (var a in person.Contacts) { var ct = viewModel.Contacts.Where(b => b.ContactType == a.ContactType).FirstOrDefault(); if (ct != null) { viewModel.Contacts.Remove(ct); } viewModel.Contacts.Add(a); } } // reorder so always in the same order viewModel.Addresses = viewModel.Addresses.OrderBy(a => a.AddressType.Id).ToList(); viewModel.Contacts = viewModel.Contacts.OrderBy(a => a.ContactType.Id).ToList(); // get the firms and add the "Other" option var firms = new List <Firm>(firmService.GetAllFirms()); firms.Add(new Firm() { Name = "Other (Not Listed)" }); viewModel.Firms = firms; if (viewModel.Person.User != null) { viewModel.UserName = viewModel.Person.User.UserName; } return(viewModel); }