コード例 #1
0
        /// <summary>
        /// Returns the paged, sorted, and filtered people in the system.
        /// </summary>
        /// <param name="queryOperator">The query operator.</param>
        /// <returns>The paged, sorted, and filtered people in the system.</returns>
        public async Task <PagedQueryResults <SimplePersonDTO> > GetPeopleAsync(QueryableOperator <SimplePersonDTO> queryOperator)
        {
            var people = await PersonQueries.CreateGetSimplePersonDTOsQuery(this.Context, queryOperator).ToPagedQueryResultsAsync(queryOperator.Start, queryOperator.Limit);

            logger.Trace("Retrieved people using the query operator [{0}]", queryOperator);
            return(people);
        }
コード例 #2
0
        public void TestCreateGetSimplePersonDTOsQuery_CurrentParticipation_StatusIsNull()
        {
            var person = new Person
            {
                Alias      = "alias",
                FamilyName = "family",
                FirstName  = "firstName",
                GivenName  = "givenName",
                LastName   = "lastName",
                MiddleName = "middleName",
                NamePrefix = "Mr.",
                NameSuffix = "III",
                Patronym   = "patronym",
                Gender     = new Gender
                {
                    GenderId   = Gender.Female.Id,
                    GenderName = Gender.Female.Value
                }
            };
            var participant = new Participant
            {
                Person = person,
            };

            person.Participations.Add(participant);
            context.People.Add(person);
            context.Genders.Add(person.Gender);

            var result = PersonQueries.CreateGetSimplePersonDTOsQuery(context).First();

            Assert.AreEqual(PersonQueries.UNKNOWN_PARTICIPANT_STATUS, result.CurrentStatus);
        }
コード例 #3
0
        public void TestCreateGetSimplePersonDTOsQuery_PlaceOfBirthIsUnknown()
        {
            var person = new Person
            {
                FullName = "fullname",
                Gender   = new Gender
                {
                    GenderId   = Gender.Female.Id,
                    GenderName = Gender.Female.Value
                },
                IsPlaceOfBirthUnknown = true
            };
            var status = new ParticipantStatus
            {
                ParticipantStatusId = 1,
                Status = "status"
            };
            var participant = new Participant
            {
                Status = status,
                Person = person,
            };

            context.ParticipantStatuses.Add(status);
            person.Participations.Add(participant);
            context.People.Add(person);
            context.Genders.Add(person.Gender);

            var result = PersonQueries.CreateGetSimplePersonDTOsQuery(context).First();

            Assert.AreEqual(result.IsPlaceOfBirthUnknown, result.IsPlaceOfBirthUnknown);
        }
コード例 #4
0
        public void TestCreateGetSimplePersonDTOsQuery_DoesNotHavePlaceOfBirth()
        {
            var person = new Person
            {
                FullName = "fullname",
                Gender   = new Gender
                {
                    GenderId   = Gender.Female.Id,
                    GenderName = Gender.Female.Value
                }
            };
            var status = new ParticipantStatus
            {
                ParticipantStatusId = 1,
                Status = "status"
            };
            var participant = new Participant
            {
                Status = status,
                Person = person,
            };

            context.ParticipantStatuses.Add(status);
            person.Participations.Add(participant);
            context.People.Add(person);
            context.Genders.Add(person.Gender);

            var result = PersonQueries.CreateGetSimplePersonDTOsQuery(context).First();

            Assert.IsNull(result.CityOfBirthId);
            Assert.IsNull(result.CityOfBirth);
        }
コード例 #5
0
        public void TestCreateGetSimplePersonDTOsQuery_CheckDateOfBirth()
        {
            var person = new Person
            {
                DateOfBirth            = DateTime.UtcNow,
                IsDateOfBirthEstimated = true,
                FullName = "fullname",
                Gender   = new Gender
                {
                    GenderId   = Gender.Female.Id,
                    GenderName = Gender.Female.Value
                }
            };
            var status = new ParticipantStatus
            {
                ParticipantStatusId = 1,
                Status = "status"
            };
            var participant = new Participant
            {
                Status = status,
                Person = person,
            };

            context.ParticipantStatuses.Add(status);
            person.Participations.Add(participant);
            context.People.Add(person);
            context.Genders.Add(person.Gender);

            var result = PersonQueries.CreateGetSimplePersonDTOsQuery(context).First();

            Assert.AreEqual(person.DateOfBirth, result.DateOfBirth);
            Assert.AreEqual(person.IsDateOfBirthEstimated, result.IsDateOfBirthEstimated);
        }
コード例 #6
0
        public void TestCreateGetSimplePersonDTOsQuery_CheckPlaceOfBirth()
        {
            var country = new Location
            {
                LocationName = "country",
                LocationId   = 1
            };
            var division = new Location
            {
                LocationName = "division",
                LocationId   = 2
            };
            var city = new Location
            {
                LocationName = "city",
                LocationId   = 3,
                Division     = division,
                DivisionId   = division.LocationId,
                Country      = country,
                CountryId    = country.LocationId
            };
            var person = new Person
            {
                FullName = "fullname",
                Gender   = new Gender
                {
                    GenderId   = Gender.Female.Id,
                    GenderName = Gender.Female.Value
                },
                PlaceOfBirth   = city,
                PlaceOfBirthId = city.LocationId
            };
            var status = new ParticipantStatus
            {
                ParticipantStatusId = 1,
                Status = "status"
            };
            var participant = new Participant
            {
                Status = status,
                Person = person,
            };

            context.Locations.Add(city);
            context.Locations.Add(division);
            context.Locations.Add(country);
            context.ParticipantStatuses.Add(status);
            person.Participations.Add(participant);
            context.People.Add(person);
            context.Genders.Add(person.Gender);

            var result = PersonQueries.CreateGetSimplePersonDTOsQuery(context).First();

            Assert.AreEqual(city.LocationId, result.CityOfBirthId);
            Assert.AreEqual(city.LocationName, result.CityOfBirth);
            Assert.AreEqual(division.LocationName, result.DivisionOfBirth);
            Assert.AreEqual(country.LocationName, result.CountryOfBirth);
        }
コード例 #7
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);
        }
コード例 #8
0
        public void TestCreateGetSimplePersonDTOsQuery_CheckNames()
        {
            var person = new Person
            {
                Alias      = "alias",
                FamilyName = "family",
                FirstName  = "firstName",
                GivenName  = "givenName",
                LastName   = "lastName",
                MiddleName = "middleName",
                NamePrefix = "Mr.",
                NameSuffix = "III",
                Patronym   = "patronym",
                FullName   = "fullname",
                Gender     = new Gender
                {
                    GenderId   = Gender.Female.Id,
                    GenderName = Gender.Female.Value
                }
            };
            var status = new ParticipantStatus
            {
                ParticipantStatusId = 1,
                Status = "status"
            };
            var participant = new Participant
            {
                Status = status,
                Person = person,
            };

            context.ParticipantStatuses.Add(status);
            person.Participations.Add(participant);
            context.People.Add(person);
            context.Genders.Add(person.Gender);

            var result = PersonQueries.CreateGetSimplePersonDTOsQuery(context).First();

            Assert.AreEqual(person.Alias, result.Alias);
            Assert.AreEqual(person.FamilyName, result.FamilyName);
            Assert.AreEqual(person.FirstName, result.FirstName);
            Assert.AreEqual(person.GivenName, result.GivenName);
            Assert.AreEqual(person.LastName, result.LastName);
            Assert.AreEqual(person.MiddleName, result.MiddleName);
            Assert.AreEqual(person.NamePrefix, result.NamePrefix);
            Assert.AreEqual(person.Patronym, result.Patronym);
            Assert.AreEqual(person.FullName, result.FullName);
        }
コード例 #9
0
        private IQueryable <SimplePersonDTO> CreateGetSimplePerson(int personId)
        {
            var query = PersonQueries.CreateGetSimplePersonDTOsQuery(this.Context);

            return(query.Where(p => p.PersonId == personId));
        }
コード例 #10
0
        public void TestCreateGetSimplePersonDTOsQuery_HasCurrentParticipation()
        {
            var person = new Person
            {
                Alias      = "alias",
                FamilyName = "family",
                FirstName  = "firstName",
                GivenName  = "givenName",
                LastName   = "lastName",
                MiddleName = "middleName",
                NamePrefix = "Mr.",
                NameSuffix = "III",
                Patronym   = "patronym",
                Gender     = new Gender
                {
                    GenderId   = Gender.Female.Id,
                    GenderName = Gender.Female.Value
                }
            };
            var activeStatus = new ParticipantStatus
            {
                ParticipantStatusId = ParticipantStatus.Active.Id,
                Status = ParticipantStatus.Active.Value
            };
            var activeParticipant = new Participant
            {
                ParticipantId = 25,
                Status        = activeStatus,
                Person        = person,
                ProjectId     = 10
            };
            var alumnusStatus = new ParticipantStatus
            {
                ParticipantStatusId = ParticipantStatus.Alumnus.Id,
                Status = ParticipantStatus.Alumnus.Value
            };
            var alumnusParticipant = new Participant
            {
                ParticipantId = 250,
                Status        = activeStatus,
                Person        = person,
                ProjectId     = 100
            };

            context.ParticipantStatuses.Add(activeStatus);
            context.ParticipantStatuses.Add(alumnusStatus);

            person.Participations.Add(activeParticipant);
            person.Participations.Add(alumnusParticipant);

            person.Participations = person.Participations.OrderBy(x => x.ParticipantStatusId).ToList();

            context.People.Add(person);
            context.Participants.Add(activeParticipant);
            context.Participants.Add(alumnusParticipant);
            context.Genders.Add(person.Gender);

            var result = PersonQueries.CreateGetSimplePersonDTOsQuery(context).First();

            Assert.AreEqual(activeStatus.Status, result.CurrentStatus);
            Assert.AreEqual(activeParticipant.ParticipantId, result.ParticipantId);
            Assert.AreEqual(activeParticipant.ProjectId, result.ProjectId);
        }
コード例 #11
0
 private IQueryable <SimplePersonDTO> CreateGetSimplePersonDTOsByParticipantIdQuery(int personId)
 {
     return(PersonQueries.CreateGetSimplePersonDTOsQuery(this.Context).Where(x => x.PersonId == personId));
 }