public ServiceAttendanceModel GenerateEditViewModel(EducationSecurityPrincipal user, int id) { var serviceAttendance = ServiceAttendanceRepository.Items. Include(s => s.CreatingUser). Include(s => s.LastModifyingUser). Include(s => s.StudentAssignedOffering). SingleOrDefault(s => s.Id == id); if (serviceAttendance == null) { throw new EntityNotFoundException("Specified service attendance does not exist"); } IPermission permission = PermissionFactory.Current.Create("EditServiceAttendance", serviceAttendance.StudentAssignedOffering); permission.GrantAccess(user); var viewModel = new ServiceAttendanceModel(); viewModel.CopyFrom(serviceAttendance); viewModel.Subjects = new SelectList(LookupHelper.LoadSubjectList(SubjectRepository), "Id", "Name", viewModel.SelectedSubjectId); return(viewModel); }
public ServiceAttendanceModel GenerateCreateViewModel(EducationSecurityPrincipal user, int id) { StudentAssignedOffering studentAssignedOffering = StudentAssignedOfferingRepository.Items. Include(s => s.Student.School). Include(s => s.ServiceOffering.Provider). SingleOrDefault(s => s.Id == id); if (studentAssignedOffering == null) { throw new EntityNotFoundException("Could not find student assigned offering with given Id."); } IPermission permission = PermissionFactory.Current.Create("CreateServiceAttendance", studentAssignedOffering); permission.GrantAccess(user); var viewModel = new ServiceAttendanceModel() { StudentAssignedOfferingId = id, DateAttended = DateTime.Now, SelectedSubjectId = 1 }; viewModel.Subjects = new SelectList(LookupHelper.LoadSubjectList(SubjectRepository), "Id", "Name", viewModel.SelectedSubjectId); return(viewModel); }
public void PopulateViewModel(ServiceRequestModel viewModel) { if (viewModel == null) { throw new ArgumentNullException("viewModel"); } viewModel.Priorities = new SelectList(PriorityRepository.Items.OrderBy(p => p.Id), "Id", "Name", viewModel.SelectedPriorityId); viewModel.Subjects = new SelectList(LookupHelper.LoadSubjectList(SubjectRepository), "Id", "Name", viewModel.SelectedSubjectId); viewModel.ServiceTypes = new SelectList(ServiceTypeRepository.Items.Where(s => s.IsActive || viewModel.SelectedServiceTypeId == s.Id), "Id", "Name", viewModel.SelectedServiceTypeId); Student selectedStudent = null; if (viewModel.StudentIds != null) { selectedStudent = StudentRepository.Items. Include("StudentAssignedOfferings.ServiceOffering.Provider"). Include("StudentAssignedOfferings.ServiceOffering.ServiceType"). Include("StudentAssignedOfferings.ServiceOffering.Program"). FirstOrDefault(s => s.Id == viewModel.StudentIds.FirstOrDefault()); } List <StudentAssignedOffering> offerings = new List <StudentAssignedOffering>(); if (selectedStudent != null) { viewModel.AssignedOfferings = new SelectList((from o in selectedStudent.StudentAssignedOfferings.Where(s => s.IsActive || (viewModel.SelectedAssignedOfferingId != null && s.Id == viewModel.SelectedAssignedOfferingId)).ToList() select new { Id = o.Id, Name = o.ServiceOffering.Name }), "Id", "Name", viewModel.SelectedAssignedOfferingId); } else { viewModel.AssignedOfferings = new SelectList(Enumerable.Empty <StudentAssignedOffering>()); } viewModel.Statuses = new SelectList(FulfillmentStatusRepository.Items, "Id", "Name", viewModel.SelectedStatusId); }