protected override async Task OnInitializedAsync() { try { EmployeeService = ScopedServices.GetRequiredService <IEmployeeService>(); OrgStructureService = ScopedServices.GetRequiredService <IOrgStructureService>(); ModalDialogService.OnCancel += ModalDialogService_OnCancel; Employee = await EmployeeService.GetEmployeeByIdAsync(EmployeeId); if (Employee == null) { throw new Exception("Employee not found."); } EntityBeingEdited = MemoryCache.TryGetValue(Employee.Id, out object _); if (!EntityBeingEdited) { MemoryCache.Set(Employee.Id, Employee); } Companies = await OrgStructureService.GetCompaniesAsync(); if (Employee.DepartmentId == null) { Departments = new List <Department>(); } else { Departments = await OrgStructureService.GetDepartmentsByCompanyIdAsync(Employee.Department.CompanyId); } Positions = await OrgStructureService.GetPositionsAsync(); SetInitialized(); } catch (Exception ex) { Logger.LogError(ex.Message); SetLoadFailed(ex.Message); await ToastService.ShowToastAsync(ex.Message, ToastType.Error); await ModalDialogService.CancelAsync(); } }
protected override async Task OnInitializedAsync() { try { EmployeeService = ScopedServices.GetRequiredService <IEmployeeService>(); HardwareVaultService = ScopedServices.GetRequiredService <IHardwareVaultService>(); OrgStructureService = ScopedServices.GetRequiredService <IOrgStructureService>(); SharedAccountService = ScopedServices.GetRequiredService <ISharedAccountService>(); RemoteDeviceConnectionsService = ScopedServices.GetRequiredService <IRemoteDeviceConnectionsService>(); Companies = await OrgStructureService.GetCompaniesAsync(); Departments = new List <Department>(); Positions = await OrgStructureService.GetPositionsAsync(); SharedAccounts = await SharedAccountService.GetAllSharedAccountsAsync(); SharedAccountId = SharedAccounts.FirstOrDefault()?.Id; await LoadHardwareVaultsAsync(); Employee = new Employee() { Id = Guid.NewGuid().ToString() }; EmployeeContext = new EditContext(Employee); PersonalAccount = new AccountAddModel { EmployeeId = Employee.Id, LoginType = LoginType.Local }; PersonalAccountContext = new EditContext(PersonalAccount); SetInitialized(); } catch (Exception ex) { Logger.LogError(ex.Message); SetLoadFailed(ex.Message); await ToastService.ShowToastAsync(ex.Message, ToastType.Error); await ModalDialogService.CloseAsync(); } }
private async Task LoadPositionsAsync() { Positions = await OrgStructureService.GetPositionsAsync(); StateHasChanged(); }