Exemplo n.º 1
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();
        }
Exemplo n.º 2
0
        public void Edit(ProgramModel viewModel)
        {
            if (viewModel == null)
            {
                throw new ArgumentNullException("viewModel");
            }
            Program toUpdate = ProgramRepository.Items.Include(s => s.ServiceOfferings).Include(s => s.Schools).SingleOrDefault(p => p.Id == viewModel.Id);

            if (toUpdate == null || !toUpdate.IsActive)
            {
                throw new EntityNotFoundException("Could not find Program with specified Id.");
            }
            var currentMappings = ServiceOfferingRepository.Items.
                                  Include(c => c.ServiceType).
                                  Include(c => c.Provider).
                                  Include("StudentAssignedOfferings").
                                  Where(s => s.ProgramId == viewModel.Id).ToList();
            var newMappings = GenerateServiceOfferingMappings(viewModel, toUpdate);

            UpdateSchools(viewModel, toUpdate);
            DeactivateServiceOfferings(currentMappings, newMappings);
            ActivateServiceOfferings(currentMappings, newMappings);
            viewModel.CopyTo(toUpdate);
            ProgramRepository.Update(toUpdate);
            RepositoryContainer.Save();
        }
 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();
 }
 public void Edit(ProgramModel viewModel)
 {
     if (viewModel == null)
     {
         throw new ArgumentNullException("viewModel");
     }
     Program toUpdate = ProgramRepository.Items.Include(s => s.ServiceOfferings).Include(s => s.Schools).SingleOrDefault(p => p.Id == viewModel.Id);
     if (toUpdate == null || !toUpdate.IsActive)
     {
         throw new EntityNotFoundException("Could not find Program with specified Id.");
     }
     var currentMappings = ServiceOfferingRepository.Items.
         Include(c => c.ServiceType).
         Include(c => c.Provider).
         Include("StudentAssignedOfferings").
         Where(s => s.ProgramId == viewModel.Id).ToList();
     var newMappings = GenerateServiceOfferingMappings(viewModel, toUpdate);
     UpdateSchools(viewModel, toUpdate);
     DeactivateServiceOfferings(currentMappings, newMappings);
     ActivateServiceOfferings(currentMappings, newMappings);
     viewModel.CopyTo(toUpdate);
     ProgramRepository.Update(toUpdate);
     RepositoryContainer.Save();
 }