Exemple #1
0
        /// <summary>
        /// Constructor
        /// </summary>
        /// <param name="saveActions">The save actions.</param>
        /// <param name="context">The context to query</param>
        public PersonService(EcaContext context, IBusinessValidator <PersonServiceValidationEntity, PersonServiceValidationEntity> validator, List <ISaveAction> saveActions = null)
            : base(context, saveActions)
        {
            Contract.Requires(context != null, "The context must not be null.");
            Contract.Requires(validator != null, "The validator must not be null.");
            this.validator = validator;

            throwIfLocationNotFound = (location, id) =>
            {
                if (location == null)
                {
                    throw new ModelNotFoundException(String.Format("The location entity with id [{0}] was not found.", id));
                }
            };
            throwValidationErrorIfParticipantSevisInfoIsLocked = (participant) =>
            {
                participant.ValidateSevisLock();
            };
            throwIfModelDoesNotExist = (id, instance, type) =>
            {
                if (instance == null)
                {
                    throw new ModelNotFoundException(String.Format("The model of type [{0}] with id [{1}] was not found.", type.Name, id));
                }
            };
        }
 /// <summary>
 /// Creates a new instance of the service with the context to query and the validators.
 /// </summary>
 /// <param name="context">The context to operate against.</param>
 /// <param name="exchangeVisitorService">The exchange visitor service that is capable of executing validation.</param>
 /// <param name="exchangeVisitorValidator">The update exchange visitor validator.</param>
 /// <param name="saveActions">The context save actions.</param>
 public ExchangeVisitorValidationService(
     EcaContext context,
     IExchangeVisitorService exchangeVisitorService,
     IParticipantPersonsSevisService participantPersonSevisService,
     AbstractValidator <ExchangeVisitor> exchangeVisitorValidator = null,
     List <ISaveAction> saveActions = null)
     : base(context, saveActions)
 {
     Contract.Requires(exchangeVisitorService != null, "The exchange visitor service must not be null.");
     Contract.Requires(context != null, "The context must not be null.");
     Contract.Requires(participantPersonSevisService != null, "The participantPersonSevisService must not be null.");
     this.exchangeVisitorService        = exchangeVisitorService;
     this.participantPersonSevisService = participantPersonSevisService;
     if (exchangeVisitorValidator == null)
     {
         this.ExchangeVisitorValidator = new ExchangeVisitorValidator();
     }
     else
     {
         this.ExchangeVisitorValidator = exchangeVisitorValidator;
     }
     throwIfModelDoesNotExist = (id, instance, type) =>
     {
         if (instance == null)
         {
             throw new ModelNotFoundException(String.Format("The model of type [{0}] with id [{1}] was not found.", type.Name, id));
         }
     };
 }
Exemple #3
0
        /// <summary>
        /// Returns the contact information for a person
        /// </summary>
        /// <param name="context">The context to query</param>
        /// <param name="personId">The person id to lookup</param>
        /// <returns>The contact information for a person</returns>
        public static IQueryable <ContactInfoDTO> CreateGetContactInfoByIdQuery(EcaContext context, int personId)
        {
            Contract.Requires(context != null, "The context must not be null.");
            var emailAddressQuery = EmailAddressQueries.CreateGetEmailAddressDTOQuery(context);
            var phoneNumberQuery  = PhoneNumberQueries.CreateGetPhoneNumberDTOQuery(context);

            var query = from person in context.People
                        let participantPerson = context.ParticipantPersons.Where(x => x.Participant.PersonId == person.PersonId).FirstOrDefault()
                                                let currentParticipant = person.Participations.OrderByDescending(p => p.ParticipantStatusId).FirstOrDefault()
                                                                         where person.PersonId == personId
                                                                         select new ContactInfoDTO
            {
                EmailAddresses = emailAddressQuery.Where(x => x.PersonId == personId),
                SocialMedias   = person.SocialMedias.Select(x => new SocialMediaDTO
                {
                    Id = x.SocialMediaId,
                    SocialMediaType   = x.SocialMediaType.SocialMediaTypeName,
                    SocialMediaTypeId = x.SocialMediaTypeId,
                    Value             = x.SocialMediaValue
                }).OrderBy(s => s.SocialMediaType),
                PhoneNumbers        = phoneNumberQuery.Where(x => x.PersonId == personId),
                HasContactAgreement = person.HasContactAgreement,
                PersonId            = person.PersonId,
                ParticipantId       = currentParticipant == null ? 0 : currentParticipant.ParticipantId,
                ProjectId           = currentParticipant == null ? 0 : currentParticipant.ProjectId,
                SevisId             = currentParticipant == null ? "" : currentParticipant.ParticipantPerson.SevisId
            };

            return(query);
        }
        /// <summary>
        /// Returns a query to get the us government funding of a participant for sevis.
        /// </summary>
        /// <param name="context">The context to query.</param>
        /// <param name="participantId">The participant id.</param>
        /// <returns>The query to get us government funding as it relates to sevis.</returns>
        public static IQueryable <ExchangeVisitorFundingDTO> CreateGetUSFundingQuery(EcaContext context, int participantId)
        {
            Contract.Requires(context != null, "The context must not be null.");
            var query = from visitor in context.ParticipantExchangeVisitors

                        let firstUsGovFundingAgency = visitor.GovtAgency1
                                                      let secondUsGovFundingAgency = visitor.GovtAgency2

                                                                                     let hasFirstUsGovFunding = visitor.FundingGovtAgency1.HasValue && visitor.FundingGovtAgency1.Value > 0
                                                                                                                let hasSecondUsGovFunding = visitor.FundingGovtAgency2.HasValue && visitor.FundingGovtAgency2.Value > 0

                                                                                                                                            let otherName1 = firstUsGovFundingAgency == null ||
                                                                                                                                                             (firstUsGovFundingAgency != null && firstUsGovFundingAgency.AgencyCode == USGovernmentFundingValidator.OTHER_ORG_CODE)
                            ? visitor.GovtAgency1OtherName : null

                                                                                                                                                             let otherName2 = secondUsGovFundingAgency == null ||
                                                                                                                                                                              (secondUsGovFundingAgency != null && secondUsGovFundingAgency.AgencyCode == USGovernmentFundingValidator.OTHER_ORG_CODE)
                            ? visitor.GovtAgency2OtherName : null

                                                                                                                                                                              where visitor.ParticipantId == participantId

                                                                                                                                                                              select new ExchangeVisitorFundingDTO
            {
                Amount1    = hasFirstUsGovFunding ? visitor.FundingGovtAgency1 : null,
                Org1       = firstUsGovFundingAgency != null && hasFirstUsGovFunding ? firstUsGovFundingAgency.AgencyCode : null,
                OtherName1 = otherName1 != null && otherName1.Length > 0 ? otherName1 : null,

                Amount2    = hasSecondUsGovFunding ? visitor.FundingGovtAgency2 : null,
                Org2       = secondUsGovFundingAgency != null && hasSecondUsGovFunding ? secondUsGovFundingAgency.AgencyCode : null,
                OtherName2 = otherName2 != null && otherName2.Length > 0 ? otherName2 : null
            };

            return(query);
        }
        public static SnapshotGraphDTO CreateGetProgramParticipantAgeQuery(EcaContext context, IEnumerable <int> programIds)
        {
            // TODO: get participant ages
            var ranges = new[] { 16, 25, 35, 50, 51 };

            throw new NotImplementedException();
        }
        /// <summary>
        /// Returns the focus dto with the given focus id.
        /// </summary>
        /// <param name="context">The context to query.</param>
        /// <param name="focusId">the id of the focus.</param>
        /// <returns>The focus dto.</returns>
        public static IQueryable <FocusDTO> CreateGetFocusByIdQuery(EcaContext context, int focusId)
        {
            Contract.Requires(context != null, "The context must not be null.");
            var query = CreateGetFocusDTOQuery(context).Where(x => x.Id == focusId);

            return(query);
        }
Exemple #7
0
        /// <summary>
        /// Returns the participant by participant id
        /// </summary>
        /// <param name="context">The context to query</param>
        /// <param name="participantId">The participant id to lookup</param>
        /// <returns>The participant</returns>
        public static IQueryable <ParticipantDTO> CreateGetParticipantDTOByIdQuery(EcaContext context, int participantId)
        {
            Contract.Requires(context != null, "The context must not be null.");
            var query = from participant in context.Participants
                        let person = participant.Person
                                     let participantType = participant.ParticipantType
                                                           where participant.PersonId != null &&
                                                           participant.ParticipantId == participantId
                                                           select new ParticipantDTO
            {
                Name                    = person.FullName,
                OrganizationId          = default(int?),
                ParticipantId           = participant.ParticipantId,
                ParticipantType         = participantType.Name,
                ParticipantTypeId       = participantType.ParticipantTypeId,
                IsPersonParticipantType = participantType.IsPerson,
                PersonId                = person.PersonId,
                ProjectId               = participant.ProjectId,
                ParticipantStatus       = participant.Status.Status,
                StatusId                = participant.ParticipantStatusId,
                StatusDate              = participant.StatusDate,
                RevisedOn               = participant.History.RevisedOn
            };

            return(query);
        }
Exemple #8
0
 /// <summary>
 /// Constructor
 /// </summary>
 /// <param name="context">The db context</param>
 /// <param name="officeService">The office service.</param>
 /// <param name="validator">The project business validator.</param>
 /// <param name="saveActions">The context save actions.</param>
 public ProjectService(
     EcaContext context,
     IOfficeService officeService,
     IBusinessValidator <ProjectServiceCreateValidationEntity, ProjectServiceUpdateValidationEntity> validator,
     List <ISaveAction> saveActions = null)
     : base(context, saveActions)
 {
     Contract.Requires(context != null, "The context must not be null.");
     Contract.Requires(validator != null, "The validator must not be null.");
     this.validator             = validator;
     this.officeService         = officeService;
     throwIfProjectDoesNotExist = (projectId, project) =>
     {
         if (project == null)
         {
             throw new ModelNotFoundException(String.Format("The project with id [{0}] does not exist.", projectId));
         }
     };
     throwIfParticipantTypeDoesNotExist = (participantType) =>
     {
         if (participantType == null)
         {
             throw new ModelNotFoundException("The participant type does not exist.");
         }
     };
 }
Exemple #9
0
        /// <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);
        }
Exemple #10
0
        public static IQueryable <OfficeDTO> CreateGetOfficesQuery(EcaContext context)
        {
            Contract.Requires(context != null, "The context must not be null.");
            var query = from office in context.Organizations
                        let contacts = office.Contacts
                                       let programs                         = office.OwnerPrograms
                                                                  let goals = programs.SelectMany(x => x.Goals).Distinct()
                                                                              let themes = programs.SelectMany(x => x.Themes).Distinct()
                                                                                           let parentOffice = office.ParentOrganization

                                                                                                              where Organization.OFFICE_ORGANIZATION_TYPE_IDS.Contains(office.OrganizationTypeId)
                                                                                                              select new OfficeDTO
            {
                Contacts = contacts.OrderBy(x => x.FullName).Select(x => new SimpleLookupDTO {
                    Id = x.ContactId, Value = x.Position == null ? x.FullName : x.FullName + " (" + x.Position + ")"
                }),
                Description = office.Description,
                Goals       = goals.OrderBy(x => x.GoalName).Select(x => new SimpleLookupDTO {
                    Id = x.GoalId, Value = x.GoalName
                }),
                Id        = office.OrganizationId,
                Name      = office.Name,
                RevisedOn = office.History.RevisedOn,
                Themes    = themes.OrderBy(x => x.ThemeName).Select(x => new SimpleLookupDTO {
                    Id = x.ThemeId, Value = x.ThemeName
                }),
                OfficeSymbol     = office.OfficeSymbol,
                ParentOfficeId   = parentOffice == null ? default(int?) : parentOffice.OrganizationId,
                ParentOfficeName = parentOffice == null ? null : parentOffice.Name
            };

            return(query);
        }
 /// <summary>
 /// Creates a new ExchangeVisitorService and initializes the context and save actions.
 /// </summary>
 /// <param name="context">The context to operate against.</param>
 /// <param name="appSettings">The app settings.</param>
 /// <param name="saveActions">The context save actions.</param>
 public ExchangeVisitorService(EcaContext context, AppSettings appSettings, List <ISaveAction> saveActions = null)
     : base(context, saveActions)
 {
     Contract.Requires(context != null, "The context must not be null.");
     Contract.Requires(appSettings != null, "The app settings must not be null.");
     this.appSettings         = appSettings;
     throwIfModelDoesNotExist = (id, instance, type) =>
     {
         if (instance == null)
         {
             throw new ModelNotFoundException(String.Format("The model of type [{0}] with id [{1}] was not found.", type.Name, id));
         }
     };
     throwIfParticipantIsNotAPerson = (participant) =>
     {
         if (!participant.PersonId.HasValue)
         {
             throw new NotSupportedException(String.Format("The participant with id [0] is not a person participant.", participant.ParticipantId));
         }
     };
     throwIfProjectIsNotExchangeVisitorType = (participant, project) =>
     {
         if (project.VisitorTypeId != VisitorType.ExchangeVisitor.Id)
         {
             throw new NotSupportedException(String.Format("The participant with id [{0}] belongs to a project with id [{1}] that is not an exchange visitor project.", participant.ParticipantId, project.ProjectId));
         }
     };
 }
Exemple #12
0
 /// <summary>
 /// Creates a new ParticipantPersonService with the given context to operate against.
 /// </summary>
 /// <param name="saveActions">The save actions.</param>
 /// <param name="context">The context to operate against.</param>
 public ParticipantPersonsSevisService(EcaContext context, List <ISaveAction> saveActions = null) : base(context, saveActions)
 {
     Contract.Requires(context != null, "The context must not be null.");
     throwIfModelDoesNotExist = (id, instance, type) =>
     {
         if (instance == null)
         {
             throw new ModelNotFoundException(String.Format("The model of type [{0}] with id [{1}] was not found.", type.Name, id));
         }
     };
     throwSecurityViolationIfParticipantDoesNotBelongToProject = (userId, projectId, participant) =>
     {
         if (participant != null && participant.ProjectId != projectId)
         {
             throw new BusinessSecurityException(
                       String.Format("The user with id [{0}] attempted to validate a participant with id [{1}] and project id [{2}] but should have been denied access.",
                                     userId,
                                     participant.ParticipantId,
                                     projectId));
         }
     };
     throwValidationErrorIfParticipantSevisInfoIsLocked = (participant) =>
     {
         participant.ValidateSevisLock();
     };
 }
Exemple #13
0
 //[TestMethod]
 public void TestCreateDatabase()
 {
     using (var context = new EcaContext(@"Data Source=(LocalDb)\v11.0;Initial Catalog=Test;Integrated Security=True"))
     {
         Database.SetInitializer <EcaContext>(new DropCreateDatabaseAlways <EcaContext>());
         context.Database.Initialize(true);
     }
 }
 private void OnBeforeSaveChanges(DbContext context)
 {
     Contract.Requires(context is EcaContext, "The given context must be an EcaContext instance.");
     this.Context         = (EcaContext)context;
     this.CreatedObjects  = GetCreatedEntities(context).ToList();
     this.ModifiedObjects = GetModifiedEntities(context).ToList();
     this.DeletedObjects  = GetDeletedEntities(context).ToList();
 }
Exemple #15
0
 /// <summary>
 /// Returns a query to get ItineraryDTOs from the given context and project with the given id.
 /// </summary>
 /// <param name="context">The context to query.</param>
 /// <param name="projectId">The id of the project to get itineraries for.</param>
 /// <returns>The query to get itineraries from the given context with the project id.</returns>
 public static IQueryable <ItineraryDTO> CreateGetItinerariesByProjectIdQuery(EcaContext context, int projectId)
 {
     Contract.Requires(context != null, "The context must not be null.");
     return(CreateGetItinerariesQuery(context).Where(x => x.ProjectId == projectId)
            .OrderBy(x => x.StartDate)
            .ThenBy(x => x.EndDate)
            .ThenBy(x => x.Name));
 }
Exemple #16
0
 /// <summary>
 /// Returns a query to get membership dtos from the given context.
 /// </summary>
 /// <param name="context">The context to query.</param>
 /// <returns>The query to retrieve membership dtos.</returns>
 public static IQueryable <MembershipDTO> CreateGetMembershipDTOQuery(EcaContext context)
 {
     Contract.Requires(context != null, "The context must not be null.");
     return(context.Memberships.Select(x => new MembershipDTO
     {
         Id = x.MembershipId,
         Name = x.Name
     }));
 }
        /// <summary>
        /// Returns a query to filtered and sorted contacts in the system.
        /// </summary>
        /// <param name="context">The context to query.</param>
        /// <param name="queryOperator">The query operator.</param>
        /// <returns>The query to retrieve filtered and sorted contacts.</returns>
        public static IQueryable <ContactDTO> CreateContactQuery(EcaContext context, QueryableOperator <ContactDTO> queryOperator)
        {
            Contract.Requires(context != null, "The context must not be null.");
            Contract.Requires(queryOperator != null, "The query operator must not be null.");
            var query = CreateContactQuery(context);

            query = query.Apply(queryOperator);
            return(query);
        }
Exemple #18
0
        /// <summary>
        /// Returns a query to retrieve filtered and sorted simple project dtos for the given program id.
        /// </summary>
        /// <param name="context">The context to query.</param>
        /// <param name="programId">The project's parent program id.</param>
        /// <param name="queryOperator">The query operator.</param>
        /// <returns>The query to retrieved filtered and sorted simple project dtos for the given program id.</returns>
        public static IQueryable <SimpleProjectDTO> CreateGetProjectsByProgramQuery(EcaContext context, int programId, QueryableOperator <SimpleProjectDTO> queryOperator)
        {
            Contract.Requires(context != null, "The context must not be null.");
            Contract.Requires(queryOperator != null, "The query operator must not be null.");
            var query = CreateGetProjectsQuery(context).Where(x => x.ProgramId == programId);

            query = query.Apply(queryOperator);
            return(query);
        }
        /// <summary>
        /// Returns the person id from an entity that is related to a person.  This is useful when an entity
        /// has been deleted via the context, but the related person must be retrieved.
        /// </summary>
        /// <typeparam name="T">The entity type that is related to a person.</typeparam>
        /// <param name="context">The context to query.</param>
        /// <param name="entity">The entity that has been deleted.</param>
        /// <param name="propertySelector"></param>
        /// <returns>The id of the person or null if it does not exist.</returns>
        public int?GetPersonIdByEntity <T>(EcaContext context, T entity, Expression <Func <T, object> > propertySelector) where T : class
        {
            Contract.Requires(context != null, "The context must not be null.");
            Contract.Requires(entity != null, "The entity must not be null.");
            Contract.Requires(propertySelector != null, "The property selector must not be null.");
            var databaseValues = context.GetEntry <T>(entity).GetDatabaseValues();
            var personId       = databaseValues.GetValue <int?>(PropertyHelper.GetPropertyName <T>(propertySelector));

            return(personId);
        }
 /// <summary>
 /// Returns a query to get all location types given the location ids.
 /// </summary>
 /// <param name="context">The context to query.</param>
 /// <param name="locationIds">The location ids to get types for.</param>
 /// <returns>The query to get the distinct list of location types.</returns>
 public static IQueryable <int> CreateGetLocationTypeIdsQuery(EcaContext context, List <int> locationIds)
 {
     Contract.Requires(context != null, "The context must not be null.");
     Contract.Requires(locationIds != null, "The location ids must not be null.");
     return(context.Locations
            .Where(x => locationIds.Contains(x.LocationId))
            .Select(x => x.LocationTypeId)
            .OrderBy(x => x)
            .Distinct());
 }
        /// <summary>
        /// Count of impacts in a program
        /// </summary>
        /// <param name="context"></param>
        /// <param name="programId"></param>
        /// <returns></returns>
        public static IEnumerable <int> CreateGetProgramImpactStoryCountQuery(EcaContext context, IEnumerable <int> programIds)
        {
            Contract.Requires(context != null, "The context must not be null.");

            var query = context.Programs
                        .Where(x => programIds.Contains(x.ProgramId))
                        .Select(i => i).SelectMany(x => x.Impacts).Select(m => m.ImpactId).Distinct();

            return(query);
        }
 public static SnapshotDTO CreateGetProgramBeneficiaryCountQuery(EcaContext context, IEnumerable <int> programIds)
 {
     // TODO: get beneficiary count
     Contract.Requires(context != null, "The context must not be null.");
     return(new SnapshotDTO()
     {
         DataLabel = "BENEFICIARIES",
         DataValue = 0
     });
 }
        /// <summary>
        /// Gets a list of bookmark dtos
        /// </summary>
        /// <param name="context">The context to query</param>
        /// <returns>Bookmark dtos</returns>
        public static IQueryable <BookmarkDTO> CreateGetBookmarksQuery(EcaContext context)
        {
            Contract.Requires(context != null, "The context must not be null.");
            var allPeople = PersonQueries.CreateGetSimplePersonDTOsQuery(context);
            var query     = from bookmark in context.Bookmarks

                            let hasOffice = bookmark.OfficeId.HasValue
                                            let office = bookmark.Office

                                                         let hasProgram = bookmark.ProgramId.HasValue
                                                                          let program = bookmark.Program

                                                                                        let hasProject = bookmark.ProjectId.HasValue
                                                                                                         let project = bookmark.Project

                                                                                                                       let hasPerson = bookmark.PersonId.HasValue
                                                                                                                                       let person = allPeople.Where(x => x.PersonId == bookmark.PersonId).FirstOrDefault()

                                                                                                                                                    let hasOrganization = bookmark.OrganizationId.HasValue
                                                                                                                                                                          let organization = bookmark.Organization

                                                                                                                                                                                             let ownerSymbol = hasProject ? project.ParentProgram.Owner.OfficeSymbol :
                                                                                                                                                                                                               hasProgram ? program.Owner.OfficeSymbol :
                                                                                                                                                                                                               hasOffice ? office.OfficeSymbol : "UNKNOWN OFFICE SYMBOL"

                                                                                                                                                                                                               let orgRoleFundingSource = hasOrganization ? bookmark.Organization.OrganizationRoles.Where(x => x.OrganizationRoleId == OrganizationRole.FundingSource.Id).FirstOrDefault() : null

                                                                                                                                                                                                                                          select new BookmarkDTO
            {
                BookmarkId     = bookmark.BookmarkId,
                OfficeId       = bookmark.OfficeId,
                ProgramId      = bookmark.ProgramId,
                ProjectId      = bookmark.ProjectId,
                PersonId       = bookmark.PersonId,
                OrganizationId = bookmark.OrganizationId,
                PrincipalId    = bookmark.PrincipalId,
                AddedOn        = bookmark.AddedOn,
                Automatic      = bookmark.Automatic,
                Type           = hasProject ? "Project" :
                                 hasOffice ? "Office" :
                                 hasProgram ? "Program" :
                                 hasPerson ? "Person" :
                                 hasOrganization ? ((orgRoleFundingSource != null) ? "Funding" : "Organization") : "Unknown",
                OfficeSymbolOrStatus = (hasProject || hasProgram || hasOffice) ? ownerSymbol :
                                       hasPerson ? person.CurrentStatus :
                                       hasOrganization ? organization.Status : "",
                Name = hasProject ? project.Name :
                       hasOffice ? office.Name :
                       hasProgram ? program.Name :
                       hasPerson ? person.FullName :
                       hasOrganization ? organization.Name : ""
            };

            return(query);
        }
        /// <summary>
        /// Returns a query to select focus dtos.
        /// </summary>
        /// <param name="context">The context to query.</param>
        /// <returns>The query.</returns>
        public static IQueryable <FocusDTO> CreateGetFocusDTOQuery(EcaContext context)
        {
            Contract.Requires(context != null, "The context must not be null.");
            var query = context.Foci.Select(x => new FocusDTO
            {
                Id   = x.FocusId,
                Name = x.FocusName
            });

            return(query);
        }
Exemple #25
0
        /// <summary>
        /// Returns a query capable of retrieving people from the given context.  A FullName value is also calculated for the person.
        /// </summary>
        /// <param name="context">The context to query.</param>
        /// <returns>The query to retrieve people from the context.</returns>
        public static IQueryable <SimplePersonDTO> CreateGetSimplePersonDTOsQuery(EcaContext context)
        {
            Contract.Requires(context != null, "The context must not be null.");
            var query = from person in context.People
                        let gender = person.Gender
                                     let currentParticipation = person.Participations.OrderByDescending(p => p.ParticipantStatusId).FirstOrDefault() // the ID order has default precidence, for example if there are two statues, Active(2) and Alumnus(1), Active is shown.
                                                                let hasCurrentParticipation = currentParticipation != null &&
                                                                                              currentParticipation.Status != null &&
                                                                                              currentParticipation.Status.Status != null

                                                                                              let hasPlaceOfBirth = person.PlaceOfBirth != null
                                                                                                                    let cityOfBirth = person.PlaceOfBirth

                                                                                                                                      let cityOfBirthName = hasPlaceOfBirth ? cityOfBirth.LocationName : null

                                                                                                                                                            let hasCountryOfBirth = hasPlaceOfBirth && cityOfBirth.Country != null
                                                                                                                                                                                    let countryOfBirthName = hasCountryOfBirth ? cityOfBirth.Country.LocationName : null

                                                                                                                                                                                                             let hasDivisionOfBirth = hasPlaceOfBirth && cityOfBirth.Division != null
                                                                                                                                                                                                                                      let divisionOfBirthName = hasDivisionOfBirth ? cityOfBirth.Division.LocationName : null

                                                                                                                                                                                                                                                                select new SimplePersonDTO
            {
                Alias                  = person.Alias,
                DateOfBirth            = person.DateOfBirth,
                IsDateOfBirthEstimated = person.IsDateOfBirthEstimated,
                IsDateOfBirthUnknown   = person.IsDateOfBirthUnknown,
                IsPlaceOfBirthUnknown  = person.IsPlaceOfBirthUnknown,
                IsSingleName           = person.IsSingleName,
                FamilyName             = person.FamilyName,
                FirstName              = person.FirstName,
                Gender                 = gender.GenderName,
                GenderId               = gender.GenderId,
                GivenName              = person.GivenName,
                PersonId               = person.PersonId,
                LastName               = person.LastName,
                MiddleName             = person.MiddleName,
                NamePrefix             = person.NamePrefix,
                NameSuffix             = person.NameSuffix,
                Patronym               = person.Patronym,
                FullName               = person.FullName,
                PassportName           = person.PassportName,
                CurrentStatus          = hasCurrentParticipation ? currentParticipation.Status.Status : UNKNOWN_PARTICIPANT_STATUS,
                ProjectId              = hasCurrentParticipation ? currentParticipation.ProjectId : default(int?),
                ParticipantId          = hasCurrentParticipation ? currentParticipation.ParticipantId : default(int?),
                CountryOfBirth         = countryOfBirthName,
                DivisionOfBirth        = divisionOfBirthName,
                CityOfBirth            = cityOfBirthName,
                CityOfBirthId          = hasPlaceOfBirth ? cityOfBirth.LocationId : default(int?),
                ProminentCategories    = person.ProminentCategories.Select(x => x.Name)
            };

            return(query);
        }
Exemple #26
0
 /// <summary>
 /// Returns a query to select office setting dtos from the given context.
 /// </summary>
 /// <param name="context">The context to query.</param>
 /// <returns>The query to retrieve office settings.</returns>
 public static IQueryable <OfficeSettingDTO> CreateGetOfficeSettingDTOQuery(EcaContext context)
 {
     Contract.Requires(context != null, "The context must not be null.");
     return(context.OfficeSettings.Select(x => new OfficeSettingDTO
     {
         Id = x.OfficeSettingId,
         Name = x.Name,
         OfficeId = x.OfficeId,
         Value = x.Value
     }));
 }
        /// <summary>
        /// Count of funding sources of all program projects
        /// </summary>
        /// <param name="context"></param>
        /// <param name="programId"></param>
        /// <returns></returns>
        public static SnapshotDTO CreateGetProgramFundingSourceCountQuery(EcaContext context, int programId)
        {
            Contract.Requires(context != null, "The context must not be null.");
            var query = MoneyFlowQueries.CreateGetSourceMoneyFlowDTOsByProgramId(context, programId);

            return(new SnapshotDTO()
            {
                DataLabel = "FUNDING SOURCES",
                DataValue = query.Count(x => x.FiscalYear >= oldestDate.Year - 1)
            });
        }
Exemple #28
0
 /// <summary>
 /// Returns a query to get social media dtos from the given context.
 /// </summary>
 /// <param name="context">The context to query.</param>
 /// <returns>The query to retrieve social media dtos.</returns>
 public static IQueryable <SocialMediaDTO> CreateGetSocialMediaDTOQuery(EcaContext context)
 {
     Contract.Requires(context != null, "The context must not be null.");
     return(context.SocialMedias.Select(x => new SocialMediaDTO
     {
         Id = x.SocialMediaId,
         SocialMediaType = x.SocialMediaType.SocialMediaTypeName,
         SocialMediaTypeId = x.SocialMediaTypeId,
         Value = x.SocialMediaValue
     }));
 }
Exemple #29
0
        /// <summary>
        /// Returns a query to select goal dtos.
        /// </summary>
        /// <param name="context">The context to query.</param>
        /// <returns>The query.</returns>
        public static IQueryable <GoalDTO> CreateGetGoalDTOQuery(EcaContext context)
        {
            Contract.Requires(context != null, "The context must not be null.");
            var query = context.Goals.Select(x => new GoalDTO
            {
                Id       = x.GoalId,
                Name     = x.GoalName,
                IsActive = x.IsActive
            });

            return(query);
        }
Exemple #30
0
        /// <summary>
        /// Creates a query that returns a list of organization roles
        /// </summary>
        /// <param name="context">The context to query</param>
        /// <param name="queryOperator">The query operator to apply</param>
        /// <returns>The query</returns>
        public static IQueryable <SimpleLookupDTO> CreateGetOrganizationRolesQuery(EcaContext context, QueryableOperator <SimpleLookupDTO> queryOperator)
        {
            Contract.Requires(context != null, "The context must not be null.");
            Contract.Requires(queryOperator != null, "The query operator must not be null.");

            var query = context.OrganizationRoles.Select(x => new SimpleLookupDTO {
                Id = x.OrganizationRoleId, Value = x.OrganizationRoleName
            });

            query = query.Apply(queryOperator);
            return(query);
        }