public void Create(EducationSecurityPrincipal user, ServiceOfferingScheduleModel viewModel)
        {
            if (user == null)
            {
                throw new ArgumentNullException("user");
            }
            if (viewModel == null)
            {
                throw new ArgumentNullException("viewModel");
            }
            if (!ServiceOfferingRepository.Items.Any(s => s.Id == viewModel.ServiceOfferingId && s.IsActive))
            {
                throw new EntityNotFoundException("Selected Service Offering was not found.");
            }
            ServiceOffering       offering   = ServiceOfferingRepository.Items.Single(s => s.Id == viewModel.ServiceOfferingId && s.IsActive);
            IEnumerable <Student> students   = StudentRepository.Items.Include(s => s.School).Where(s => viewModel.SelectedStudents.Contains(s.Id));
            IPermission           permission = PermissionFactory.Current.Create("ScheduleOffering", students, offering);

            permission.GrantAccess(user);
            User       userEntity = user.Identity.User;
            List <int> studentIds = viewModel.SelectedStudents.ToList();

            foreach (int studentId in studentIds)
            {
                var studentAssignedOffering = new StudentAssignedOffering
                {
                    StudentId      = studentId,
                    CreatingUserId = userEntity.Id,
                    IsActive       = true
                };
                viewModel.CopyTo(studentAssignedOffering);
                StudentAssignedOfferingRepository.Add(studentAssignedOffering);
            }
            RepositoryContainer.Save();
        }
        private StudentAssignedOffering CreateNewStudentAssignedOffering(Student student, ServiceUploadModel model, EducationSecurityPrincipal user)
        {
            var newOffering = new StudentAssignedOffering();

            newOffering.Student           = student;
            newOffering.StudentId         = student.Id;
            newOffering.CreatingUser      = user.Identity.User;
            newOffering.ServiceOfferingId = model.ServiceOfferingId;
            newOffering.StartDate         = DateTime.Now;
            newOffering.CreateTime        = DateTime.Now;
            newOffering.IsActive          = true;
            StudentAssignedOfferingRepository.Add(newOffering);
            return(newOffering);
        }
Example #3
0
        private void CreateNewStudentAssignedOffering(Student student, ServiceUploadModel model, DateTime?startDate, DateTime?endDate, string notes, EducationSecurityPrincipal user)
        {
            var newOffering = new StudentAssignedOffering()
            {
                StudentId         = student.Id,
                CreatingUser      = user.Identity.User,
                ServiceOfferingId = model.ServiceOfferingId,
                StartDate         = startDate,
                EndDate           = endDate,
                Notes             = notes,
                IsActive          = true
            };

            StudentAssignedOfferingRepository.Add(newOffering);
        }