/// <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); }
/// <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); }
public void Constructor() { WebOrganization organization; organization = new WebOrganization(); Assert.IsNotNull(organization); }
/// <summary> /// Check the data in current object /// </summary> /// <param name='organization'>The Organization.</param> public static void CheckData(this WebOrganization organization) { if (!organization.IsDataChecked) { organization.CheckStrings(); organization.IsDataChecked = true; } }
private WebOrganization GetOrganization(Boolean refresh) { if (_organization.IsNull() || refresh) { _organization = new WebOrganization(); } return(_organization); }
/// <summary> /// Delete Organization /// </summary> /// <param name="context">Web service request context.</param> /// <param name="organization">Object representing the Organization.</param> /// <returns>void</returns> public static void DeleteOrganization(WebServiceContext context, WebOrganization organization) { //Check whether or not the user has the super administrator role. //Only super administrators are currently authorized to run this method. if (!AuthorizationManager.IsUserAuthorized(context, Settings.Default.RoleIdForSuperAdministrator, null, null, null)) { throw new Exception(Settings.Default.ErrorMessageIsNotSuperAdministrator); } context.CheckTransaction(); context.GetUserDatabase().DeleteOrganization(organization.Id, context.GetUser().Id); }
/// <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); }
public void UpdateOrganization() { // Assert.IsFalse(useTransaction); WebOrganization organization; // Get existing organization. organization = OrganizationManager.GetOrganization(GetContext(), Settings.Default.TestOrganizationId); organization.Name = "TestNameUpdate3"; organization.ShortName = "TestOrgShortName3"; organization.ModifiedBy = Settings.Default.TestUserId; organization.AdministrationRoleId = Settings.Default.TestUserId; organization.Category.Id = 2; organization.Description = "Testdescription update"; organization.ValidFromDate = DateTime.Now; organization.ValidToDate = DateTime.Today.AddYears(100); //organization.Addresses[0].PostalAddress1 = "PA1 update1"; //organization.PhoneNumbers[0].Number = "090-101010"; WebOrganization updatedOrganization; updatedOrganization = OrganizationManager.UpdateOrganization(GetContext(), organization); Assert.IsNotNull(updatedOrganization); Assert.AreEqual(Settings.Default.TestOrganizationId, updatedOrganization.Id); Assert.AreEqual(updatedOrganization.Description, organization.Description); Assert.AreEqual(updatedOrganization.ModifiedBy, Settings.Default.TestUserId); Assert.AreEqual(updatedOrganization.Name, organization.Name); Assert.AreEqual(updatedOrganization.ShortName, organization.ShortName); Assert.IsNotNull(updatedOrganization.ValidFromDate); Assert.IsNotNull(updatedOrganization.ValidToDate); // Number of address records // Assert.AreEqual(1, updatedOrganization.Addresses.Count); // Number of phone records // Assert.AreEqual(1, updatedOrganization.PhoneNumbers.Count); // Update description for organization from blank to not blank organization = new WebOrganization(); organization.Name = "OrganizationUniqueName4"; organization.ShortName = "OrganizationUniqueShortName4"; organization.Category = new WebOrganizationCategory(); organization.Category.Id = 2; organization.Description = null; WebOrganization newOrganization = new WebOrganization(); newOrganization = OrganizationManager.CreateOrganization(GetContext(), organization); newOrganization.Description = "Description update"; updatedOrganization = OrganizationManager.UpdateOrganization(GetContext(), newOrganization); Assert.IsNotNull(updatedOrganization.Description); }
/// <summary> /// Creates a new organization /// </summary> /// <param name="context">Web service request context.</param> /// <param name="organization">Object representing the Organization.</param> /// <returns>WebOrganization object with the created organization.</returns> public static WebOrganization CreateOrganization(WebServiceContext context, WebOrganization organization) { //Check whether or not the user has the super administrator role. //Only super administrators are currently authorized to run this method. if (!AuthorizationManager.IsUserAuthorized(context, Settings.Default.RoleIdForSuperAdministrator, null, null, null)) { throw new Exception(Settings.Default.ErrorMessageIsNotSuperAdministrator); } Int32 organizationId = Int32.MinValue; // Check arguments. context.CheckTransaction(); organization.CheckNotNull("organization"); organization.CheckData(); Int32?administrationRoleId; administrationRoleId = null; if (organization.IsAdministrationRoleIdSpecified) { administrationRoleId = organization.AdministrationRoleId; } organizationId = context.GetUserDatabase().CreateOrganization( organization.Name, organization.ShortName, organization.Description, administrationRoleId, organization.HasSpeciesCollection, organization.Category.Id, context.GetUser().Id, context.Locale.Id, organization.ValidFromDate, organization.ValidToDate); if (organization.Addresses.IsNotEmpty()) { List <WebAddress> addresses = organization.Addresses; foreach (WebAddress webAddress in addresses) { webAddress.OrganizationId = organizationId; UserManager.CreateAddress(context, webAddress); } } if (organization.PhoneNumbers.IsNotEmpty()) { List <WebPhoneNumber> phoneNumbers = organization.PhoneNumbers; foreach (WebPhoneNumber webPhoneNumber in phoneNumbers) { webPhoneNumber.OrganizationId = organizationId; UserManager.CreatePhoneNumber(context, webPhoneNumber); } } return(GetOrganization(context, organizationId)); }
private WebOrganization GetNewWebOrganization() { WebOrganization newOrganization; WebOrganizationCategory organizationCategory; List <WebAddress> addresses; newOrganization = new WebOrganization(); newOrganization.Name = @"Fågelskådarna Name3"; newOrganization.ShortName = @"Fågelskådarna ShortName2"; newOrganization.Description = @"testdescription"; newOrganization.CategoryId = 2; organizationCategory = new WebOrganizationCategory(); newOrganization.Category = organizationCategory; newOrganization.Category.Id = 2; addresses = new List <WebAddress>(); newOrganization.Addresses = addresses; return(newOrganization); }
public void UpdateOrganizationAddress() { String city, postalAddress1, postalAddress2, zipCode; WebOrganization organization, updatedOrganization; WebAddress address; WebCountry country; WebAddressType addressType; organization = new WebOrganization(); organization = GetOneOrganization(); address = new WebAddress(); city = "Uppsala"; address.City = city; country = new WebCountry(); country = CountryManager.GetCountry(GetContext(), Settings.Default.TestCountryId); address.Country = country; postalAddress1 = ""; address.PostalAddress1 = postalAddress1; postalAddress2 = "ArtDatabanken, SLU"; address.PostalAddress2 = postalAddress2; zipCode = "752 52"; address.ZipCode = zipCode; addressType = new WebAddressType(); addressType.Id = 1; address.Type = addressType; organization.Addresses.Add(address); updatedOrganization = new WebOrganization(); updatedOrganization = OrganizationManager.UpdateOrganization(GetContext(), organization); Assert.IsNotNull(updatedOrganization); Assert.IsTrue(updatedOrganization.Addresses.IsNotEmpty()); Assert.AreEqual(1, updatedOrganization.Addresses.Count); Assert.AreEqual(city, updatedOrganization.Addresses[0].City); Assert.AreEqual(country.Id, updatedOrganization.Addresses[0].Country.Id); Assert.AreEqual(postalAddress1, updatedOrganization.Addresses[0].PostalAddress1); Assert.AreEqual(postalAddress2, updatedOrganization.Addresses[0].PostalAddress2); Assert.AreEqual(zipCode, updatedOrganization.Addresses[0].ZipCode); }
/// <summary> /// Load data into the WebOrganization instance. /// </summary> /// <param name='organization'>The organization.</param> /// <param name='dataReader'>An open data reader.</param> public static void LoadData(this WebOrganization organization, DataReader dataReader) { // Organization organization.Id = dataReader.GetInt32(OrganizationData.ID); organization.GUID = dataReader.GetString(OrganizationData.GUID); organization.Name = dataReader.GetString(OrganizationData.NAME); organization.ShortName = dataReader.GetString(OrganizationData.SHORT_NAME); organization.CategoryId = dataReader.GetInt32(OrganizationData.ORGANIZATION_CATEGORY_ID); organization.Description = dataReader.GetString(OrganizationData.DESCRIPTION); organization.IsAdministrationRoleIdSpecified = dataReader.IsNotDbNull(OrganizationData.ADMINISTRATION_ROLE_ID); if (organization.IsAdministrationRoleIdSpecified) { organization.AdministrationRoleId = dataReader.GetInt32(OrganizationData.ADMINISTRATION_ROLE_ID); } organization.HasSpeciesCollection = dataReader.GetBoolean(OrganizationData.HAS_COLLECTION); organization.CategoryId = dataReader.GetInt32(OrganizationData.ORGANIZATION_CATEGORY_ID); organization.CreatedDate = dataReader.GetDateTime(OrganizationData.CREATED_DATE); organization.CreatedBy = dataReader.GetInt32(OrganizationData.CREATED_BY, 0); organization.ModifiedDate = dataReader.GetDateTime(OrganizationData.MODIFIED_DATE); organization.ModifiedBy = dataReader.GetInt32(OrganizationData.MODIFIED_BY, 0); organization.ValidFromDate = dataReader.GetDateTime(OrganizationData.VALID_FROM_DATE); organization.ValidToDate = dataReader.GetDateTime(OrganizationData.VALID_TO_DATE); }
public WebOrganizationTest() { _organization = null; }