public void SetFavoriteState(EducationSecurityPrincipal user, int offeringId, bool isFavorite)
        {
            if (user == null)
            {
                throw new ArgumentNullException("user");
            }
            User            userEntity      = user.Identity.User;
            ServiceOffering serviceOffering = ServiceOfferingRepository.Items.Include(u => u.UsersLinkingAsFavorite).SingleOrDefault(s => s.Id == offeringId);

            if (serviceOffering == null || !serviceOffering.IsActive)
            {
                throw new EntityNotFoundException("Service Offering with the specified ID was not found.");
            }
            IPermission permission = PermissionFactory.Current.Create("SetFavoriteServiceOffering", serviceOffering.ProviderId);

            permission.GrantAccess(user);
            if (isFavorite)
            {
                ServiceOfferingRepository.AddLink(serviceOffering, userEntity);
            }
            else
            {
                ServiceOfferingRepository.DeleteLink(serviceOffering, userEntity);
            }
            RepositoryContainer.Save();
        }
Beispiel #2
0
        public void Create(ProgramModel viewModel)
        {
            if (viewModel == null)
            {
                throw new ArgumentNullException("viewModel");
            }
            Program item = ProgramRepository.Items.SingleOrDefault(p => p.Name == viewModel.Name && !p.IsActive);

            if (item == null)
            {
                item = new Program();
                ProgramRepository.Add(item);
            }
            viewModel.Id  = item.Id;
            item.IsActive = true;
            viewModel.CopyTo(item);
            UpdateSchools(viewModel, item);
            var mappings = GenerateServiceOfferingMappings(viewModel, item);

            foreach (var mapping in mappings)
            {
                if (!ServiceOfferingRepository.Items.Where(s => s.ProgramId == mapping.ProgramId && s.ProviderId == mapping.ProviderId && s.ServiceTypeId == mapping.ServiceTypeId).Any())
                {
                    item.ServiceOfferings.Add(mapping);
                    ServiceOfferingRepository.Add(mapping);
                }
            }
            RepositoryContainer.Save();
        }
Beispiel #3
0
        private void DeactivateServiceOfferings(List <ServiceOffering> currentMappings, List <ServiceOffering> newMappings)
        {
            var offeringsToDeactivate = currentMappings.Where(c => !newMappings.Any(n => n.ProviderId == c.ProviderId && n.ServiceTypeId == c.ServiceTypeId));

            foreach (var offering in offeringsToDeactivate)
            {
                if (offering.StudentAssignedOfferings.Any(s => s.IsActive))
                {
                    throw new ValidationException(string.Format("There are still active Student Assigned Offerings for Service Type {0} and Provider {1}.", offering.ServiceType.Name, offering.Provider.Name));
                }
                offering.IsActive = false;
                ServiceOfferingRepository.Update(offering);
            }
        }
Beispiel #4
0
        private void ActivateServiceOfferings(List <ServiceOffering> currentMappings, List <ServiceOffering> newMappings)
        {
            var offeringsToActivate = currentMappings.Where(c => newMappings.Any(n => n.ProviderId == c.ProviderId && n.ServiceTypeId == c.ServiceTypeId) && !c.IsActive);

            foreach (var offering in offeringsToActivate)
            {
                offering.IsActive = true;
            }
            var offeringsToAdd = newMappings.Where(n => !currentMappings.Any(c => n.ProviderId == c.ProviderId && n.ServiceTypeId == c.ServiceTypeId));

            foreach (var offering in offeringsToAdd)
            {
                offering.Program.ServiceOfferings.Add(offering);
                ServiceOfferingRepository.Add(offering);
            }
        }
 private void CreateServiceOfferings(Program program, ServiceType serviceType)
 {
     foreach (int providerId in program.ServiceOfferings.Select(s => s.ProviderId).Distinct().ToArray())
     {
         if (!serviceType.ServiceOfferings.Any(o => o.Program == program && o.ProviderId == providerId))
         {
             ServiceOffering newOffering = new ServiceOffering
             {
                 IsActive    = true,
                 ServiceType = serviceType,
                 Program     = program,
                 ProgramId   = program.Id,
                 ProviderId  = providerId
             };
             serviceType.ServiceOfferings.Add(newOffering);
             ServiceOfferingRepository.Add(newOffering);
         }
         else if (serviceType.ServiceOfferings.Any(o => o.Program == program && o.ProviderId == providerId && !o.IsActive))
         {
             serviceType.ServiceOfferings.Single(o => o.Program == program && o.ProviderId == providerId && !o.IsActive).IsActive = true;
         }
     }
 }