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; }
// not sure if these are even used //public IEnumerable<Ceremony> Ceremonies { get; private set; } public static RegistrationModel Create(IRepository repository, IList<Ceremony> ceremonies, Student student, Registration registration = null, List<CeremonyParticipation> ceremonyParticipations = null, bool edit = false, bool admin = false) { var viewModel = new RegistrationModel { States = repository.OfType<State>().GetAll(), Registration = registration ?? new Registration() {Student = student}, Student = student, //Ceremonies = ceremonies, FutureTerms = repository.OfType<vTermCode>().Queryable.Where(a=>a.EndDate > DateTime.UtcNow.ToPacificTime()) }; // since the change to using a drop down, this is somewhat unnecessary, but should we move back to checkboxes, it would be a simple change var specialNeeds = repository.OfType<SpecialNeed>().Queryable.Where(a=>a.IsActive).ToList(); viewModel.FullSpecialNeeds = specialNeeds; if (viewModel.Registration.Id != 0 && viewModel.Registration.SpecialNeeds != null) { viewModel.SpecialNeedsOld = new MultiSelectList(specialNeeds, "Id", "Name", registration.SpecialNeeds.Select(a=>a.Id).ToList()); } else { viewModel.SpecialNeedsOld = new MultiSelectList(specialNeeds, "Id", "Name"); } var participations = new List<CeremonyParticipation>(); if (ceremonyParticipations == null) { // populate in any ceremonies that the student has registered for if (registration != null) { foreach (var a in registration.RegistrationParticipations) { if (!participations.Any(b => b.Major == a.Major)) { var part = CreateCeremonyParticipation(participations.Count, edit, student, a.Major, a.Ceremony, registration, null, repository); if (part != null) participations.Add(part); } } } foreach (var major in student.Majors) { Ceremony ceremony = GetCeremony(repository, major); if (ceremony != null && !participations.Any(a => a.Ceremony == ceremony)) { var part = CreateCeremonyParticipation(participations.Count, edit, student, major, ceremony, registration, null, repository, admin); if (part != null) { participations.Add(part); } } } } else { // fill in the majors for (var i = 0; i < ceremonyParticipations.Count; i++) { var part = ceremonyParticipations[i]; part.MajorCodes = part.Ceremony.Majors.OrderBy(x => x.MajorName).ToList(); part.Index = i; } participations = ceremonyParticipations; } viewModel.Participations = participations; return viewModel; }