public async Task <Result> AddUserAsync(string companyId, AddUserParams data) { try { var company = await _dataService.CompanyService.ExternalGetAsync(companyId); var ug = new UsernameGenerator(data.FirstName, data.LastName, company.Name, UsernameGenerator.UserType.User); var newUser = data.GetUser(); newUser.CompanyId = company.Id; newUser.ApplicationLoginName = ug.Username; var validator = new AddUserValidator(_dataService); var valResults = validator.Validate(newUser); var validationSucceeded = valResults.IsValid; if (!validationSucceeded) { var failures = valResults.Errors; var message = failures.Aggregate(string.Empty, (current, failure) => current + (failure.ErrorMessage + "<br />")); return(new Result { IsCompleted = false, Success = false, Message = message }); } return(await _dataService.UserService.AddUserAsync(newUser)); } catch (Exception ex) { await _dataService.LogDataService.InsertLogoRecordAsync(nameof(AddUserAsync), nameof(Enums.LogLevel.Error), ex.Message, data.TransactionId, JsonConvert.SerializeObject(data)); return(new Result(false, ex.Message)); } }
internal Result AddUser(string companyId, AddUserParams data) { var loggerManager = new LoggerManager(); var operationGuid = Guid.NewGuid().ToString(); try { loggerManager.InsertLogoRecord(nameof(AddUser), nameof(LogLevel.Info), null, data.TransactionId, JsonConvert.SerializeObject(data)); var orderDemandManager = new OrderDemandManager(); var addUser = new CreateUserData { Address = data.Address, Email = data.Email, FirstName = data.FirstName, LastName = data.LastName, OrderDemandGuid = operationGuid, ContactInfo = data.ContactInfo, ExternalCustomerId = companyId, ExternalId = data.UserId, Username = data.Username }; var validator = new AddUserValidator(); var valResults = validator.Validate(addUser); var validationSucceeded = valResults.IsValid; if (!validationSucceeded) { var failures = valResults.Errors; var message = failures.Aggregate(string.Empty, (current, failure) => current + (failure.ErrorMessage + "<br />")); return(new Result { IsCompleted = false, Success = false, Message = message }); } orderDemandManager.SaveOrderDemand(null, operationGuid, 0, (int)ProvisionType.CreateUser, (int)OrderDemandStates.Created, (int)OrderDemandType.Integrated, JsonConvert.SerializeObject(addUser), data.TransactionId); return(new Result { IsCompleted = false, Success = true }); } catch (Exception ex) { loggerManager.InsertLogoRecord(nameof(AddUser), nameof(LogLevel.Error), ex.Message + " " + ex.StackTrace, operationGuid, JsonConvert.SerializeObject(data)); return(new Result { IsCompleted = true, Success = false, Message = ex.Message }); } }