public static string CreateOrganization(RestCommand command) { Addresses addresses = new Addresses(command.LoginUser); Address address = addresses.AddNewAddress(); PhoneNumbers phoneNumbers = new PhoneNumbers(command.LoginUser); PhoneNumber phoneNumber = phoneNumbers.AddNewPhoneNumber(); Organizations organizations = new Organizations(command.LoginUser); Organization organization = organizations.AddNewOrganization(); organization.ParentID = command.Organization.OrganizationID; organization.IsActive = true; organization.FullReadFromXml(command.Data, true, ref phoneNumber, ref address); organization.NeedsIndexing = true; organization.Collection.Save(); organization.UpdateCustomFieldsFromXml(command.Data); if (!String.IsNullOrEmpty(phoneNumber.Number) || !String.IsNullOrEmpty(phoneNumber.Extension)) { phoneNumber.RefType = ReferenceType.Organizations; phoneNumber.RefID = organization.OrganizationID; phoneNumbers.Save(); } if (!String.IsNullOrEmpty(address.Description) || !String.IsNullOrEmpty(address.Addr1) || !String.IsNullOrEmpty(address.Addr2) || !String.IsNullOrEmpty(address.Addr3) || !String.IsNullOrEmpty(address.City) || !String.IsNullOrEmpty(address.Country) || !String.IsNullOrEmpty(address.Description) || !String.IsNullOrEmpty(address.State) || !String.IsNullOrEmpty(address.Zip)) { address.RefType = ReferenceType.Organizations; address.RefID = organization.OrganizationID; addresses.Save(); } return(OrganizationsView.GetOrganizationsViewItem(command.LoginUser, organization.OrganizationID).GetXml("Customer", true)); }
public override bool Save() { if (string.IsNullOrEmpty(textName.Text.Trim())) { _manager.Alert("Please choose a name."); return(false); } Organization organization; Organizations organizations = new Organizations(UserSession.LoginUser); if (_organizatinID < 0) { organization = organizations.AddNewOrganization(); organization.ParentID = UserSession.LoginUser.OrganizationID; organization.PrimaryUserID = null; organization.ExtraStorageUnits = 0; organization.PortalSeats = 0; organization.UserSeats = 0; organization.IsCustomerFree = false; organization.ProductType = ProductType.Express; organization.HasPortalAccess = false; organization.IsActive = true; organization.IsBasicPortal = true; } else { organization = Organizations.GetOrganization(UserSession.LoginUser, _organizatinID); } int?id = int.Parse(cmbUsers.SelectedValue); organization.PrimaryUserID = id < 0 ? null : id; id = int.Parse(cmbSupportUsers.SelectedValue); organization.DefaultSupportUserID = id < 0 ? null : id; id = int.Parse(cmbGroups.SelectedValue); organization.DefaultPortalGroupID = id < 0 ? null : id; id = int.Parse(cmbSupportGroups.SelectedValue); organization.DefaultSupportGroupID = id < 0 ? null : id; organization.TimeZoneID = cmbTimeZones.SelectedValue; UserSession.LoginUser.TimeZoneInfo = null; try { TimeZoneInfo timeZoneInfo = TimeZoneInfo.FindSystemTimeZoneById(organization.TimeZoneID); } catch (Exception) { } if (organization.Name != "_Unknown Company") { organization.Name = textName.Text; } organization.Website = textWebSite.Text; organization.CompanyDomains = textDomains.Text; organization.Description = textDescription.Text; organization.SAExpirationDate = DataUtils.DateToUtc(UserSession.LoginUser, dpSAExpiration.SelectedDate); if (cmbSlas.SelectedIndex == 0) { organization.SlaLevelID = null; } else { organization.SlaLevelID = int.Parse(cmbSlas.SelectedValue); } int shm = 0; int.TryParse(textSupportHoursMonth.Text, out shm); organization.SupportHoursMonth = shm; if (_isAdmin) { organization.HasPortalAccess = cbPortal.Checked; organization.IsActive = cbActive.Checked; organization.IsApiActive = cbApiEnabled.Checked; organization.IsApiEnabled = cbApiEnabled.Checked; organization.InActiveReason = textActiveReason.Text; } organization.Collection.Save(); Settings.Session.WriteInt("SelectedOrganizationID", organization.OrganizationID); _customControls.RefID = organization.OrganizationID; if (_organizatinID != UserSession.LoginUser.OrganizationID) { _customControls.SaveCustomFields(); } return(true); }