/// <summary>
        /// Returns the distinct list of location types for the given locations by id.
        /// </summary>
        /// <param name="locationIds">The locations by id.</param>
        /// <returns>The list of location type ids.</returns>
        public async Task <List <int> > GetLocationTypeIdsAsync(List <int> locationIds)
        {
            var ids = await LocationQueries.CreateGetLocationTypeIdsQuery(this.Context, locationIds).ToListAsync();

            this.logger.Trace("Retrieved location types for location ids {0}.", String.Join(", ", locationIds));
            return(ids);
        }
Exemple #2
0
 /// <summary>
 /// Returns the location types for the given location ids.
 /// </summary>
 /// <param name="locationIds">The list of location ids.</param>
 /// <returns>The list of location type ids.</returns>
 public async Task <List <int> > GetLocationTypeIdsAsync(List <int> locationIds)
 {
     return(await LocationQueries.CreateGetLocationTypeIdsQuery(this.Context, locationIds).ToListAsync());
 }
Exemple #3
0
 /// <summary>
 /// Returns the location types for the given location ids.
 /// </summary>
 /// <param name="locationIds">The list of location ids.</param>
 /// <returns>The list of location type ids.</returns>
 public List <int> GetLocationTypeIds(List <int> locationIds)
 {
     Contract.Requires(locationIds != null, "The location ids must not be null.");
     return(LocationQueries.CreateGetLocationTypeIdsQuery(this.Context, locationIds).ToList());
 }
Exemple #4
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);
        }