public void GivenServiceTypeAlreadyExistsWithName_AndIsInactive_WhenCreate_ThenReactivateServiceType()
        {
            ServiceType      inactiveType = Data.ServiceTypes[5];
            ServiceTypeModel viewModel    = new ServiceTypeModel();

            viewModel.CopyFrom(inactiveType);

            Target.Create(viewModel);

            Assert.IsTrue(inactiveType.IsActive);
        }
        public ServiceTypeModel GenerateDeleteViewModel(int typeId)
        {
            var model = ServiceTypeRepository.Items.SingleOrDefault(s => s.Id == typeId);

            if (model == null)
            {
                throw new EntityNotFoundException("Specified service type does not exist");
            }
            ServiceTypeModel viewModel = new ServiceTypeModel();

            viewModel.CopyFrom(model);
            return(viewModel);
        }
        public ServiceTypeModel GenerateEditViewModel(EducationSecurityPrincipal user, int typeId)
        {
            if (user == null)
            {
                throw new ArgumentNullException("user");
            }
            var serviceType = ServiceTypeRepository.Items.Include(s => s.Categories).Include("ServiceOfferings.Program").SingleOrDefault(s => s.Id == typeId && s.IsActive);

            if (serviceType == null)
            {
                throw new EntityNotFoundException("Specified service type does not exist");
            }
            ServiceTypeModel viewModel = new ServiceTypeModel();

            viewModel.CopyFrom(serviceType);
            viewModel.Categories      = new MultiSelectList(CategoryRepository.Items, "Id", "Name", serviceType.Categories.Select(c => c.Id));
            viewModel.Programs        = new MultiSelectList(ProgramRepository.Items.Where(p => p.IsActive), "Id", "Name", serviceType.ServiceOfferings.Where(so => so.IsActive && so.Program.IsActive).Select(s => s.ProgramId).Distinct());
            viewModel.IsAdministrator = user.IsInRole(SecurityRoles.DataAdmin);
            return(viewModel);
        }
 public ServiceTypeModel GenerateEditViewModel(EducationSecurityPrincipal user, int typeId)
 {
     if (user == null)
     {
         throw new ArgumentNullException("user");
     }
     var serviceType = ServiceTypeRepository.Items.Include(s => s.Categories).Include("ServiceOfferings.Program").SingleOrDefault(s => s.Id == typeId && s.IsActive);
     if (serviceType == null)
     {
         throw new EntityNotFoundException("Specified service type does not exist");
     }
     ServiceTypeModel viewModel = new ServiceTypeModel();
     viewModel.CopyFrom(serviceType);
     viewModel.Categories = new MultiSelectList(CategoryRepository.Items, "Id", "Name", serviceType.Categories.Select(c => c.Id));
     viewModel.Programs = new MultiSelectList(ProgramRepository.Items.Where(p => p.IsActive), "Id", "Name", serviceType.ServiceOfferings.Where(so => so.IsActive && so.Program.IsActive).Select(s => s.ProgramId).Distinct());
     viewModel.IsAdministrator = user.IsInRole(SecurityRoles.DataAdmin);
     return viewModel;
 }
 public ServiceTypeModel GenerateDeleteViewModel(int typeId)
 {
     var model = ServiceTypeRepository.Items.SingleOrDefault(s => s.Id == typeId);
     if (model == null)
     {
         throw new EntityNotFoundException("Specified service type does not exist");
     }
     ServiceTypeModel viewModel = new ServiceTypeModel();
     viewModel.CopyFrom(model);
     return viewModel;
 }