internal static async Task SeedDefaultDepartments(IApiClient client, TenantContainer tenantInfo) { await client.SignInWithUserPasswordAsync(tenantInfo.AdminName, tenantInfo.AdminPassword); { // create department 1.1 var defaultDepartment11 = new DepartmentDto { Id = Guid.NewGuid().ToString(), Name = "Head Office Operations", BranchOfficeId = tenantInfo.BranchOffice_One.Id.ToString(), }; await client.PostDepartmentAsync(defaultDepartment11); tenantInfo.Department_1_1.Department = defaultDepartment11; } { // create department 1.2 var defaultDepartment12 = new DepartmentDto { Id = Guid.NewGuid().ToString(), Name = "Head Office Sales", BranchOfficeId = tenantInfo.BranchOffice_One.Id.ToString() }; var createdDto12 = await client.PostDepartmentAsync(defaultDepartment12); tenantInfo.Department_1_2.Department = defaultDepartment12; } }
internal static async Task SeedDefaultPosition(IApiClient client, TenantContainer tenantInfo) { var defaultPosition = new PositionDto { Id = Guid.NewGuid().ToString(), Name = "Electrical Engineer", }; await client.SignInWithUserPasswordAsync(tenantInfo.AdminName, tenantInfo.AdminPassword); var result = await client.PostPositionAsync(defaultPosition); tenantInfo.Position_Default = defaultPosition; }
/// <summary> /// creates 2 employees in each of departments (dept_1_1 and dept_1_2) /// </summary> /// <param name="client"></param> /// <param name="tenantInfo"></param> /// <returns></returns> internal static async Task SeedDefaultEmployees(IApiClient client, TenantContainer tenantInfo) { await client.SignInWithUserPasswordAsync(tenantInfo.AdminName, tenantInfo.AdminPassword); { var deptId = tenantInfo.Department_1_1.Department.Id.ToString(); var branchId = tenantInfo.BranchOffice_One.Id.ToString(); var employee1 = new EmployeeDto { Id = Guid.NewGuid().ToString(), FirstName = "John", LastName = "Doe", Gender = PskOnline.Client.Api.Models.Gender.Male, BirthDate = DateTime.UtcNow - TimeSpan.FromDays(30 * 365), DepartmentId = deptId, BranchOfficeId = branchId, PositionId = tenantInfo.Position_Default.Id }; var employee2 = new EmployeeDto { Id = Guid.NewGuid().ToString(), FirstName = "Dorothy", LastName = "Lovecraft", Gender = PskOnline.Client.Api.Models.Gender.Female, BirthDate = DateTime.UtcNow - TimeSpan.FromDays(26 * 365), DepartmentId = deptId, BranchOfficeId = branchId, PositionId = tenantInfo.Position_Default.Id }; await Task.WhenAll(client.PostEmployeeAsync(employee1), client.PostEmployeeAsync(employee2)); } { var deptId = tenantInfo.Department_1_2.Department.Id.ToString(); var branchId = tenantInfo.BranchOffice_One.Id.ToString(); var employee1 = new EmployeeDto { Id = Guid.NewGuid().ToString(), FirstName = "Sherlock", LastName = "Holmes", Gender = PskOnline.Client.Api.Models.Gender.Male, BirthDate = DateTime.UtcNow - TimeSpan.FromDays(34 * 365), DepartmentId = deptId, BranchOfficeId = branchId, PositionId = tenantInfo.Position_Default.Id }; var employee2 = new EmployeeDto { Id = Guid.NewGuid().ToString(), FirstName = "James", LastName = "Watson", Gender = PskOnline.Client.Api.Models.Gender.Male, BirthDate = DateTime.UtcNow - TimeSpan.FromDays(36 * 365), DepartmentId = deptId, BranchOfficeId = branchId, PositionId = tenantInfo.Position_Default.Id }; var employee3 = new EmployeeDto { Id = Guid.NewGuid().ToString(), FirstName = "Martha Louise", LastName = "Hudson", Gender = PskOnline.Client.Api.Models.Gender.Female, BirthDate = DateTime.UtcNow - TimeSpan.FromDays(55 * 365), DepartmentId = deptId, BranchOfficeId = branchId, PositionId = tenantInfo.Position_Default.Id }; await Task.WhenAll( client.PostEmployeeAsync(employee1), client.PostEmployeeAsync(employee2), client.PostEmployeeAsync(employee3)); } }
public static async Task <TenantContainer> CreateTenantWithRolesAndUsers(IApiClient client, HttpClient httpClient, TenantDto t) { IMapper mapper = new AutoMapperConfig().CreateMapper(); // pretend we are the site user... var tenantSpecification = new TenantContainer(t); var newT = new TenantCreateDto { TenantDetails = new TenantDto { Name = t.Name, Slug = t.Slug, Comment = t.Comment, PrimaryContact = new ContactInfoDto { FullName = "John Smith", MobilePhoneNumber = "+79998887766", StreetAddress = "931 Baker street", Email = "*****@*****.**" }, ServiceDetails = new ServiceDetailsDto { ServiceMaxEmployees = 1000, ServiceMaxUsers = 10, ServiceExpireDate = DateTime.Now + TimeSpan.FromDays(730), ServiceMaxStorageMegabytes = 40960 } }, AdminUserDetails = new TenantCreateAdminDto { UserName = tenantSpecification.AdminName, FirstName = "John", LastName = "Doe", Email = tenantSpecification.AdminName + "@somedomain.com", NewPassword = tenantSpecification.AdminPassword } }; var newTenantId = client.PostTenantAsync(newT).Result; tenantSpecification.Tenant.Id = newTenantId.ToString(); tenantSpecification.TenantId = newTenantId; // now read any details of the Tenant await client.SignInWithUserPassword_WithSlug_Async(newT.AdminUserDetails.UserName, newT.AdminUserDetails.NewPassword, httpClient, newT.TenantDetails.Slug); var tenantRoles = await client.GetRolesAsync(); tenantSpecification.TenantAdminRole = tenantRoles.First(r => r.Name.Contains("admin", StringComparison.InvariantCultureIgnoreCase)); tenantSpecification.TenantAdminRoleId = Guid.Parse(tenantSpecification.TenantAdminRole.Id); var tenantUsers = await client.GetUsersAsync(); var tenantAdminUser = tenantUsers.First( u => !string.IsNullOrEmpty(u.UserName) && u.UserName.Contains("admin", StringComparison.InvariantCultureIgnoreCase)); tenantSpecification.AdminUser = mapper.Map <UserEditDto>(tenantAdminUser); tenantSpecification.AdminUser.CurrentPassword = newT.AdminUserDetails.NewPassword; newT.AdminUserDetails.NewPassword = null; return(tenantSpecification); }
internal static async Task SeedDefaultBranchOffice(IApiClient client, HttpClient httpClient, TenantContainer tenantInformation) { var defaultBranchOffice = new BranchOfficeDto { Id = Guid.NewGuid().ToString(), Name = "Head Office", TimeZoneId = "MSK+5" // "Irkutsk time" }; await client.SignInWithUserPassword_WithSlug_Async( tenantInformation.AdminName, tenantInformation.AdminPassword, httpClient, tenantInformation.Tenant.Slug); var result = await client.PostBranchOfficeAsync(defaultBranchOffice); tenantInformation.BranchOffice_One = defaultBranchOffice; }