Beispiel #1
0
        private void DoUpdate(PublishedProject updatedProject, Project projectToUpdate, DefaultExchangeVisitorFunding existingDefaultExchangeVisitorFunding, List <Participant> participantsWithoutParticipantExchangeVisitor)
        {
            Contract.Requires(updatedProject != null, "The updated project must not be null.");
            Contract.Requires(projectToUpdate != null, "The project to update must not be null.");
            SetPointOfContacts(updatedProject.PointsOfContactIds.ToList(), projectToUpdate);
            SetThemes(updatedProject.ThemeIds.ToList(), projectToUpdate);
            SetGoals(updatedProject.GoalIds.ToList(), projectToUpdate);
            SetCategories(updatedProject.CategoryIds.ToList(), projectToUpdate);
            SetObjectives(updatedProject.ObjectiveIds.ToList(), projectToUpdate);
            SetLocations <Project>(updatedProject.LocationIds.ToList(), projectToUpdate, x => x.Locations);
            SetRegions(updatedProject.RegionIds.ToList(), projectToUpdate);
            CreateDefaultExchangeVisitorFunding(updatedProject, projectToUpdate, existingDefaultExchangeVisitorFunding);
            CreateParticipantExchangeVisitors(participantsWithoutParticipantExchangeVisitor);
            projectToUpdate.Name                    = updatedProject.Name;
            projectToUpdate.Description             = updatedProject.Description;
            projectToUpdate.SevisOrgId              = updatedProject.SevisOrgId;
            projectToUpdate.EndDate                 = updatedProject.EndDate;
            projectToUpdate.Name                    = updatedProject.Name;
            projectToUpdate.ProjectStatusId         = updatedProject.ProjectStatusId;
            projectToUpdate.StartDate               = updatedProject.StartDate;
            projectToUpdate.VisitorTypeId           = updatedProject.VisitorTypeId;
            projectToUpdate.UsParticipantsEst       = updatedProject.UsParticipantsEst;
            projectToUpdate.NonUsParticipantsEst    = updatedProject.NonUsParticipantsEst;
            projectToUpdate.UsParticipantsActual    = updatedProject.UsParticipantsActual;
            projectToUpdate.NonUsParticipantsActual = updatedProject.NonUsParticipantsActual;

            Contract.Assert(updatedProject.Audit != null, "The audit must not be null.");
            updatedProject.Audit.SetHistory(projectToUpdate);
        }
        /// <summary>
        /// Creates a new ProjectServiceValidationEntity.
        /// </summary>
        /// <param name="updatedProject">The updated project.</param>
        /// <param name="projectToUpdate">The project to be updated.</param>
        /// <param name="locationsExist">The boolean value indicating whether all locations exist in the system.</param>
        /// <param name="categoriesExist">The boolean value indicating whether all categories exist in the system.</param>
        /// <param name="objectivesExist">The boolean value indicating whether all objectives exist in the system.</param>
        /// <param name="newInactiveLocations">The ids of locations that are inactive and were not previously set on the project.</param>
        /// <param name="goalsExist">The boolean value indicating whether all goals exist in the system.</param>
        /// <param name="themesExist">The boolean value indicating whether all themes exist in the system.</param>
        /// <param name="pointsOfContactExist">the boolean valud indicating whether all points of contact in the system.</param>
        /// <param name="numberOfCategories">The number of categories.</param>
        /// <param name="numberOfObjectives">The number of objectives.</param>
        /// <param name="officeSettings">The office settings.</param>
        /// <param name="allowedCategoryIds">The category ids the project can be assigned as deteremined by the parent program.</param>
        /// <param name="allowedObjectiveIds">The objective ids the project can be assigned as determined by the parent program.</param>
        /// <param name="regionLocationTypeIds">The location type ids for the given project regions.</param>
        public ProjectServiceUpdateValidationEntity(
            PublishedProject updatedProject,
            Project projectToUpdate,
            List <int> newInactiveLocations,
            bool goalsExist,
            bool themesExist,
            bool pointsOfContactExist,
            bool categoriesExist,
            bool objectivesExist,
            bool locationsExist,
            int numberOfObjectives,
            int numberOfCategories,
            IEnumerable <int> allowedCategoryIds,
            IEnumerable <int> allowedObjectiveIds,
            IEnumerable <int> regionLocationTypeIds,
            OfficeSettings officeSettings,
            IEnumerable <int> allowedThemeIds,
            IEnumerable <int> allowedGoalIds)
        {
            Contract.Requires(updatedProject != null, "The updated project must not be null.");
            Contract.Requires(projectToUpdate != null, "The project to update must not be null.");

            var updatedProjectStatus = ProjectStatus.GetStaticLookup(updatedProject.ProjectStatusId);

            if (updatedProjectStatus == null)
            {
                throw new UnknownStaticLookupException(String.Format("The project status with id [{0}] is not recognized.", updatedProject.ProjectStatusId));
            }
            Contract.Assert(ProjectStatus.GetStaticLookup(projectToUpdate.ProjectStatusId) != null, "The project to update should have a valid project status.");
            this.Name                    = updatedProject.Name;
            this.Description             = updatedProject.Description;
            this.GoalsExist              = goalsExist;
            this.ThemesExist             = themesExist;
            this.LocationsExist          = locationsExist;
            this.PointsOfContactExist    = pointsOfContactExist;
            this.CategoriesExist         = categoriesExist;
            this.ObjectivesExist         = objectivesExist;
            this.UpdatedProjectStatusId  = updatedProject.ProjectStatusId;
            this.SevisOrgId              = updatedProject.SevisOrgId;
            this.OriginalProjectStatusId = projectToUpdate.ProjectStatusId;
            this.StartDate               = updatedProject.StartDate;
            this.EndDate                 = updatedProject.EndDate;
            this.NumberOfCategories      = numberOfCategories;
            this.NumberOfObjectives      = numberOfObjectives;
            this.OfficeSettings          = officeSettings;
            this.CategoryIds             = updatedProject.CategoryIds;
            this.ObjectiveIds            = updatedProject.ObjectiveIds;
            this.AllowedCategoryIds      = allowedCategoryIds == null ? new List <int>() : allowedCategoryIds.Distinct();
            this.AllowedObjectiveIds     = allowedObjectiveIds == null ? new List <int>() : allowedObjectiveIds.Distinct();
            this.NewInactiveLocationIds  = newInactiveLocations == null ? new List <int>() : newInactiveLocations.Distinct();
            this.RegionLocationTypeIds   = regionLocationTypeIds == null ? new List <int>() : regionLocationTypeIds.Distinct();
            this.ThemeIds                = updatedProject.ThemeIds;
            this.GoalIds                 = updatedProject.GoalIds;
            this.AllowedThemeIds         = allowedThemeIds == null ? new List <int>() : allowedThemeIds.Distinct();
            this.AllowedGoalIds          = allowedGoalIds == null ? new List <int>() : allowedGoalIds.Distinct();
        }
Beispiel #3
0
 private void CreateDefaultExchangeVisitorFunding(PublishedProject updatedProject, Project projectToUpdate, DefaultExchangeVisitorFunding existingDefaultExchangeVisitorFunding)
 {
     if (existingDefaultExchangeVisitorFunding == null && updatedProject.VisitorTypeId == VisitorType.ExchangeVisitor.Id)
     {
         var defaultExchangeVisitorFunding = new DefaultExchangeVisitorFunding
         {
             Project = projectToUpdate
         };
         projectToUpdate.DefaultExchangeVisitorFunding = defaultExchangeVisitorFunding;
         Context.DefaultExchangeVisitorFunding.Add(defaultExchangeVisitorFunding);
     }
 }
Beispiel #4
0
 private ProjectServiceUpdateValidationEntity GetUpdateValidationEntity(
     PublishedProject publishedProject,
     Project projectToUpdate,
     bool goalsExist,
     bool themesExist,
     bool pointsOfContactExist,
     bool categoriesExist,
     bool objectivesExist,
     bool locationsExist,
     int numberOfCategories,
     int numberOfObjectives,
     List <int> allowedCategoryIds,
     List <int> allowedObjectiveIds,
     List <int> newInactiveLocationIds,
     List <int> regionLocationTypeIds,
     OfficeSettings settings,
     List <int> allowedThemeIds,
     List <int> allowedGoalIds)
 {
     return(new ProjectServiceUpdateValidationEntity(
                updatedProject: publishedProject,
                projectToUpdate: projectToUpdate,
                goalsExist: goalsExist,
                themesExist: themesExist,
                locationsExist: locationsExist,
                pointsOfContactExist: pointsOfContactExist,
                categoriesExist: categoriesExist,
                objectivesExist: objectivesExist,
                numberOfCategories: numberOfCategories,
                numberOfObjectives: numberOfObjectives,
                officeSettings: settings,
                allowedCategoryIds: allowedCategoryIds,
                allowedObjectiveIds: allowedObjectiveIds,
                regionLocationTypeIds: regionLocationTypeIds,
                newInactiveLocations: newInactiveLocationIds,
                allowedThemeIds: allowedThemeIds,
                allowedGoalIds: allowedGoalIds
                ));
 }
Beispiel #5
0
 /// <summary>
 ///
 /// </summary>
 /// <param name="updatedProject"></param>
 /// <returns></returns>
 public Task UpdateAsync(PublishedProject updatedProject)
 {
     Contract.Requires(updatedProject != null, "The updated project must not be null.");
     return(Task.FromResult <object>(null));
 }
Beispiel #6
0
 /// <summary>
 ///
 /// </summary>
 /// <param name="updatedProject"></param>
 public void Update(PublishedProject updatedProject)
 {
     Contract.Requires(updatedProject != null, "The updated project must not be null.");
 }
Beispiel #7
0
        /// <summary>
        /// Updates the system's project with the given updated project.
        /// </summary>
        /// <param name="updatedProject">The updated project.</param>
        public async Task UpdateAsync(PublishedProject updatedProject)
        {
            var projectToUpdate = await GetProjectEntityByIdAsync(updatedProject.ProjectId);

            if (projectToUpdate == null)
            {
                throw new ModelNotFoundException(String.Format("The project with id [{0}] was not found.", updatedProject.ProjectId));
            }
            this.logger.Trace("Retrieved project by id {0}.", updatedProject.ProjectId);

            var allLocationIds = updatedProject.LocationIds.Union(updatedProject.RegionIds);
            var locationsExist = await CheckAllLocationsExistAsync(allLocationIds);

            this.logger.Trace("Checked all locations with id {0} existed.", String.Join(", ", allLocationIds));

            var themesExist = await CheckAllThemesExistAsync(updatedProject.ThemeIds);

            this.logger.Trace("Check all themes with ids {0} existed.", String.Join(", ", updatedProject.ThemeIds));

            var goalsExist = await CheckAllGoalsExistAsync(updatedProject.GoalIds);

            this.logger.Trace("Check all goals with ids {0} existed.", String.Join(", ", updatedProject.GoalIds));

            var contactsExist = await CheckAllContactsExistAsync(updatedProject.PointsOfContactIds);

            this.logger.Trace("Check all contacts with ids {0} existed.", String.Join(", ", updatedProject.PointsOfContactIds));

            var categoriesExist = await CheckAllCategoriesExistAsync(updatedProject.CategoryIds);

            this.logger.Trace("Check all categories with ids {0} existed.", String.Join(", ", updatedProject.CategoryIds));

            var objectivesExist = await CheckAllObjectivesExistAsync(updatedProject.ObjectiveIds);

            this.logger.Trace("Check all contacts with ids {0} existed.", String.Join(", ", updatedProject.PointsOfContactIds));

            var office = await CreateGetOrganizationByProjectIdQuery(updatedProject.ProjectId).FirstOrDefaultAsync();

            Contract.Assert(office != null, "The project must have an office.");
            var officeSettings = await officeService.GetOfficeSettingsAsync(office.OrganizationId);

            var allowedCategoryIds = await CreateGetAllowedCategoryIdsQuery(office.OrganizationId).ToListAsync();

            this.logger.Trace("Loaded allowed category ids [{0}] for program with id [{1}].", String.Join(", ", allowedCategoryIds), projectToUpdate.ProgramId);

            var allowedObjectiveIds = await CreateGetAllowedObjectiveIdsQuery(office.OrganizationId).ToListAsync();

            this.logger.Trace("Loaded allowed objective ids [{0}] for program with id [{1}].", String.Join(", ", allowedCategoryIds), projectToUpdate.ProgramId);

            var newInactiveLocationIds = await GetNewInactiveProjectLocations(updatedProject.ProjectId, updatedProject.LocationIds).Select(x => x.LocationId).ToListAsync();

            this.logger.Trace("Loaded locations that were not previously set on the project and are inactive.");

            var regionLocationTypeIds = await LocationQueries.CreateGetLocationTypeIdsQuery(this.Context, updatedProject.RegionIds.ToList()).ToListAsync();

            this.logger.Trace("Loaded region location types.");

            var existingDefaultExchangeVisitorFunding = await Context.DefaultExchangeVisitorFunding.FindAsync(updatedProject.ProjectId);

            this.logger.Trace("Loaded existing default exchange visitor funding.");

            var participantsWithoutParticipantExchangeVisitor = new List <Participant>();

            if (updatedProject.VisitorTypeId == VisitorType.ExchangeVisitor.Id &&
                projectToUpdate.VisitorTypeId != VisitorType.ExchangeVisitor.Id)
            {
                participantsWithoutParticipantExchangeVisitor = await GetParticipantsWithoutParticipantExchangeVisitor(updatedProject.ProjectId).ToListAsync();

                this.logger.Trace("Loaded participant ids without a participant exchange visitor record.");
            }

            var allowedThemeIds = await CreateGetAllowedThemeIdsQuery(projectToUpdate.Themes.Select(x => x.ThemeId)).ToListAsync();

            this.logger.Trace("Loaded allowed theme ids [{0}] for project with id [{1}].", String.Join(", ", allowedThemeIds), projectToUpdate.ProjectId);

            var allowedGoalIds = await CreateGetAllowedGoalIdsQuery(projectToUpdate.Goals.Select(x => x.GoalId)).ToListAsync();

            this.logger.Trace("Loaded allowed goal ids [{0}] for project with id [{1}].", String.Join(", ", allowedGoalIds), projectToUpdate.ProjectId);

            validator.ValidateUpdate(GetUpdateValidationEntity(
                                         publishedProject: updatedProject,
                                         projectToUpdate: projectToUpdate,
                                         goalsExist: goalsExist,
                                         themesExist: themesExist,
                                         locationsExist: locationsExist,
                                         pointsOfContactExist: contactsExist,
                                         settings: officeSettings,
                                         allowedCategoryIds: allowedCategoryIds,
                                         allowedObjectiveIds: allowedObjectiveIds,
                                         categoriesExist: categoriesExist,
                                         objectivesExist: objectivesExist,
                                         newInactiveLocationIds: newInactiveLocationIds,
                                         regionLocationTypeIds: regionLocationTypeIds,
                                         numberOfCategories: updatedProject.CategoryIds.Count(),
                                         numberOfObjectives: updatedProject.ObjectiveIds.Count(),
                                         allowedThemeIds: allowedThemeIds,
                                         allowedGoalIds: allowedGoalIds));
            DoUpdate(updatedProject, projectToUpdate, existingDefaultExchangeVisitorFunding, participantsWithoutParticipantExchangeVisitor);
        }