private bool updateUser(string associateId, string firstname, string lastname, string fullname, string username, string email, string role, string group, string license, DataGridViewRow item) { bool result = false; try { SoUser user = SoUser.ManageUser(Convert.ToInt32(associateId)); SuperOffice.CRM.Entities.Person p = user.Person; p.Firstname = firstname; p.Lastname = lastname; //p.PersonNumber = username; String pwd = username; EmailRow em = null; if (p.Emails.Count == 0) { em = p.Emails.AddNew(); em.SetDefaults(); } else { em = p.Emails[0]; } // always set correct email; we have just the one address em.EmailAddress = email; em.Protocol = "SMTP"; // save complete person entity p.Save(); //Console.WriteLine("\tPerson/email done"); // set our various properties user.SetPassword(pwd); user.GroupIdx = _groups[group]; user.OtherGroupIds = new int[0]; user.RoleIdx = _roles[role]; user.LogonName = username; user.Tooltip = fullname + " (" + SoSystemInfo.GetCurrent().CompanyName + ")"; // add licenses if (user.GetModuleLicense("SuperOffice", DefaultLicense).CanAssign) { user.GetModuleLicense("SuperOffice", DefaultLicense).Assigned = true; item.Cells["AssignedLicenses"].Value = "Assigned Default"; } else { item.Cells["AssignedLicenses"].Value = "Cannot Assign"; } //user.GetModuleLicense(SoLicenseNames.SuperLicenseServicePro).Assigned = true; /*user.GetModuleLicense(SoLicenseNames.User).Assigned = true; * user.GetModuleLicense(SoLicenseNames.Web).Assigned = true;*/ user.GetModuleLicense(SoLicenseNames.VisibleFor).Assigned = true; // save the user user.Save(); //Console.WriteLine("\tUser saved\n"); result = true; } catch (Exception ex) { MessageBox.Show(ex.Message); } return(result); }
private bool createUser(string firstname, string lastname, string fullname, string username, string email, string role, string group, string company, string license, DataGridViewRow item) { bool result = false; try { // find person by firstname, lastname & owner contact SuperOffice.CRM.Entities.Person.CustomSearch pc = new SuperOffice.CRM.Entities.Person.CustomSearch(); pc.Restriction = pc.TableInfo.Firstname.Equal(S.Parameter(firstname)). And(pc.TableInfo.Lastname.Equal(S.Parameter(lastname))). And(pc.TableInfo.ContactId.Equal(S.Parameter(_contacts[company]))); SuperOffice.CRM.Entities.Person p = SuperOffice.CRM.Entities.Person.GetFromCustomSearch(pc); // we either found an existing person, or got a blank, ready-to-populate one if (p.IsNew) { p.SetDefaults(_contacts[company]); p.Firstname = firstname; p.Lastname = lastname; } // always set userid into number field, for convenience p.PersonNumber = username; // find existing email, or create a new one EmailRow em = null; if (p.Emails.Count == 0) { em = p.Emails.AddNew(); em.SetDefaults(); } else { em = p.Emails[0]; } // always set correct email; we have just the one address em.EmailAddress = email; em.Protocol = "SMTP"; // save complete person entity p.Save(); // if person is associate - get him/her; otherwise create a new SoUser SoUser user; if (AssociateCache.GetCurrent().IsPersonAssociate(p.PersonId)) { user = SoUser.ManageUserFromPersonId(p.PersonId)[0]; } else { user = SoUser.CreateNew(p.PersonId, UserType.InternalAssociate); } // set our various properties user.SetPassword(username); user.GroupIdx = _groups[group]; user.OtherGroupIds = new int[0]; user.RoleIdx = _roles[role]; user.LogonName = username; user.Tooltip = fullname + " (" + company + ")"; // add licenses if (user.GetModuleLicense("SuperOffice", DefaultLicense).CanAssign) { user.GetModuleLicense("SuperOffice", DefaultLicense).Assigned = true; item.Cells["AssignedLicenses"].Value = "Assigned Default"; } else { item.Cells["AssignedLicenses"].Value = "Cannot Assign"; } //user.GetModuleLicense(SoLicenseNames.SuperLicenseServicePro).Assigned = true; /*user.GetModuleLicense(SoLicenseNames.User).Assigned = true; * user.GetModuleLicense(SoLicenseNames.Web).Assigned = true;*/ user.GetModuleLicense(SoLicenseNames.VisibleFor).Assigned = true; // save the user user.Save(); result = true; } catch (Exception ex) { MessageBox.Show(ex.Message); } return(result); }