public ScheduleServiceOfferingListOptionsModel GenerateScheduleOfferingViewModel(EducationSecurityPrincipal user, IEnumerable <int> studentIds)
        {
            IEnumerable <Student> students   = StudentRepository.Items.Include(s => s.School).Where(s => studentIds.Contains(s.Id));
            IPermission           permission = PermissionFactory.Current.Create("ScheduleOffering", students);

            permission.GrantAccess(user);
            ScheduleServiceOfferingListOptionsModel viewModel = new ScheduleServiceOfferingListOptionsModel {
                SelectedStudents = studentIds
            };

            viewModel.Favorites          = LookupHelper.LoadFavorites(ServiceOfferingRepository, user);
            viewModel.TypeFilterList     = ServiceTypeRepository.Items.Where(s => s.IsActive).Select(t => t.Name).ToList();
            viewModel.CategoryFilterList = CategoryRepository.Items.Select(c => c.Name).ToList();
            return(viewModel);
        }
示例#2
0
        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);
        }
示例#3
0
        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);
        }
 public IEnumerable <ServiceOffering> LoadFavorites(EducationSecurityPrincipal user)
 {
     return(LookupHelper.LoadFavorites(ServiceOfferingRepository, user));
 }