/// <summary> /// Create a new instance of an AccessRequest for a default user. /// </summary> /// <param name="id"></param> /// <param name="keycloakUserId"></param> /// <param name="username"></param> /// <param name="firstName"></param> /// <param name="lastName"></param> /// <param name="person"></param> /// <param name="role"></param> /// <param name="organization"></param> /// <returns></returns> public static Entity.PimsUser CreateUser(long id, Guid keycloakUserId, string username, string firstName = "given name", string lastName = "surname", Entity.PimsRole role = null, Entity.PimsOrganization organization = null, Entity.PimsAddress address = null) { organization ??= EntityHelper.CreateOrganization(id, "Organization 1"); role ??= EntityHelper.CreateRole("Real Estate Manager"); var person = new Entity.PimsPerson(lastName, firstName, address); person.PimsContactMethods = new List <Entity.PimsContactMethod>(); var user = new Entity.PimsUser(keycloakUserId, username, person) { Id = id, IssueDate = DateTime.UtcNow, ConcurrencyControlNumber = 1 }; user.PimsUserRoles.Add(new Entity.PimsUserRole() { Role = role, RoleId = role.Id, User = user, UserId = user.Id }); user.PimsUserOrganizations.Add(new Entity.PimsUserOrganization() { Organization = organization, OrganizationId = organization.Id, User = user, UserId = user.Id }); return(user); }
/// <summary> /// Get the concatenated full name of this person /// </summary> /// <param name="person"></param> /// <returns></returns> public static string GetFullName(this PimsPerson person) { if (person == null) { return(null); } string[] names = { person.FirstName, person.MiddleNames, person.Surname }; return(String.Join(" ", names.Where(n => n != null && n.Trim() != String.Empty))); }
/// <summary> /// Create a new instance of a Lease. /// </summary> /// <returns></returns> public static Entity.PimsLease CreateLease(int pid, string lFileNo = null, string tenantFirstName = null, string tenantLastName = null, string motiFirstName = null, string motiLastName = null, PimsAddress address = null, bool addTenant = false, bool addProperty = true, PimsLeaseProgramType pimsLeaseProgramType = null, PimsLeasePurposeType pimsLeasePurposeType = null, PimsLeaseStatusType pimsLeaseStatusType = null, PimsLeasePayRvblType pimsLeasePayRvblType = null, PimsLeaseCategoryType pimsLeaseCategoryType = null, PimsLeaseInitiatorType pimsLeaseInitiatorType = null, PimsLeaseResponsibilityType pimsLeaseResponsibilityType = null, PimsLeaseLicenseType pimsLeaseLicenseType = null, PimsRegion region = null) { var lease = new Entity.PimsLease() { LeaseId = pid, LFileNo = lFileNo, ConcurrencyControlNumber = 1, }; var person = new Entity.PimsPerson() { FirstName = tenantFirstName, Surname = tenantLastName }; person.PimsPersonAddresses.Add(new PimsPersonAddress() { Person = person, Address = address }); var organization = new Entity.PimsOrganization(); organization.PimsOrganizationAddresses.Add(new PimsOrganizationAddress() { Organization = organization, Address = address }); if (addProperty) { lease.PimsPropertyLeases.Add(new PimsPropertyLease() { Property = new Entity.PimsProperty() { Pid = pid }, Lease = lease }); } lease.MotiContact = $"{motiFirstName} {motiLastName}"; lease.LeaseProgramTypeCodeNavigation = pimsLeaseProgramType ?? new Entity.PimsLeaseProgramType() { Id = "testProgramType" }; lease.LeasePurposeTypeCodeNavigation = pimsLeasePurposeType ?? new Entity.PimsLeasePurposeType() { Id = "testPurposeType" }; lease.LeaseStatusTypeCodeNavigation = pimsLeaseStatusType ?? new Entity.PimsLeaseStatusType() { Id = "testStatusType" }; lease.LeasePayRvblTypeCodeNavigation = pimsLeasePayRvblType ?? new Entity.PimsLeasePayRvblType() { Id = "testRvblType" }; lease.LeaseCategoryTypeCodeNavigation = pimsLeaseCategoryType ?? new Entity.PimsLeaseCategoryType() { Id = "testCategoryType" }; lease.LeaseInitiatorTypeCodeNavigation = pimsLeaseInitiatorType ?? new Entity.PimsLeaseInitiatorType() { Id = "testInitiatorType" }; lease.LeaseResponsibilityTypeCodeNavigation = pimsLeaseResponsibilityType ?? new Entity.PimsLeaseResponsibilityType() { Id = "testResponsibilityType" }; lease.LeaseLicenseTypeCodeNavigation = pimsLeaseLicenseType ?? new Entity.PimsLeaseLicenseType() { Id = "testType" }; if (region != null) { lease.RegionCodeNavigation = region; } if (addTenant) { lease.PimsLeaseTenants.Add(new PimsLeaseTenant(lease, person, organization, new PimsLessorType("tst"))); } return(lease); }
/// <summary> /// DEPRECATED, either get an address by type, or get all addresses for a person. /// Get a single address from this user's address list. /// </summary> /// <param name="person"></param> /// <returns></returns> public static PimsAddress GetSingleAddress(this PimsPerson person) { return(person?.PimsPersonAddresses.FirstOrDefault()?.Address); }
/// <summary> /// Get the mailing address of the person, or null if the person does not have a mailing address. /// Note this will only return a value if Person.ContactMethods.ContactType is eager loaded into context. /// </summary> /// <param name="person"></param> /// <returns></returns> public static PimsAddress GetMailingAddress(this PimsPerson person) { return(person?.PimsPersonAddresses.FirstOrDefault(a => a?.AddressUsageTypeCode == AddressUsageTypes.Mailing)?.Address); }
/// <summary> /// Get the first mobile phone number for the person from their contact methods, prioritizing numbers with preferred set. /// Note this will only return a value if Person.ContactMethods.ContactType is eager loaded into context. /// </summary> /// <param name="person"></param> /// <returns></returns> public static string GetMobilePhoneNumber(this PimsPerson person) { return(person?.PimsContactMethods.OrderBy(cm => cm.IsPreferredMethod).FirstOrDefault(cm => cm.ContactMethodTypeCode == ContactMethodTypes.PerseMobil || cm.ContactMethodTypeCode == ContactMethodTypes.WorkMobil)?.ContactMethodValue); }
/// <summary> /// Get the first email address for the person from their contact methods, preferring work emails. /// Note this will only return a value if Person.ContactMethods.ContactType is eager loaded into context. /// </summary> /// <param name="person"></param> /// <returns></returns> public static string GetEmail(this PimsPerson person) { return(person?.PimsContactMethods.OrderBy(cm => cm.ContactMethodTypeCode == "WORKEMAIL" ? 0 : 1).ThenByDescending(cm => cm.IsPreferredMethod) .FirstOrDefault(cm => cm.ContactMethodTypeCode == ContactMethodTypes.WorkEmail || cm.ContactMethodTypeCode == ContactMethodTypes.PerseEmail)?.ContactMethodValue); }
/// <summary> /// Get the first email address for the person from their contact methods. /// Note this will only return a value if Person.ContactMethods.ContactType is eager loaded into context. /// </summary> /// <param name="person"></param> /// <returns></returns> public static string GetWorkEmail(this PimsPerson person) { return(person?.PimsContactMethods?.OrderByDescending(cm => cm.IsPreferredMethod).FirstOrDefault(cm => cm.ContactMethodTypeCode == ContactMethodTypes.WorkEmail)?.ContactMethodValue); }