public async Task <ResponseMessage <CustomerProfileData> > CreateCustomerUser(Guid customerId, string username) { var customer = GetDbShipper(customerId); if (string.IsNullOrWhiteSpace(customer.TopsOwnerId)) { return(new ResponseMessage <CustomerProfileData> { Errors = new List <ResponseError> { new ResponseError { Message = "Owner Id must be saved." } } }); } var ssos = await _topsLoadshopApiService.GetSourceSystemOwners(customer.TopsOwnerId); if (!ssos.Success || !ssos.Data.ContainsKey(customer.TopsOwnerId)) { return(new ResponseMessage <CustomerProfileData> { Errors = new List <ResponseError> { new ResponseError { Message = $"This Owner Id ({customer.TopsOwnerId}) is not setup properly in tops." } } }); } var user = new RegisterViewModel { OwnerId = customer.TopsOwnerId.ToLower(), UserId = $"LS{customer.TopsOwnerId.ToLower()}", Password = $"LS{customer.TopsOwnerId.ToLower()}00", ConfirmPassword = $"LS{customer.TopsOwnerId.ToLower()}00", Company = customer.Name, FirstName = customer.Name, LastName = "User", Email = "*****@*****.**" }; //1. Create Identity User var topsResult = await _topsLoadshopApiService.CreateCustomerUser(user); if (topsResult.Success) { //2. set identUserId on customer customer.IdentUserId = topsResult.Data.Id; customer.LastChgBy = username; customer.LastChgDtTm = DateTime.Now; _context.SaveChanges(); //3. Create[user] for [customer] with same identUserId // a. same username as processSetting // b. assign them access to the customer and give them system role var securityAccessRoles = _mapper.Map <List <SecurityAccessRoleData> >( _context.SecurityAccessRoles .Where(x => x.AccessRoleName == "System") .ToList()); var userData = new UserData { //User Data Username = user.UserId, CompanyName = user.Company, Email = user.Email, FirstName = user.FirstName, LastName = user.LastName, //Identity Data IdentUserId = topsResult.Data.Id.GetValueOrDefault(), //Customer Data PrimaryCustomerId = customerId, ShipperIds = new List <Guid> { customerId }, //Security Data SecurityRoleIds = securityAccessRoles.Select(x => x.AccessRoleId).ToList(), //General Data IsNotificationsEnabled = false, CarrierScacs = new List <string>(), UserNotifications = new List <UserNotificationData>(), CreateBy = username, CreateDtTm = DateTime.Now, LastChgBy = username, LastChgDtTm = DateTime.Now }; var userDataResponse = await _userAdminService.Create(userData); return(new ResponseMessage <CustomerProfileData> { Data = GetShipper(customerId), Errors = userDataResponse.Exceptions?.Select(x => new ResponseError { Message = x.Message, StackTrace = x.StackTrace, Data = x.Data }).ToList() }); } return(new ResponseMessage <CustomerProfileData> { Errors = topsResult.Errors }); }