public static Person CreatePerson(User newUser, Person newPerson) { if (newUser == null) { throw new ArgumentNullException("user"); } if (newPerson == null) { throw new ArgumentNullException("address"); } if (string.IsNullOrEmpty(newPerson.FirstName)) { throw new ArgumentNullException("firstName"); } if (string.IsNullOrEmpty(newPerson.LastName)) { throw new ArgumentNullException("lastName"); } if (string.IsNullOrEmpty(newPerson.Address.Id)) { if (string.IsNullOrEmpty(newPerson.Address.Address1)) { newPerson.Address.Address1 = "-"; } AddressManager.CreateAddress(newPerson.Address); newPerson.Address = AddressManager.GetAddressByDetails(newPerson.Address.Address1, newPerson.Address.Address2, newPerson.Address.Suburb, newPerson.Address.Postcode, newPerson.Address.State); } Person person = new Person(); person.Address = newPerson.Address; person.Email = newPerson.Email; person.FirstName = newPerson.FirstName; person.LastName = newPerson.LastName; person.PhoneNumber = newPerson.PhoneNumber; person.Position = newPerson.Position; person.WorkFax = newPerson.WorkFax; person.WorkMobile = newPerson.WorkMobile; person.WorkPhone = newPerson.WorkPhone; Provider.CreatePerson(person, newUser); return(GetPersonByUserName(newUser.Name)); }
public static void CreatePerson(string lastName, string firstName, Address address) { if (string.IsNullOrEmpty(lastName)) { throw new ArgumentNullException("lastName"); } if (string.IsNullOrEmpty(firstName)) { throw new ArgumentNullException("firstName"); } if (address == null) { throw new ArgumentNullException("address"); } if (string.IsNullOrEmpty(address.Id)) { AddressManager.CreateAddress(address); address = AddressManager.GetAddressByDetails(address.Address1, address.Address2, address.Suburb, address.Postcode, address.State); } var person = new Person(); person.FirstName = firstName; person.LastName = lastName; person.Address = address; // todo figure out a better default username. string defaultName = firstName + lastName; MembershipUser membershipUser = System.Web.Security.Membership.CreateUser(defaultName, defaultName); if (membershipUser.ProviderUserKey != null) { User user = MembershipManager.GetUser(membershipUser.ProviderUserKey.ToString()); Provider.CreatePerson(person, user); } }
protected void btnUpdate_Click(object sender, EventArgs e) { try { bool nameAvailable = true; Site currentSite = null; if (!string.IsNullOrEmpty(lblSiteId.Text)) { currentSite = SiteManager.GetSiteById(lblSiteId.Text); } Site site = SiteManager.GetSiteByName(txtSiteName.Text); if (site != null) { if (currentSite != null) { if (site != null && site.Id != currentSite.Id) { nameAvailable = false; ((IFeedback)Page.Master).ShowFeedback(Feedback.Actions.Error, "Site " + txtSiteName.Text + " already exists"); } } else //new site { nameAvailable = false; ((IFeedback)Page.Master).ShowFeedback(Feedback.Actions.Error, "Region " + txtSiteName.Text + " already exists"); } } if (nameAvailable) { // Figure out the address. Address physicalAddress = CreatePhysicalAddressFromFields(); //if (physicalAddress == null) // physicalAddress = new Address(); Address postalAddress = CreatePostalAddressFromFields(); //if (postalAddress == null) // postalAddress = new Address(); if (currentSite == null) { // Create a new site. currentSite = new Site(); currentSite.Name = txtSiteName.Text; // Just get the first available site type. We don't use site types at the moment. currentSite.SiteType = SiteManager.GetAllSiteTypes()[0]; currentSite.PhoneNumber = txtPhoneNumber.Text; currentSite.AltPhoneNumber = txtAltPhoneNumber.Text; currentSite.Email = txtEmail.Text; currentSite.Region = (Region)regions[cmbRegions.SelectedIndex]; currentSite.PhysicalAddress = physicalAddress; currentSite.PostalAddress = postalAddress; SiteManager.CreateSite(currentSite); lblSiteId.Text = SiteManager.GetSiteByName(currentSite.Name).Id; RefreshData(SiteManager.GetSiteByName(currentSite.Name).Id); btnUpdate.Text = UpdateSite; ((IFeedback)Master).QueueFeedback(BusiBlocksConstants.Blocks.Administration.LongName, currentSite.GetType().Name, Feedback.Actions.Created, currentSite.Name); Navigation.Admin_ManageLocations().Redirect(this); } else { if (physicalAddress != null) { if (currentSite.PhysicalAddress == null) { currentSite.PhysicalAddress = new Address(); } currentSite.PhysicalAddress.Address1 = physicalAddress.Address1; currentSite.PhysicalAddress.Address2 = physicalAddress.Address2; currentSite.PhysicalAddress.Suburb = physicalAddress.Suburb; currentSite.PhysicalAddress.Postcode = physicalAddress.Postcode; currentSite.PhysicalAddress.State = physicalAddress.State; if (string.IsNullOrEmpty(currentSite.PhysicalAddress.Id)) { AddressManager.CreateAddress(currentSite.PhysicalAddress); } else { AddressManager.UpdateAddress(currentSite.PhysicalAddress); } } else if (physicalAddress == null && currentSite.PhysicalAddress != null) { // Delete the address. AddressManager.DeleteAddress(currentSite.PhysicalAddress); currentSite.PhysicalAddress = null; } if (postalAddress != null) { if (currentSite.PostalAddress == null) { currentSite.PostalAddress = new Address(); } currentSite.PostalAddress.Address1 = postalAddress.Address1; currentSite.PostalAddress.Address2 = postalAddress.Address2; currentSite.PostalAddress.Suburb = postalAddress.Suburb; currentSite.PostalAddress.Postcode = postalAddress.Postcode; currentSite.PostalAddress.State = postalAddress.State; if (string.IsNullOrEmpty(currentSite.PostalAddress.Id)) { AddressManager.CreateAddress(currentSite.PostalAddress); } else { AddressManager.UpdateAddress(currentSite.PostalAddress); } } else if (postalAddress == null && currentSite.PostalAddress != null) { // Delete the address. AddressManager.DeleteAddress(currentSite.PostalAddress); currentSite.PostalAddress = null; } currentSite.Name = txtSiteName.Text; currentSite.PhoneNumber = txtPhoneNumber.Text; currentSite.AltPhoneNumber = txtAltPhoneNumber.Text; currentSite.Email = txtEmail.Text; currentSite.Region = (Region)regions[cmbRegions.SelectedIndex]; SiteManager.UpdateSite(currentSite); ((IFeedback)Master).QueueFeedback(BusiBlocksConstants.Blocks.Administration.LongName, currentSite.GetType().Name, Feedback.Actions.Saved, currentSite.Name); Navigation.Admin_ManageLocations().Redirect(this); } } } catch (Exception ex) { throw ex; ((IFeedback)Master).SetException(GetType(), ex); } }
public override void CreateSite(Site site) { if (site.Region == null) { throw new ArgumentNullException("site", "Region is null"); } if (site.SiteType == null) { throw new ArgumentNullException("site", "SiteType is null"); } if (string.IsNullOrEmpty(site.Name)) { throw new ProviderException("Site name cannot be empty or null."); } if (site.Name.IndexOf(',') > 0) { throw new ArgumentException("Site names cannot contain commas."); } if (GetSiteByName(site.Name) != null) { throw new ProviderException("Site name already exists."); } using (var transaction = new TransactionScope(_configuration)) { if (!RegionExists(site.Region)) { CreateRegion(site.Region); } else { site.Region = GetRegionByName(site.Region.Name); } if (!SiteTypeExists(site.SiteType)) { CreateSiteType(site.SiteType); } else { site.SiteType = GetSiteTypeByName(site.SiteType.Name); } //if (site.PhysicalAddress == null || string.IsNullOrEmpty(site.PhysicalAddress.Address1)) // site.PhysicalAddress = new Address.Address(); //if (site.PostalAddress == null || string.IsNullOrEmpty(site.PostalAddress.Address1)) // site.PostalAddress = new Address.Address(); if (site.PhysicalAddress != null) { if (string.IsNullOrEmpty(site.PhysicalAddress.Id)) { if (!string.IsNullOrEmpty(site.PhysicalAddress.Address1)) { Address currentAddress = AddressManager.GetAddressByDetails(site.PhysicalAddress.Address1, site.PhysicalAddress.Address2, site.PhysicalAddress.Suburb, site.PhysicalAddress.Postcode, site.PhysicalAddress.State); if (currentAddress == null) { AddressManager.CreateAddress(site.PhysicalAddress); } else { site.PhysicalAddress = currentAddress; } } } } if (site.PostalAddress != null) { if (string.IsNullOrEmpty(site.PostalAddress.Id)) { if (!string.IsNullOrEmpty(site.PostalAddress.Address1)) { Address currentAddress = AddressManager.GetAddressByDetails(site.PostalAddress.Address1, site.PostalAddress.Address2, site.PostalAddress.Suburb, site.PostalAddress.Postcode, site.PostalAddress.State); if (currentAddress == null) { AddressManager.CreateAddress(site.PostalAddress); } else { site.PostalAddress = currentAddress; } } } } var ptDs = new SiteDataStore(transaction); ptDs.Insert(site); transaction.Commit(); } }
protected void btCreateAdmin_Click(object sender, EventArgs e) { // Create a person type, and a role, and a persontyperole. PersonType adminPersonType = new PersonType(); adminPersonType.Name = BusiBlocks.BusiBlocksConstants.AdministratorsGroup; var personTypes = PersonManager.GetAllPersonTypes(true).FirstOrDefault(x => x.Name.Equals(adminPersonType.Name)); if (personTypes == null) { PersonManager.CreatePersonType(adminPersonType); } adminPersonType = PersonManager.GetAllPersonTypes(true).FirstOrDefault(x => x.Name.Equals(adminPersonType.Name)); Role role = RoleManager.GetRoleByName(txtAdminRole.Text); if (role == null) { Roles.CreateRole(txtAdminRole.Text); } PersonTypeRole personTypeRole = new PersonTypeRole(); personTypeRole.PersonType = adminPersonType; Role role1 = RoleManager.GetRoleByName(txtAdminRole.Text); personTypeRole.Role = role1; var personTypeRole1 = PersonManager.GetAllPersonTypeRoles().FirstOrDefault(x => (x.Role.Name.Equals(role1.Name) && x.PersonType.Name.Equals(personTypeRole.PersonType.Name))); if (personTypeRole1 == null) { PersonManager.CreatePersonTypeRole(personTypeRole); } string pwd = txtAdminPassword.Text; MembershipUser user2 = Membership.GetUser(txtAdminUser.Text); if (user2 == null) { Membership.CreateUser(txtAdminUser.Text, pwd, txtAdminEMail.Text); } MembershipUserCollection col = Membership.FindUsersByName(txtAdminUser.Text); MembershipUser memUser = col[txtAdminUser.Text]; User user = MembershipManager.GetUser(memUser.ProviderUserKey.ToString()); var roles1 = RoleManager.GetRolesByUser(user).FirstOrDefault(x => x.Name.Equals(role1.Name)); if (roles1 == null) { RoleManager.AddUserToRole(user, role1); } // Find a Person who matches this User. // If none exists, create one. string userName = txtAdminUser.Text; Person person = PersonManager.GetPersonByUserName(userName); if (person == null) { Address address1 = new Address(); address1.Address1 = "1 Admin Drive"; AddressManager.CreateAddress(address1); User user1 = MembershipManager.GetUserByName(userName); PersonManager.CreatePerson(user1, userName, address1); person = PersonManager.GetPersonByUserId(user1.Id); } var personType1 = PersonManager.GetPersonTypesByPerson(person).FirstOrDefault(x => x.Name.Equals(adminPersonType.Name)); if (personType1 == null) { PersonManager.AddPersonToPersonType(person.Id, adminPersonType.Id); } lblStatus.InnerText = "User created!"; }