Exemple #1
0
        /// <summary>
        /// Returns the sorted, filtered, and paged contact DTOs in the eca system.
        /// </summary>
        /// <param name="queryOperator"></param>
        /// <returns></returns>
        public async Task <PagedQueryResults <ContactDTO> > GetContactsAsync(QueryableOperator <ContactDTO> queryOperator)
        {
            var contacts = await ContactQueries.CreateContactQuery(this.Context, queryOperator)
                           .ToPagedQueryResultsAsync <ContactDTO>(queryOperator.Start, queryOperator.Limit);

            this.logger.Trace("Retrieved contacts by query operator [{0}].", queryOperator);

            return(contacts);
        }
Exemple #2
0
        // <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);
        }
Exemple #3
0
 private IQueryable <ContactDTO> CreateGetContactByIdQuery(int contactId)
 {
     return(ContactQueries.CreateContactQuery(this.Context).Where(c => c.Id == contactId));
 }