/// <summary> /// Returns a query to get ItineraryDTOs from the given context. /// </summary> /// <param name="context">The context to query.</param> /// <returns>The query to get itineraries from the given context.</returns> public static IQueryable <ItineraryDTO> CreateGetItinerariesQuery(EcaContext context) { Contract.Requires(context != null, "The context must not be null."); var locationsQuery = LocationQueries.CreateGetLocationsQuery(context); var query = from itinerary in context.Itineraries let hasArrival = itinerary.ArrivalLocationId.HasValue let arrival = locationsQuery.Where(x => x.Id == itinerary.ArrivalLocationId).FirstOrDefault() let hasDeparture = itinerary.DepartureLocationId.HasValue let departure = locationsQuery.Where(x => x.Id == itinerary.DepartureLocationId).FirstOrDefault() let participants = itinerary.Participants let participantsCount = participants.Count() select new ItineraryDTO { ArrivalLocation = hasArrival ? arrival : null, DepartureLocation = hasDeparture ? departure : null, EndDate = itinerary.EndDate, Id = itinerary.ItineraryId, LastRevisedOn = itinerary.History.RevisedOn, Name = itinerary.Name, ParticipantsCount = participantsCount, ProjectId = itinerary.ProjectId, StartDate = itinerary.StartDate }; return(query); }
/// <summary> /// Returns the location with the given id, or null if it is not found. /// </summary> /// <param name="locationId">The id of the location.</param> /// <returns>The location, or null if it does not exist.</returns> public LocationDTO GetLocationById(int locationId) { var location = LocationQueries.CreateGetLocationsQuery(this.Context).Where(x => x.Id == locationId).FirstOrDefault(); logger.Debug("Retrieved location = [{0}] by id [{1}].", location, locationId); return(location); }
/// <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); }
/// <summary> /// Returns a query to retrieve itinerary stops from the given context. /// </summary> /// <param name="context">The context to query.</param> /// <returns>The query to retrieve itinerary stops.</returns> public static IQueryable <ItineraryStopDTO> CreateGetItineraryStopsQuery(EcaContext context) { Contract.Requires(context != null, "The context must not be null."); var locationQuery = LocationQueries.CreateGetLocationsQuery(context); var query = from itineraryStop in context.ItineraryStops let participants = itineraryStop.Participants let participantsCount = participants.Count() let hasDestination = itineraryStop.DestinationId.HasValue let destination = hasDestination ? locationQuery.Where(x => x.Id == itineraryStop.DestinationId.Value).FirstOrDefault() : null select new ItineraryStopDTO { ArrivalDate = itineraryStop.DateArrive, DepartureDate = itineraryStop.DateLeave, DestinationLocation = destination, Participants = itineraryStop.Participants.Where(p => p.PersonId.HasValue).Select(p => new ItineraryStopParticipantDTO { FullName = p.Person.FullName, ItineraryInformationId = -1, ItineraryStopId = itineraryStop.ItineraryStopId, ParticipantId = p.ParticipantId, PersonId = p.Person.PersonId, //TravelingFrom = null }).OrderBy(p => p.FullName), ItineraryId = itineraryStop.ItineraryId, ItineraryStopId = itineraryStop.ItineraryStopId, LastRevisedOn = itineraryStop.History.RevisedOn, Name = itineraryStop.Name, ParticipantsCount = participantsCount, ProjectId = itineraryStop.Itinerary.ProjectId, TimezoneId = itineraryStop.TimezoneId }; return(query); }
/// <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()); }
/// <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()); }
// <summary> /// Returns a query to retrieve projets. /// </summary> /// <param name="context">The context to query</param> /// <returns>Project</returns> public static IQueryable <ProjectDTO> CreateGetProjectDTOQuery(EcaContext context) { Contract.Requires(context != null, "The context must not be null."); var countryTypeId = LocationType.Country.Id; var regionTypeId = LocationType.Region.Id; var allLocations = LocationQueries.CreateGetLocationsQuery(context); var allContacts = ContactQueries.CreateContactQuery(context); var query = from project in context.Projects let program = project.ParentProgram let owner = program.Owner let status = project.Status let themes = project.Themes let goals = project.Goals let categories = project.Categories let objectives = project.Objectives let contacts = from contact in allContacts join projectContact in project.Contacts on contact.Id equals projectContact.ContactId select contact let locations = from location in allLocations join projectLocation in project.Locations on location.Id equals projectLocation.LocationId select location //get country locations of project locations that are not countries or regions let locationCountries = from location in project.Locations join country in context.Locations on location.CountryId equals country.LocationId where location.LocationTypeId != regionTypeId && location.LocationTypeId != countryTypeId select country //get project locations that are themselves countries let countries = from location in project.Locations where location.LocationTypeId == countryTypeId select location //get the countries of the project locations that are regions... let regionCountries = from location in project.Locations join country in context.Locations on location.LocationId equals country.RegionId where location.LocationTypeId == regionTypeId && country.LocationTypeId == countryTypeId && !project.Locations.Contains(country) select country let allCountries = locationCountries .Union(regionCountries) .Union(countries) let regions = from location in allLocations join region in project.Regions on location.Id equals region.LocationId select location let projectRegionCountries = from location in allLocations join region in project.Regions on location.RegionId equals region.LocationId where location.LocationTypeId == countryTypeId select location select new ProjectDTO { Id = project.ProjectId, Name = project.Name, Description = project.Description, ProjectStatusId = status.ProjectStatusId, Status = status.Status, RevisedOn = project.History.RevisedOn, SevisOrgId = project.SevisOrgId, StartDate = project.StartDate, EndDate = project.EndDate, ProgramId = project.ProgramId, ProgramName = program.Name, OwnerId = owner.OrganizationId, OwnerName = owner.Name, OwnerOfficeSymbol = owner.OfficeSymbol, Themes = themes.Select(x => new SimpleLookupDTO { Id = x.ThemeId, Value = x.ThemeName }), CountryIsosByLocations = allCountries.Select(x => new SimpleLookupDTO { Id = x.LocationId, Value = x.LocationIso }).Distinct(), Locations = locations, Goals = goals.Select(x => new SimpleLookupDTO { Id = x.GoalId, Value = x.GoalName }), Contacts = contacts, Objectives = objectives.Select(o => new JustificationObjectiveDTO { Id = o.ObjectiveId, Name = o.ObjectiveName, JustificationName = o.Justification.JustificationName }), Categories = categories.Select(c => new FocusCategoryDTO { Id = c.CategoryId, Name = c.CategoryName, FocusName = c.Focus.FocusName }), Regions = regions, CountryIsosByRegions = projectRegionCountries.Select(x => new SimpleLookupDTO { Id = x.Id, Value = x.LocationIso }).Distinct(), VisitorTypeId = project.VisitorTypeId, VisitorTypeName = project.VisitorType.VisitorTypeName, UsParticipantsEst = project.UsParticipantsEst ?? 0, NonUsParticipantsEst = project.NonUsParticipantsEst ?? 0, UsParticipantsActual = project.UsParticipantsActual ?? 0, NonUsParticipantsActual = project.NonUsParticipantsActual ?? 0 }; return(query); }
/// <summary> /// Returns a query to get biographical data for the dependents of the participant with the given id. /// </summary> /// <param name="context">The context to query.</param> /// <param name="participantId">The participant id.</param> /// <returns>The query to get biographical data of a participant's dependents.</returns> public static IQueryable <DependentBiographicalDTO> CreateGetParticipantDependentsBiographicalQuery(EcaContext context, int participantId) { Contract.Requires(context != null, "The context must not be null."); var maleGenderCode = Gender.SEVIS_MALE_GENDER_CODE_VALUE; var femaleGenderCode = Gender.SEVIS_FEMALE_GENDER_CODE_VALUE; var familyMemberIds = context.Participants .Where(x => x.ParticipantId == participantId && x.PersonId.HasValue) .SelectMany(x => x.Person.Family.Select(f => f.DependentId)); var locationsQuery = LocationQueries.CreateGetLocationsQuery(context); var emailAddressQuery = EmailAddressQueries.CreateGetEmailAddressDTOQuery(context); var query = from dependent in context.PersonDependents let gender = context.Genders.Where(x => x.GenderId == dependent.GenderId).FirstOrDefault() let sevisGender = gender != null && (gender.SevisGenderCode == maleGenderCode || gender.SevisGenderCode == femaleGenderCode) ? gender.SevisGenderCode : null let residenceCountry = context.Locations.Where(x => x.LocationId == dependent.PlaceOfResidenceId).FirstOrDefault() let residenceSevisCountry = residenceCountry != null ? residenceCountry.BirthCountry : null let residenceSevisCountryCode = residenceSevisCountry != null ? residenceSevisCountry.CountryCode : null let birthCity = context.Locations.Where(x => x.LocationId == dependent.PlaceOfBirthId).FirstOrDefault() let birthCountry = birthCity != null ? birthCity.Country : null let sevisBirthCountry = birthCountry != null ? birthCountry.BirthCountry : null let sevisBirthCountryCode = sevisBirthCountry != null ? sevisBirthCountry.CountryCode : null let birthDate = dependent.DateOfBirth let numberOfCitizenships = dependent.CountriesOfCitizenship.Count() let countryOfCitizenship = dependent.CountriesOfCitizenship.OrderByDescending(x => x.IsPrimary).FirstOrDefault() let countryOfCitizenshipLocation = countryOfCitizenship != null ? countryOfCitizenship.Location : null let sevisCountryOfCitizenship = countryOfCitizenshipLocation != null ? countryOfCitizenshipLocation.BirthCountry : null let sevisCountryOfCitizenshipCode = sevisCountryOfCitizenship != null ? sevisCountryOfCitizenship.CountryCode : null let relationship = context.DependentTypes.Where(x => x.DependentTypeId == dependent.DependentTypeId).FirstOrDefault() let relationshipCode = relationship != null ? relationship.SevisDependentTypeCode : null let emailAddress = dependent.EmailAddresses .OrderByDescending(x => x.IsPrimary) .FirstOrDefault() let birthCountryReason = context.BirthCountryReasons.Where(x => x.BirthCountryReasonId == dependent.BirthCountryReasonId).FirstOrDefault() where familyMemberIds.Contains(dependent.DependentId) && !dependent.IsSevisDeleted select new DependentBiographicalDTO { PermanentResidenceAddressId = null, BirthCity = birthCity.LocationName, BirthCountryCode = sevisBirthCountryCode, BirthCountryReasonId = dependent.BirthCountryReasonId, BirthCountryReasonCode = birthCountryReason != null ? birthCountryReason.BirthReasonCode : null, BirthDate = birthDate, CitizenshipCountryCode = numberOfCitizenships == 1 ? sevisCountryOfCitizenshipCode : null, EmailAddress = emailAddress != null ? emailAddress.Address : null, EmailAddressId = emailAddress != null ? emailAddress.EmailAddressId : default(int?), IsTravelingWithParticipant = dependent.IsTravellingWithParticipant, IsDeleted = dependent.IsDeleted, FullName = new FullNameDTO { FirstName = dependent.FirstName != null && dependent.FirstName.Trim().Length > 0 ? dependent.FirstName.Trim() : null, LastName = dependent.LastName != null && dependent.LastName.Trim().Length > 0 ? dependent.LastName.Trim() : null, Suffix = dependent.NameSuffix != null && dependent.NameSuffix.Trim().Length > 0 ? dependent.NameSuffix.Trim() : null, PassportName = dependent.PassportName != null && dependent.PassportName.Trim().Length > 0 ? dependent.PassportName.Trim() : null, PreferredName = dependent.PreferredName != null && dependent.PreferredName.Trim().Length > 0 ? dependent.PreferredName.Trim() : null, }, Gender = gender != null && sevisGender != null ? sevisGender : null, GenderId = gender.GenderId, NumberOfCitizenships = numberOfCitizenships, PermanentResidenceCountryCode = residenceSevisCountryCode, PersonId = dependent.DependentId, ParticipantId = participantId, Relationship = relationshipCode, DependentTypeId = relationship != null ? relationship.DependentTypeId : -1, SevisId = dependent.SevisId }; return(query); }
/// <summary> /// Returns a query to get dtos. /// </summary> /// <returns>The query to get location dtos.</returns> protected override IQueryable <LocationDTO> GetSelectDTOQuery() { return(LocationQueries.CreateGetLocationsQuery(this.Context)); }
/// <summary> /// Get pii by id /// </summary> /// <param name="context">The context to query</param> /// <param name="personId">The person id to lookup</param> /// <returns>Personally identifiable information for person</returns> public static IQueryable <PiiDTO> CreateGetPiiByIdQuery(EcaContext context, int personId) { Contract.Requires(context != null, "The context must not be null."); var locationsQuery = LocationQueries.CreateGetLocationsQuery(context); var query = from person in context.People let currentParticipant = person.Participations.OrderByDescending(p => p.ParticipantStatusId).FirstOrDefault() let hasPlaceOfBirth = person.PlaceOfBirthId.HasValue let cityOfBirth = hasPlaceOfBirth ? person.PlaceOfBirth : null let locationOfBirth = hasPlaceOfBirth ? locationsQuery.Where(x => x.Id == person.PlaceOfBirthId).FirstOrDefault() : null where person.PersonId == personId select new PiiDTO { Gender = person.Gender.GenderName, GenderId = person.GenderId, DateOfBirth = person.DateOfBirth, IsDateOfBirthUnknown = person.IsDateOfBirthUnknown, IsDateOfBirthEstimated = person.IsDateOfBirthEstimated, CountriesOfCitizenship = person.CountriesOfCitizenship.Select(x => new SimpleLookupDTO { Id = x.LocationId, Value = x.LocationName }).OrderBy(l => l.Value), Dependents = person.Family.Where(x => x.IsDeleted == false).Select(x => new SimpleLookupDTO { Id = x.DependentId, Value = x.LastName + ", " + x.FirstName + " (" + x.DependentType.Name + ")" }), IsSingleName = person.IsSingleName, FirstName = person.FirstName, LastName = person.LastName, NamePrefix = person.NamePrefix, NameSuffix = person.NameSuffix, GivenName = person.GivenName, FamilyName = person.FamilyName, MiddleName = person.MiddleName, PassportName = person.PassportName, Patronym = person.Patronym, Alias = person.Alias, MaritalStatus = person.MaritalStatus.Description, MaritalStatusId = person.MaritalStatus.MaritalStatusId, Ethnicity = person.Ethnicity, MedicalConditions = person.MedicalConditions, Addresses = (from address in person.Addresses let addressType = address.AddressType let location = address.Location let hasCity = location.City != null let city = location.City let hasCountry = location.Country != null let country = location.Country let hasDivision = location.Division != null let division = location.Division select new AddressDTO { AddressId = address.AddressId, AddressType = addressType.AddressName, AddressTypeId = addressType.AddressTypeId, City = hasCity ? city.LocationName : null, CityId = location.CityId, Country = hasCountry ? country.LocationName : null, CountryId = location.CountryId, CountryIso2 = location.LocationIso2, Division = hasDivision ? division.LocationName : null, DivisionId = location.DivisionId, IsPrimary = address.IsPrimary, LocationId = location.LocationId, LocationName = location.LocationName, OrganizationId = address.OrganizationId, PostalCode = location.PostalCode, PersonId = address.PersonId, Street1 = location.Street1, Street2 = location.Street2, Street3 = location.Street3, }).OrderByDescending(a => a.IsPrimary).ThenBy(a => a.AddressType), IsPlaceOfBirthUnknown = person.IsPlaceOfBirthUnknown, PlaceOfBirth = hasPlaceOfBirth ? locationOfBirth : null, ParticipantId = currentParticipant == null ? 0 : currentParticipant.ParticipantId, ProjectId = currentParticipant == null ? 0 : currentParticipant.ProjectId, SevisId = currentParticipant == null ? "" : currentParticipant.ParticipantPerson.SevisId }; return(query); }
/// <summary> /// Returns a query capable of retrieving dependents from the given context. /// </summary> /// <param name="context">The context to query</param> /// <returns>The query to retrieve dependents from the context</returns> public static IQueryable <SimplePersonDependentDTO> CreateGetSimplePersonDependentDTOsQuery(EcaContext context) { Contract.Requires(context != null, "The context must not be null."); var locationsQuery = LocationQueries.CreateGetLocationsQuery(context); var dependentTypesQuery = CreateGetDependentTypesQuery(context); var birthCountryReasonQuery = CreateGetBirthCountryReasonsQuery(context); var query = from dependent in context.PersonDependents let locationOfBirth = locationsQuery.Where(x => x.Id == dependent.PlaceOfBirthId).FirstOrDefault() let dependentType = dependentTypesQuery.Where(x => x.Id == dependent.DependentTypeId).FirstOrDefault() let birthCountryReason = birthCountryReasonQuery.Where(x => x.Id == dependent.BirthCountryReasonId).FirstOrDefault() let permanentResidence = locationsQuery.Where(x => x.Id == dependent.PlaceOfResidenceId).FirstOrDefault() let PermanentResidence = (from address in context.Addresses let addressType = address.AddressType let location = address.Location let hasCity = location.City != null let city = location.City let hasCountry = location.Country != null let country = location.Country let hasDivision = location.Division != null let division = location.Division where address.LocationId == dependent.PlaceOfResidenceId select new AddressDTO { AddressId = address.AddressId, AddressType = addressType.AddressName, AddressTypeId = addressType.AddressTypeId, City = hasCity ? city.LocationName : null, CityId = location.CityId, Country = hasCountry ? country.LocationName : null, CountryId = location.CountryId, CountryIso2 = location.LocationIso2, Division = hasDivision ? division.LocationName : null, DivisionId = location.DivisionId, IsPrimary = address.IsPrimary, LocationId = location.LocationId, LocationName = location.LocationName, OrganizationId = address.OrganizationId, PersonId = address.PersonId, }).FirstOrDefault() where dependent.IsDeleted == false select new SimplePersonDependentDTO { DependentId = dependent.DependentId, PersonId = dependent.PersonId, SevisId = dependent.SevisId, DependentTypeId = dependent.DependentTypeId, DependentType = dependent.DependentType.Name, IsSingleName = dependent.IsSingleName, FirstName = dependent.FirstName, LastName = dependent.LastName, NameSuffix = dependent.NameSuffix, PassportName = dependent.PassportName, PreferredName = dependent.PreferredName, GenderId = dependent.GenderId, Gender = dependent.Gender.GenderName, EmailAddress = dependent.EmailAddresses.Select(x => x.Address).FirstOrDefault(), DateOfBirth = dependent.DateOfBirth, PlaceOfBirthId = dependent.PlaceOfBirthId, PlaceOfBirth = locationOfBirth, CountriesOfCitizenship = dependent.CountriesOfCitizenship.Select(x => new CitizenCountryDTO { LocationId = x.LocationId, LocationName = x.Location.LocationName, IsPrimary = x.IsPrimary }), PlaceOfResidenceId = dependent.PlaceOfResidenceId, PlaceOfResidence = permanentResidence, BirthCountryReasonId = dependent.BirthCountryReasonId, BirthCountryReason = birthCountryReason, IsTravellingWithParticipant = dependent.IsTravellingWithParticipant, IsDeleted = dependent.IsDeleted, IsSevisDeleted = dependent.IsSevisDeleted, HasDS2019 = dependent.DS2019FileName != null }; return(query); }
/// <summary> /// Returns an EcaProgram query. /// </summary> /// <param name="context">The context to query.</param> /// <returns>The EcaProgram query.</returns> public static IQueryable <ProgramDTO> CreateGetPublishedProgramsQuery(EcaContext context) { Contract.Requires(context != null, "The context must not be null."); var regionTypeId = LocationType.Region.Id; var countryTypeId = LocationType.Country.Id; var allLocations = LocationQueries.CreateGetLocationsQuery(context); var query = from program in context.Programs let owner = program.Owner let themes = program.Themes let parentProgram = program.ParentProgram let goals = program.Goals let contacts = program.Contacts let categories = program.Categories let objectives = program.Objectives let status = program.ProgramStatus let websites = program.Websites let regions = from location in allLocations join programRegion in program.Regions on location.Id equals programRegion.LocationId select location let countries = from country in allLocations join region in regions on country.RegionId equals region.Id where country.LocationTypeId == countryTypeId select country join officeSetting in context.OfficeSettings on owner equals officeSetting.Office into focusSetting from tempFocusSetting in focusSetting.Where(x => x.Name == OfficeSetting.FOCUS_SETTING_KEY).DefaultIfEmpty() join officeSetting in context.OfficeSettings on owner equals officeSetting.Office into objectiveSetting from tempObjectiveSetting in objectiveSetting.Where(x => x.Name == OfficeSetting.OBJECTIVE_SETTING_KEY).DefaultIfEmpty() select new ProgramDTO { Contacts = contacts.Select(x => new SimpleLookupDTO { Id = x.ContactId, Value = x.FullName + " (" + x.Position + ")" }), CountryIsos = countries.Select(x => new SimpleLookupDTO { Id = x.Id, Value = x.LocationIso }), Categories = categories.Select(c => new FocusCategoryDTO { Id = c.CategoryId, Name = c.CategoryName, FocusName = c.Focus.FocusName }), Description = program.Description, EndDate = program.EndDate, Goals = goals.Select(x => new SimpleLookupDTO { Id = x.GoalId, Value = x.GoalName }), Id = program.ProgramId, Objectives = objectives.Select(o => new JustificationObjectiveDTO { Id = o.ObjectiveId, Name = o.ObjectiveName, JustificationName = o.Justification.JustificationName }), Name = program.Name, OwnerDescription = owner.Description, OwnerName = owner.Name, OwnerOfficeSymbol = owner.OfficeSymbol, OwnerOrganizationId = owner.OrganizationId, OwnerOrganizationCategoryLabel = tempFocusSetting == null ? OfficeSettings.CATEGORY_DEFAULT_LABEL : tempFocusSetting.Value, OwnerOrganizationObjectiveLabel = tempObjectiveSetting == null ? OfficeSettings.OBJECTIVE_DEFAULT_LABEL : tempObjectiveSetting.Value, ParentProgramId = parentProgram == null ? default(int?) : parentProgram.ProgramId, ParentProgramName = parentProgram == null ? null : parentProgram.Name, RevisedOn = program.History.RevisedOn, RegionIsos = regions.Select(x => new SimpleLookupDTO { Id = x.Id, Value = x.LocationIso }), Regions = regions, RowVersion = program.RowVersion, StartDate = program.StartDate, Themes = themes.Select(x => new SimpleLookupDTO { Id = x.ThemeId, Value = x.ThemeName }), ProgramStatusId = program.ProgramStatusId, Websites = websites.Select(x => new SimpleLookupDTO { Id = x.WebsiteId, Value = x.WebsiteValue }), ProgramStatusName = status.Status }; return(query); }
/// <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); }