Ejemplo n.º 1
0
        protected override async Task OnInitializedAsync()
        {
            Saved     = false;
            Countries = (await CountryDataService.GetAllCountries()).ToList();
            //Employee = await EmployeeDataService.GetEmployeeDetails(int.Parse(EmployeeId));
            JobCategories = (await JobCategoryDataService.GetAllJobCategories()).ToList();

            int.TryParse(EmployeeId, out var employeeId);

            var savedEmployee = await LocalStorageService.GetAsync <Employee>("Employee");

            if (savedEmployee != null && employeeId == 0)
            {
                Employee = savedEmployee;
            }
            else if (employeeId == 0) //new employee is being created
            {
                //add some defaults
                Employee = new Employee {
                    CountryId = 1, JobCategoryId = 1, BirthDate = DateTime.Now, JoinedDate = DateTime.Now
                };
            }
            else
            {
                Employee = await EmployeeDataService.GetEmployeeDetails(int.Parse(EmployeeId));
            }

            CountryId     = Employee.CountryId.ToString();
            JobCategoryId = Employee.JobCategoryId.ToString();
        }
Ejemplo n.º 2
0
        public async Task InitializeAsync()
        {
            try
            {
                var token = await _localStorage.GetAsync <string>(LOCAL_USER_LOCAL_STORAGE_KEY);

                if (!string.IsNullOrWhiteSpace(token))
                {
                    await LoginAsync(token);
                }
            }
            catch (Exception ex)
            {
                _logger.Error($"Deserialize local user failed or login failed, require to re-login ex: {ex.Message}.");
                await _localStorage.ClearAsync();
            }
        }