Пример #1
0
        /// <summary>
        /// Get information about organizations.
        /// If organizationCategoryId is specified all organizations of that category are returned.
        /// If no organizationCategoryId is specified all organizations are returned.
        /// <param name="context">Web service request context.</param>
        /// <param name="organizationCategoryId">Organization category id.</param>
        /// </summary>
        /// <returns>
        /// Returns list of organizations or null if specified category
        /// has no organizations.
        /// </returns>
        private static List <WebOrganization> GetOrganizations(WebServiceContext context, Int32?organizationCategoryId)
        {
            WebOrganization        organization;
            List <WebOrganization> organizationList;

            // Get information from database.
            using (DataReader dataReader = context.GetUserDatabase().GetOrganizations(organizationCategoryId, context.Locale.Id))
            {
                organizationList = new List <WebOrganization>();
                while (dataReader.Read())
                {
                    organization          = new WebOrganization();
                    organization.Category = new WebOrganizationCategory();
                    organization.LoadData(dataReader);
                    organizationList.Add(organization);
                }
            }
            if (organizationList.IsNotEmpty())
            {
                foreach (WebOrganization tempOrganization in organizationList)
                {
                    // Get organizationCategory for this organization
                    tempOrganization.Category = GetOrganizationCategory(context, tempOrganization.CategoryId);
                    // Set WebAddress + WebPhone
                    tempOrganization.Addresses    = UserManager.GetAddresses(context, 0, tempOrganization.Id);
                    tempOrganization.PhoneNumbers = UserManager.GetPhoneNumbers(context, 0, tempOrganization.Id);
                }
            }
            return(organizationList);
        }
Пример #2
0
        /// <summary>
        /// Get information about a organization
        /// </summary>
        /// <param name="context">Web service request context.</param>
        /// <param name="organizationId">Organization id.</param>
        /// <returns>Returns organization information or null if
        ///          organizationid doesn't match.</returns>
        public static WebOrganization GetOrganization(WebServiceContext context, Int32 organizationId)
        {
            WebOrganization organization;

            // Get information from database.
            using (DataReader dataReader = context.GetUserDatabase().GetOrganization(organizationId, context.Locale.Id))
            {
                if (dataReader.Read())
                {
                    organization          = new WebOrganization();
                    organization.Category = new WebOrganizationCategory();
                    organization.LoadData(dataReader);
                }
                else
                {
                    throw new ArgumentException("Organization not found. OrganizationId = " + organizationId);
                }
            }
            // Get organizationCategory for this organization
            organization.Category = GetOrganizationCategory(context, organization.CategoryId);
            // Set WebAddress + WebPhone
            organization.Addresses    = UserManager.GetAddresses(context, 0, organization.Id);
            organization.PhoneNumbers = UserManager.GetPhoneNumbers(context, 0, organization.Id);
            return(organization);
        }
Пример #3
0
        /// <summary>
        /// Get organizations that matches the search criteria.
        /// </summary>
        /// <param name="context">Web service request context.</param>
        /// <param name="searchCriteria">Search criteria.</param>
        /// <returns>Organizations that matches the search criteria</returns>
        public static List <WebOrganization> GetOrganizationsBySearchCriteria(WebServiceContext context,
                                                                              WebOrganizationSearchCriteria searchCriteria)
        {
            Int32?  organizationCategoryId;
            Boolean?hasSpiecesCollection;
            List <WebOrganization> organizations;
            WebOrganization        organization;

            // Check data.
            searchCriteria.CheckNotNull("searchCriteria");
            searchCriteria.CheckStrings();

            organizationCategoryId = null;
            if (searchCriteria.IsOrganizationCategoryIdSpecified)
            {
                organizationCategoryId = searchCriteria.OrganizationCategoryId;
            }
            hasSpiecesCollection = null;
            if (searchCriteria.IsHasSpeciesCollectionSpecified)
            {
                hasSpiecesCollection = searchCriteria.HasSpeciesCollection;
            }
            // Get information from database.
            using (DataReader dataReader = context.GetUserDatabase().GetOrganizationsBySearchCriteria(searchCriteria.Name,
                                                                                                      searchCriteria.ShortName,
                                                                                                      organizationCategoryId,
                                                                                                      hasSpiecesCollection,
                                                                                                      context.Locale.Id))
            {
                organizations = new List <WebOrganization>();
                while (dataReader.Read())
                {
                    organization = new WebOrganization();
                    organization.LoadData(dataReader);
                    organizations.Add(organization);
                }
            }

            if (organizations.IsNotEmpty())
            {
                foreach (WebOrganization tempOrganization in organizations)
                {
                    // Get organizationCategory for this organization
                    tempOrganization.Category = GetOrganizationCategory(context, tempOrganization.CategoryId);
                    // Set WebAddress + WebPhone
                    tempOrganization.Addresses    = UserManager.GetAddresses(context, 0, tempOrganization.Id);
                    tempOrganization.PhoneNumbers = UserManager.GetPhoneNumbers(context, 0, tempOrganization.Id);
                }
            }
            return(organizations);
        }