public override bool Save() { if (string.IsNullOrEmpty(edtPhoneNumber.Text.Trim())) { _manager.Alert("Please enter a phone number."); return(false); } PhoneNumbers phoneNumbers = new PhoneNumbers(UserSession.LoginUser); if (_phoneID > -1) { phoneNumbers.LoadByPhoneID(_phoneID); if (!phoneNumbers.IsEmpty) { PhoneNumber phoneNumber = phoneNumbers[0]; phoneNumber.Extension = edtExtension.Text; phoneNumber.Number = edtPhoneNumber.Text; phoneNumber.PhoneTypeID = int.Parse(cmbTypes.SelectedValue); } } else { PhoneNumber phoneNumber = phoneNumbers.AddNewPhoneNumber(); phoneNumber.RefID = _refID; phoneNumber.RefType = _refType; phoneNumber.Extension = edtExtension.Text; phoneNumber.Number = edtPhoneNumber.Text; phoneNumber.PhoneTypeID = int.Parse(cmbTypes.SelectedValue); } phoneNumbers.Save(); return(true); }
public static string AddPhoneNumber(RestCommand command, ReferenceType refType, int refID) { if (!DataUtils.IsReferenceValid(command.LoginUser, refType, refID)) { throw new RestException(HttpStatusCode.Unauthorized); } PhoneNumbers items = new PhoneNumbers(command.LoginUser); PhoneNumber item = items.AddNewPhoneNumber(); item.ReadFromXml(command.Data, true); item.RefType = refType; item.RefID = refID; item.Collection.Save(); return(PhoneNumbersView.GetPhoneNumbersViewItem(command.LoginUser, item.PhoneID).GetXml("PhoneNumber", true)); }
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 static string CreateUser(RestCommand command) { if (Organizations.GetUserCount(command.LoginUser, command.LoginUser.OrganizationID) >= command.Organization.UserSeats) { throw new RestException(HttpStatusCode.Forbidden, "You are already at your maximum user seat count for your license."); } Addresses addresses = new Addresses(command.LoginUser); Address address = addresses.AddNewAddress(); PhoneNumbers phoneNumbers = new PhoneNumbers(command.LoginUser); PhoneNumber phoneNumber = phoneNumbers.AddNewPhoneNumber(); Users users = new Users(command.LoginUser); User user = users.AddNewUser(); user.FullReadFromXml(command.Data, true, ref phoneNumber, ref address); if (String.IsNullOrWhiteSpace(user.FirstName)) { throw new RestException(HttpStatusCode.BadRequest, "FirstName is required."); } ; if (String.IsNullOrWhiteSpace(user.LastName)) { throw new RestException(HttpStatusCode.BadRequest, "LastName is required."); } ; if (String.IsNullOrWhiteSpace(user.Email) || user.Email.IndexOf('@') < 0 || user.Email.IndexOf('.') < 0 || !users.IsEmailValid(user.Email, -1, command.LoginUser.OrganizationID)) { throw new RestException(HttpStatusCode.BadRequest, "Email is invalid."); } ; user.OrganizationID = command.LoginUser.OrganizationID; user.ActivatedOn = DateTime.UtcNow; user.LastLogin = DateTime.UtcNow.AddHours(-1); user.LastActivity = DateTime.UtcNow.AddHours(-1); user.EnforceSingleSession = true; user.NeedsIndexing = true; user.Collection.Save(); user.UpdateCustomFieldsFromXml(command.Data); if (!String.IsNullOrEmpty(phoneNumber.Number) || !String.IsNullOrEmpty(phoneNumber.Extension)) { phoneNumber.RefType = ReferenceType.Users; phoneNumber.RefID = user.UserID; 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.Users; address.RefID = user.UserID; addresses.Save(); } return(UsersView.GetUsersViewItem(command.LoginUser, user.UserID).GetXml("User", true)); }
public static string CreateContact(RestCommand command, int?organizationID) { Addresses addresses = new Addresses(command.LoginUser); Address address = addresses.AddNewAddress(); PhoneNumbers phoneNumbers = new PhoneNumbers(command.LoginUser); PhoneNumber phoneNumber = phoneNumbers.AddNewPhoneNumber(); Users users = new Users(command.LoginUser); User user = users.AddNewUser(); user.IsActive = true; user.FullReadFromXml(command.Data, true, ref phoneNumber, ref address); if (organizationID == null && user.OrganizationID == 0) { if (!String.IsNullOrEmpty(user.Email) && user.Email.Contains("@")) { Organizations matchDomainCompany = new Organizations(command.LoginUser); matchDomainCompany.LoadFirstDomainMatch(command.LoginUser.OrganizationID, user.Email.Substring(user.Email.LastIndexOf("@") + 1)); if (!matchDomainCompany.IsEmpty) { user.OrganizationID = matchDomainCompany[0].OrganizationID; } } if (user.OrganizationID == 0) { user.OrganizationID = Organizations.GetUnknownCompanyID(command.LoginUser); } } else if (organizationID != null) { user.OrganizationID = (int)organizationID; } user.ActivatedOn = DateTime.UtcNow; user.LastLogin = DateTime.UtcNow; user.LastActivity = DateTime.UtcNow.AddHours(-1); user.IsPasswordExpired = true; user.NeedsIndexing = true; if (!string.IsNullOrEmpty(user.CryptedPassword)) { user.CryptedPassword = FormsAuthentication.HashPasswordForStoringInConfigFile(user.CryptedPassword, "MD5"); } user.Collection.Save(); user.UpdateCustomFieldsFromXml(command.Data); if (!String.IsNullOrEmpty(phoneNumber.Number) || !String.IsNullOrEmpty(phoneNumber.Extension)) { phoneNumber.RefType = ReferenceType.Users; phoneNumber.RefID = user.UserID; 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.Users; address.RefID = user.UserID; addresses.Save(); } return(ContactsView.GetContactsViewItem(command.LoginUser, user.UserID).GetXml("Contact", true)); }