示例#1
0
        private void DoUpdate(EcaOrganization organization, Organization organizationToUpdate, Organization parentOrganization, OrganizationType organizationType)
        {
            throwIfOrganizationByIdNull(organization.OrganizationId, organizationToUpdate);
            if (organization.ParentOrganizationId.HasValue)
            {
                throwIfOrganizationByIdNull(organization.ParentOrganizationId.Value, parentOrganization);
            }

            throwIfOrganizationTypeByIdNull(organization.OrganizationTypeId, organizationType);
            organizationValidator.ValidateUpdate(GetOrganizationValidationEntity(organization, organizationToUpdate, parentOrganization));
            organization.Update.SetHistory(organizationToUpdate);
            SetPointOfContacts(organization.ContactIds.ToList(), organizationToUpdate);
            SetOrganizationRoles(organization.OrganizationRoleIds.ToList(), organizationToUpdate);
            organizationToUpdate.Name        = organization.Name;
            organizationToUpdate.Description = organization.Description;
            if (parentOrganization != null)
            {
                organizationToUpdate.ParentOrganization   = parentOrganization;
                organizationToUpdate.ParentOrganizationId = parentOrganization.OrganizationId;
            }
            else
            {
                organizationToUpdate.ParentOrganization   = null;
                organizationToUpdate.ParentOrganizationId = null;
            }
            organizationToUpdate.OrganizationTypeId = organization.OrganizationTypeId;
            organizationToUpdate.Website            = organization.Website;
        }
示例#2
0
 private void DoUpdate(
     UpdatedEcaAddress updatedAddress,
     Location location,
     Address address,
     ICollection <Address> otherAddresses,
     Location country,
     Location division,
     Location city)
 {
     Contract.Requires(updatedAddress != null, "The updated address must not be null.");
     Contract.Requires(location != null, "The location must not be null.");
     Contract.Requires(address != null, "The address must not be null.");
     logger.Info("Updating the address with id [{0}].", updatedAddress.AddressId);
     addressValidator.ValidateUpdate(ToEcaAddressValidationEntity(address: updatedAddress, country: country, division: division, city: city));
     location.CityId         = updatedAddress.CityId;
     location.CountryId      = updatedAddress.CountryId;
     location.DivisionId     = updatedAddress.DivisionId;
     location.LocationName   = updatedAddress.LocationName;
     location.LocationTypeId = updatedAddress.LocationTypeId;
     location.PostalCode     = updatedAddress.PostalCode;
     location.Street1        = updatedAddress.Street1;
     location.Street2        = updatedAddress.Street2;
     location.Street3        = updatedAddress.Street3;
     address.AddressTypeId   = updatedAddress.AddressTypeId;
     address.IsPrimary       = updatedAddress.IsPrimary;
     updatedAddress.Update.SetHistory(location);
     updatedAddress.Update.SetHistory(address);
     if (updatedAddress.IsPrimary)
     {
         SetAllAddressesNotPrimary(otherAddresses);
     }
 }
示例#3
0
        private void DoSetParticipants(Itinerary itinerary, ItineraryParticipants itineraryParticipants, IEnumerable <int> itineraryStopParticipantsById, IEnumerable <int> nonPersonParticipantsById)
        {
            var orphanedItineraryStopParticipantsById = itineraryStopParticipantsById.Except(itineraryParticipants.ParticipantIds).ToList();

            itineraryParticipantsValidator.ValidateUpdate(new ItineraryParticipantsValidationEntity(
                                                              orphanedParticipantsByParticipantId: orphanedItineraryStopParticipantsById,
                                                              nonPersonParticipantsByParticipantIds: nonPersonParticipantsById
                                                              ));
            itineraryParticipants.Audit.SetHistory(itinerary);
            SetParticipants(itineraryParticipants.ParticipantIds.ToList(), itinerary, x => x.Participants);
        }
示例#4
0
 private void DoUpdate(UpdatedEcaItinerary updatedItinerary, Itinerary itineraryToUpdate, Location arrivalLocation, Location departureLocation)
 {
     ecaItineraryValidator.ValidateUpdate(GetUpdatedEcaItineraryValidationEntity(
                                              updatedItinerary: updatedItinerary,
                                              itineraryToUpdate: itineraryToUpdate,
                                              arrivalLocation: arrivalLocation,
                                              departureLocation: departureLocation,
                                              stops: itineraryToUpdate.Stops));
     updatedItinerary.Audit.SetHistory(itineraryToUpdate);
     itineraryToUpdate.ArrivalLocationId   = arrivalLocation.LocationId;
     itineraryToUpdate.DepartureLocationId = departureLocation.LocationId;
     itineraryToUpdate.EndDate             = updatedItinerary.EndDate;
     itineraryToUpdate.Name      = updatedItinerary.Name;
     itineraryToUpdate.StartDate = updatedItinerary.StartDate;
 }
        private void DoUpdate(Itinerary itinerary, UpdatedEcaItineraryStop updatedStop, ItineraryStop itineraryStop)
        {
            var validationEntity = GetEcaItineraryStopValidationEntity(itinerary: itinerary, ecaitineraryStop: updatedStop);

            itineraryStopValidator.ValidateUpdate(validationEntity);

            itineraryStop.DateArrive    = updatedStop.ArrivalDate;
            itineraryStop.DateLeave     = updatedStop.DepartureDate;
            itineraryStop.DestinationId = updatedStop.DestinationLocationId;
            itineraryStop.Name          = updatedStop.Name;
            itineraryStop.TimezoneId    = updatedStop.TimezoneId;

            Contract.Assert(updatedStop.Audit.GetType() == typeof(Update), "The audit type must be an update.  The itinerary create date should not change.");
            updatedStop.Audit.SetHistory(itineraryStop);
            updatedStop.Audit.SetHistory(itinerary);
        }
        private void DoSetParticipants(
            Itinerary itinerary,
            ItineraryStop itineraryStop,
            IEnumerable <Participant> itineraryParticipants,
            ItineraryStopParticipants itineraryStopParticipants)
        {
            var notAllowedParticipantsById = itineraryStopParticipants.ParticipantIds.Except(itineraryParticipants.Select(x => x.ParticipantId).Distinct());

            var validationEntity = new ItineraryStopParticipantsValidationEntity(notAllowedParticipantsById);

            itineraryStopParticipantsValidator.ValidateUpdate(validationEntity);

            Contract.Assert(itineraryStopParticipants.Audit.GetType() == typeof(Update), "The audit type must be an update.  The itinerary create date should not change.");
            itineraryStopParticipants.Audit.SetHistory(itineraryStop);
            itineraryStopParticipants.Audit.SetHistory(itinerary);
            SetParticipants(itineraryStopParticipants.ParticipantIds.ToList(), itineraryStop, x => x.Participants);
        }
示例#7
0
        private void DoUpdate(
            UpdatedLocation updatedLocation,
            Location locationToUpdate,
            Location region,
            Location country,
            Location division,
            Location city,
            LocationType locationType)
        {
            var validationEntity = GetLocationValidationEntity(
                region: region,
                location: updatedLocation,
                country: country,
                division: division,
                city: city
                );

            locationValidator.ValidateUpdate(validationEntity);
            if (division == null && city != null && city.Division != null)
            {
                division = city.Division;
            }
            if (country == null && division != null && division.Country != null)
            {
                country = division.Country;
            }
            if (region == null && country != null && country.Region != null)
            {
                region = country.Region;
            }
            locationToUpdate.City         = city;
            locationToUpdate.Country      = country;
            locationToUpdate.Division     = division;
            locationToUpdate.Region       = region;
            locationToUpdate.Latitude     = updatedLocation.Latitude;
            locationToUpdate.Longitude    = updatedLocation.Longitude;
            locationToUpdate.LocationName = updatedLocation.LocationName;
            locationToUpdate.LocationType = locationType;
            updatedLocation.Audit.SetHistory(locationToUpdate);
        }
示例#8
0
        private void DoUpdate(Program programToUpdate, EcaProgram updatedProgram, ProgramServiceValidationEntity validationEntity)
        {
            Contract.Requires(updatedProgram != null, "The updated program must not be null.");
            validator.ValidateUpdate(validationEntity);
            programToUpdate.Description     = updatedProgram.Description;
            programToUpdate.EndDate         = updatedProgram.EndDate;
            programToUpdate.Name            = updatedProgram.Name;
            programToUpdate.OwnerId         = updatedProgram.OwnerOrganizationId;
            programToUpdate.ParentProgramId = updatedProgram.ParentProgramId;
            programToUpdate.ProgramStatusId = updatedProgram.ProgramStatusId;
            programToUpdate.RowVersion      = updatedProgram.RowVersion;
            programToUpdate.StartDate       = updatedProgram.StartDate;

            updatedProgram.Audit.SetHistory(programToUpdate);

            SetGoals(updatedProgram.GoalIds, programToUpdate);
            SetPointOfContacts(updatedProgram.ContactIds, programToUpdate);
            SetThemes(updatedProgram.ThemeIds, programToUpdate);
            SetRegions(updatedProgram.RegionIds, programToUpdate);
            SetCategories(updatedProgram.FocusCategoryIds, programToUpdate);
            SetObjectives(updatedProgram.JustificationObjectiveIds, programToUpdate);
            SetWebsitesToUpdate(updatedProgram, programToUpdate);
        }
        private void DoCreateOrUpdate(
            UpdatedParticipantPerson updatedPerson,
            Participant participant,
            ParticipantPerson participantPerson,
            ParticipantType participantType,
            ParticipantStatus participantStatus,
            Organization host,
            Organization home,
            Address hostAddress,
            Address homeAddress)
        {
            participantPersonValidator.ValidateUpdate(GetUpdatedPersonParticipantValidationEntity(participantType));
            updatedPerson.Audit.SetHistory(participant);
            updatedPerson.Audit.SetHistory(participantPerson);

            participantPerson.HomeInstitutionId        = updatedPerson.HomeInstitutionId;
            participantPerson.HomeInstitutionAddressId = updatedPerson.HomeInstitutionAddressId;

            participantPerson.HostInstitutionId        = updatedPerson.HostInstitutionId;
            participantPerson.HostInstitutionAddressId = updatedPerson.HostInstitutionAddressId;
            participant.ParticipantTypeId   = updatedPerson.ParticipantTypeId;
            participant.ParticipantStatusId = updatedPerson.ParticipantStatusId;
        }
示例#10
0
 private void DoUpdate(UpdatePii updatePii, Person person, Location cityOfBirth, List <Location> countriesOfCitizenship)
 {
     validator.ValidateUpdate(GetPersonServiceValidationEntity(
                                  person: person,
                                  dateOfBirth: updatePii.DateOfBirth,
                                  genderId: updatePii.GenderId,
                                  countriesOfCitizenship: countriesOfCitizenship,
                                  placeOfBirthId: cityOfBirth != null ? cityOfBirth.LocationId : default(int?),
                                  isDateOfBirthUnknown: updatePii.IsDateOfBirthUnknown,
                                  isDateOfBirthEstimated: updatePii.IsDateOfBirthEstimated,
                                  isPlaceOfBirthUnknown: updatePii.IsPlaceOfBirthUnknown
                                  ));
     person.IsSingleName           = updatePii.IsSingleName;
     person.FirstName              = updatePii.FirstName;
     person.LastName               = updatePii.LastName;
     person.NamePrefix             = updatePii.NamePrefix;
     person.NameSuffix             = updatePii.NameSuffix;
     person.GivenName              = updatePii.GivenName;
     person.FamilyName             = updatePii.FamilyName;
     person.MiddleName             = updatePii.MiddleName;
     person.PassportName           = updatePii.PassportName;
     person.Patronym               = updatePii.Patronym;
     person.Alias                  = updatePii.Alias;
     person.GenderId               = updatePii.GenderId;
     person.Ethnicity              = updatePii.Ethnicity;
     person.PlaceOfBirth           = cityOfBirth;
     person.PlaceOfBirthId         = updatePii.CityOfBirthId;
     person.IsPlaceOfBirthUnknown  = updatePii.IsPlaceOfBirthUnknown;
     person.DateOfBirth            = updatePii.DateOfBirth;
     person.IsDateOfBirthUnknown   = updatePii.IsDateOfBirthUnknown;
     person.MedicalConditions      = updatePii.MedicalConditions;
     person.MaritalStatusId        = updatePii.MaritalStatusId;
     person.IsDateOfBirthEstimated = updatePii.IsDateOfBirthEstimated;
     updatePii.Audit.SetHistory(person);
     SetCountriesOfCitizenship(countriesOfCitizenship, person);
 }
示例#11
0
        /// <summary>
        /// Updates the system's project with the given updated project.
        /// </summary>
        /// <param name="updatedProject">The updated project.</param>
        public void Update(PublishedProject updatedProject)
        {
            var projectToUpdate = GetProjectEntityById(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 = CheckAllLocationsExist(allLocationIds);

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

            var themesExist = CheckAllThemesExist(updatedProject.ThemeIds);

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

            var goalsExist = CheckAllGoalsExist(updatedProject.GoalIds);

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

            var contactsExist = CheckAllContactsExist(updatedProject.PointsOfContactIds);

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

            var categoriesExist = CheckAllCategoriesExist(updatedProject.CategoryIds);

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

            var objectivesExist = CheckAllObjectivesExist(updatedProject.ObjectiveIds);

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

            var office = CreateGetOrganizationByProjectIdQuery(updatedProject.ProjectId).FirstOrDefault();

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

            var allowedCategoryIds = CreateGetAllowedCategoryIdsQuery(office.OrganizationId).ToList();

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

            var allowedObjectiveIds = CreateGetAllowedObjectiveIdsQuery(office.OrganizationId).ToList();

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

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

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

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

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

            var existingDefaultExchangeVisitorFunding = Context.DefaultExchangeVisitorFunding.Find(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 = GetParticipantsWithoutParticipantExchangeVisitor(updatedProject.ProjectId).ToList();
                this.logger.Trace("Loaded participant ids without a participant exchange visitor record.");
            }

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

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

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

            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);
        }