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();
        }
Exemplo n.º 2
0
        private List <ServiceOffering> GenerateServiceOfferingMappings(ProgramModel viewModel, Program item)
        {
            List <ServiceOffering> newMappings = new List <ServiceOffering>();

            if (viewModel.SelectedServiceTypes != null && viewModel.SelectedProviders != null)
            {
                foreach (var serviceTypeId in viewModel.SelectedServiceTypes)
                {
                    foreach (var providerId in viewModel.SelectedProviders)
                    {
                        ServiceOffering newOffering = ServiceOfferingRepository.Items.SingleOrDefault(s => s.ServiceTypeId == serviceTypeId && s.ProviderId == providerId && s.ProgramId == item.Id && !s.IsActive);
                        if (newOffering == null)
                        {
                            newOffering = new ServiceOffering {
                                ProviderId = providerId, ServiceTypeId = serviceTypeId, Program = item, ProgramId = item.Id, IsActive = true
                            };
                        }
                        else
                        {
                            newOffering.IsActive = true;
                        }
                        newMappings.Add(newOffering);
                    }
                }
            }
            return(newMappings);
        }
        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();
        }
Exemplo n.º 4
0
        public void GivenServiceOffering_WhenInvokeDataSelector_ThenDataContainsExpectedProperties()
        {
            bool            expectedIsFavorite        = true;
            bool            expectedIsProviate        = true;
            string          expectedServiceTypeName   = "jw29fij2";
            string          expectedProviderName      = "slkdjfsdkljfs";
            string          expectedProgramName       = "wjovjwiojw";
            int             expectedServiceOfferingId = 382;
            ServiceOffering offering = new ServiceOffering
            {
                UsersLinkingAsFavorite = new List <User> {
                    CurrentUser.Identity.User
                },
                ServiceType = new ServiceType {
                    Name = expectedServiceTypeName, IsPrivate = expectedIsProviate
                },
                Provider = new Provider {
                    Name = expectedProviderName
                },
                Program = new Program {
                    Name = expectedProgramName
                },
                Id = expectedServiceOfferingId
            };
            ServiceOfferingClientDataTable target = new ServiceOfferingClientDataTable(MockRequest, CurrentUser);

            dynamic actual = target.DataSelector.Compile().Invoke(offering);

            Assert.AreEqual(expectedIsFavorite, actual.IsFavorite);
            Assert.AreEqual(expectedIsProviate, actual.IsPrivate);
            Assert.AreEqual(expectedServiceTypeName, actual.ServiceType);
            Assert.AreEqual(expectedProviderName, actual.Provider);
            Assert.AreEqual(expectedProgramName, actual.Program);
            Assert.AreEqual(expectedServiceOfferingId, actual.Id);
        }
 public ImportOfferingDataPermission(ServiceOffering offering)
 {
     if (offering == null)
     {
         throw new ArgumentNullException("offering");
     }
     Offering = offering;
 }
        public void GivenServiceOfferingIsUpdated_WhenSaveChanges_ThenOperationSucceeds()
        {
            ServiceOffering toUpdate = Target.ServiceOfferings.First();

            Target.SetModified(toUpdate);

            Target.SaveChanges();
        }
Exemplo n.º 7
0
        public void GivenAServiceOffering_WhenRemove_ThenThrowException()
        {
            var item = new ServiceOffering {
                Id = 1
            };

            Target.ExpectException <NotSupportedException>(() => Target.Remove(item));
        }
Exemplo n.º 8
0
        public void GivenIsActiveIsFalse_WhenIExecuteFilterPredicate_ThenReturnFalse()
        {
            ServiceOffering argument = new ServiceOffering {
                IsActive = false
            };
            ServiceOfferingClientDataTable target = new ServiceOfferingClientDataTable(MockRequest, CurrentUser);

            Assert.IsFalse(target.FilterPredicate.Compile().Invoke(argument));
        }
 public void InitializeTest()
 {
     TestData        = new TestData();
     ServiceOffering = new ServiceOffering()
     {
         Id = 1, Provider = TestData.Providers[0], ServiceType = TestData.ServiceTypes[0], Program = TestData.Programs[0]
     };
     Target = new WorksheetWriter(ServiceOffering, "Assign Service Offering");
 }
Exemplo n.º 10
0
        public void GivenAServiceOffering_WhenAdd_ThenAddToContext()
        {
            var expected = new ServiceOffering {
                Id = 1
            };

            Target.Add(expected);

            MockDbSet.AssertWasCalled(m => m.Add(expected));
        }
Exemplo n.º 11
0
        public void GivenAServiceOffering_WhenUpdate_ThenContextSetsModified()
        {
            var expected = new ServiceOffering {
                Id = 1
            };

            Target.Update(expected);

            MockContext.AssertWasCalled(m => m.SetModified(expected));
        }
Exemplo n.º 12
0
        public void GivenAnAssociatedServiceOfferingAndUser_WhenAddLink_ThenTheyAreAssociated()
        {
            ServiceOffering serviceOffering = new ServiceOffering();
            User            user            = new User();

            Target.AddLink(serviceOffering, user);

            CollectionAssert.Contains(serviceOffering.UsersLinkingAsFavorite.ToList(), user);
            CollectionAssert.Contains(user.FavoriteServiceOfferings.ToList(), serviceOffering);
        }
 public WorksheetWriter(ServiceOffering offering, string sheetName)
 {
     if (offering == null)
     {
         throw new ArgumentNullException("offering");
     }
     ServiceOffering = offering;
     SheetName       = sheetName;
     ErrorRows       = new List <FileRowModel>();
 }
Exemplo n.º 14
0
        public void GivenValidOfferingId_AndFalseState_WhenSetFavoriteState_ThenUserLinkDeleted()
        {
            ServiceOffering toSetAsFavorite = Data.ServiceOfferings[1];

            PermissionFactory.Current.Expect(m => m.Create("SetFavoriteServiceOffering", toSetAsFavorite.Id)).Return(MockRepository.GenerateMock <IPermission>());

            Target.SetFavoriteState(User, toSetAsFavorite.Id, false);

            Repositories.MockServiceOfferingRepository.AssertWasCalled(m => m.DeleteLink(toSetAsFavorite, User.Identity.User));
            Repositories.MockRepositoryContainer.AssertWasCalled(m => m.Save());
        }
 private void CreateFavoriteServiceOfferingInDatabase(int serviceOfferingId)
 {
     using (EducationDataContext context = new EducationDataContext())
     {
         User            currentUser    = context.Users.Single(u => u.UserKey == User.Identity.User.UserKey);
         ServiceOffering offeringToLink = context.ServiceOfferings.Single(o => o.Id == serviceOfferingId);
         currentUser.FavoriteServiceOfferings.Add(offeringToLink);
         offeringToLink.UsersLinkingAsFavorite.Add(currentUser);
         context.SaveChanges();
     }
 }
Exemplo n.º 16
0
        public void GivenValidServiceOffering_WhenCreateAssignedOfferingTemplateDownload_ThenFileNameContainsServiceOfferingName()
        {
            ServiceOffering offering = TestData.ServiceOfferings[0];

            PermissionFactory.Current.Expect(m => m.Create("ImportOfferingData", offering)).Return(MockRepository.GenerateMock <IPermission>());

            var model = Target.CreateTemplateDownload(User, ServiceAttendanceTemplatePath, offering.Id) as DownloadFileModel;

            StringAssert.Contains(model.FileName, offering.Name.GetSafeFileName());
            DestroyTestFile(model.BlobAddress);
        }
 public void DeleteLink(ServiceOffering serviceOffering, User user)
 {
     if (serviceOffering == null)
     {
         throw new ArgumentNullException("serviceOffering");
     }
     if (user == null)
     {
         throw new ArgumentNullException("user");
     }
     serviceOffering.UsersLinkingAsFavorite.Remove(user);
     user.FavoriteServiceOfferings.Remove(serviceOffering);
 }
Exemplo n.º 18
0
        public void GivenServiceTypeFiltersExistInRequest_AndServiceOfferingDoesNotMatchFilter_WhenIExecuteFilterPredicate_ThenServiceOfferingIsNotSelected()
        {
            ServiceOffering argument = new ServiceOffering {
                ServiceType = new ServiceType {
                    Name = "Purple"
                }
            };

            MockRequest.Expect(m => m["ServiceTypeFilters"]).Return("Apples|Oranges|Grapes");
            ServiceOfferingClientDataTable target = new ServiceOfferingClientDataTable(MockRequest, CurrentUser);

            Assert.IsFalse(target.FilterPredicate.Compile().Invoke(argument));
        }
Exemplo n.º 19
0
        public void GivenProviderRemovedFromProgram_AndServiceOfferingsToDeactivateHaveStudentAssignedOfferings_WhenEdit_ThenThrowException()
        {
            int             id = 2;
            ServiceOffering expectedInactive = Data.ServiceOfferings.Single(s => s.Id == 2);

            expectedInactive.StudentAssignedOfferings.Add(new StudentAssignedOffering {
                IsActive = true
            });
            ProgramModel viewModel = new ProgramModel {
                Id = id, SelectedServiceTypes = new int[] { 4 }, SelectedProviders = new int[] { 1 }
            };

            Target.ExpectException <ValidationException>(() => Target.Edit(viewModel));
        }
Exemplo n.º 20
0
        public void GivenTableIsInvalid_WhenImportServiceAttendances_ThenErrorFileNameHasServiceOfferingName()
        {
            ServiceOffering offering = TestData.ServiceOfferings[1];
            DataRow         row      = FileData.NewRow();

            row["Id"]           = "10a";
            row["DateAttended"] = "41390";
            FileData.Rows.Add(row);
            PermissionFactory.Current.Expect(m => m.Create("ImportOfferingData", offering)).Return(MockRepository.GenerateMock <IPermission>());

            ServiceUploadModel actual = Target.Import(User, ServiceAttendanceTemplatePath, FileData);

            StringAssert.Contains(actual.ErrorDownloadFile.FileName, offering.Name.GetSafeFileName());
        }
Exemplo n.º 21
0
        public void GivenProviderRemovedFromProgram_WhenEdit_ThenServiceOfferingsAssociatedToProviderSetInactive()
        {
            int             id = 2;
            ServiceOffering expectedInactive = Data.ServiceOfferings.Single(s => s.Id == 2);
            ServiceOffering expectedActive   = Data.ServiceOfferings.Single(s => s.Id == 3);
            ProgramModel    viewModel        = new ProgramModel {
                Id = id, SelectedServiceTypes = new int[] { 4 }, SelectedProviders = new int[] { 1 }
            };

            Target.Edit(viewModel);

            Assert.IsTrue(expectedActive.IsActive);
            Assert.IsFalse(expectedInactive.IsActive);
        }
Exemplo n.º 22
0
        public void GivenServiceTypeProviderProgramAlreadyExists_AndOfferingIsInactive_AndServiceTypeAddedToProgram_WhenEdit_ThenServiceOfferingIsActive()
        {
            int             id          = 2;
            ServiceOffering newOffering = new ServiceOffering {
                ProviderId = 1, ServiceTypeId = 1, ProgramId = id, IsActive = false
            };

            Data.ServiceOfferings.Add(newOffering);
            ProgramModel viewModel = new ProgramModel {
                Id = id, SelectedServiceTypes = new int[] { 1, 4 }, SelectedProviders = new int[] { 1 }
            };

            Target.Edit(viewModel);

            Assert.IsTrue(newOffering.IsActive);
        }
Exemplo n.º 23
0
        public void GivenAnAssociatedUserAndServiceOffering_WhenDeleteLink_ThenTheyAreNoLongerAssociated()
        {
            ServiceOffering serviceOffering = new ServiceOffering();
            User            user            = new User {
                FavoriteServiceOfferings = new List <ServiceOffering> {
                    serviceOffering
                }
            };

            serviceOffering.UsersLinkingAsFavorite.Add(user);

            Target.DeleteLink(serviceOffering, user);

            CollectionAssert.DoesNotContain(serviceOffering.UsersLinkingAsFavorite.ToList(), user);
            CollectionAssert.DoesNotContain(user.FavoriteServiceOfferings.ToList(), serviceOffering);
        }
 public ScheduleOfferingPermission(IEnumerable <Student> students, ServiceOffering offering)
 {
     if (students == null)
     {
         throw new ArgumentNullException("students");
     }
     if (offering == null)
     {
         throw new ArgumentNullException("offering");
     }
     if (!students.Any())
     {
         throw new ArgumentException("List cannot be empty.", "students");
     }
     Students = students;
     Offering = offering;
 }
Exemplo n.º 25
0
        private List <Service> GetSampleServices()
        {
            var foo = new ServiceOffering {
                Id = 1, Title = "foo", Body = "foo", Category = new Category {
                    Id = 1, Name = "foo"
                }
            };

            var bar = new ServiceOffering {
                Id = 1, Title = "bar", Body = "bar", Category = new Category {
                    Id = 2, Name = "bar"
                }
            };

            return(new List <Service> {
                foo, bar
            });
        }
Exemplo n.º 26
0
        public void GivenServiceOffering_AndUserIsDataAdmin_WhenInvokeDataSelector_ThenDataCanInteract()
        {
            ServiceOffering offering = new ServiceOffering
            {
                Provider    = new Provider(),
                ServiceType = new ServiceType(),
                Program     = new Program()
            };

            CurrentUser.Identity.User.UserRoles.Add(new UserRole {
                Role = new Role {
                    Name = SecurityRoles.DataAdmin
                }
            });
            ServiceOfferingClientDataTable target = new ServiceOfferingClientDataTable(MockRequest, CurrentUser);

            dynamic actual = target.DataSelector.Compile().Invoke(offering);

            Assert.AreEqual(true, actual.CanInteract);
        }
Exemplo n.º 27
0
        private void ProcessErrorFile(EducationSecurityPrincipal user, ServiceOffering offering, ServiceUploadModel model, string templatePath)
        {
            var fileName    = string.Format(CultureInfo.InvariantCulture, "{0}{1}{2}", offering.Name.GetSafeFileName(), DateTime.Now.Ticks, ".xlsx");
            var blobAddress = string.Format("{0}-{1}-{2}", user.Identity.User.DisplayName, user.Identity.User.Id, fileName);

            model.ErrorDownloadFile = new DownloadFileModel
            {
                FileName    = fileName,
                BlobAddress = blobAddress
            };
            var         worksheetWriter = CreateWorksheetWriter(offering);
            ExcelWriter writer          = new ExcelWriter();

            writer.InitializeFrom(templatePath, worksheetWriter);
            foreach (var error in model.RowErrorValues)
            {
                worksheetWriter.ErrorRows.Add(error);
            }
            writer.AppendErrorRows(ServiceOfferingSheetName, worksheetWriter);
            writer.Write(BlobClient.CreateContainer(ServiceFileContainerName), model.ErrorDownloadFile.BlobAddress);
        }
 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;
         }
     }
 }
Exemplo n.º 29
0
        public ServiceUploadModel Import(EducationSecurityPrincipal user, string templatePath, DataTable dataTable)
        {
            var             headerRow = dataTable.Rows[1];
            int             serviceOfferingId;
            ServiceOffering offering = null;

            if (int.TryParse(headerRow[1].ToString(), out serviceOfferingId))
            {
                offering = ServiceOfferingRepository.Items.Include(s => s.Provider).
                           Include(s => s.ServiceType).
                           Include(s => s.Program).
                           SingleOrDefault(s => s.Id == serviceOfferingId);
            }
            ServiceUploadModel model = new ServiceUploadModel();

            if (offering != null && offering.IsActive)
            {
                serviceOfferingId = int.Parse(headerRow[1].ToString());
                if (!GrantUserAccessToUploadOffering(user, offering))
                {
                    throw new EntityAccessUnauthorizedException("Not authorized to schedule service offerings with this provider.");
                }
                model.ServiceOfferingId = serviceOfferingId;
                ProcessDataTable(user, dataTable, model);
                RepositoryContainer.Save();
                if (model.RowErrors.Any())
                {
                    ProcessErrorFile(user, offering, model, templatePath);
                }
            }
            else
            {
                model.ProcessedRowCount = model.SuccessfulRowsCount = 0;
                model.RowErrors.Add("Invalid Service Offering ID");
            }
            return(model);
        }
        private List<Service> GetSampleServices()
        {
            var foo = new ServiceOffering { Id = 1, Title = "foo", Body = "foo", Category = new Category { Id = 1, Name = "foo"}};

            var bar = new ServiceOffering { Id = 1, Title = "bar", Body = "bar", Category = new Category { Id = 2, Name = "bar" } };

            return new List<Service> { foo, bar };
        }
 public void Update(ServiceOffering item)
 {
     Context.SetModified(item);
 }