Ejemplo n.º 1
0
        /// <summary>
        /// Load an Employee based on id, as as source for the component UI
        /// </summary>
        /// <returns></returns>
        protected async override Task OnInitializedAsync()
        {
            //Employee = (await EmployeeDataService.GetEmployeeDetails(int.Parse(EmployeeId)));
            Countries     = (await CountryDataService.GetAllCountries()).ToList();
            JobCategories = (await CategoryDataService.GetAllJobCategories()).ToList();

            int.TryParse(EmployeeId, out var employeeId);

            if (employeeId == 0)//New employee is created.
            {
                //Fill in some defaults for the new employee
                Employee = new Employee {
                    CountryId = 1, JobCategoryId = 1, BirthDate = DateTime.Now, JoinedDate = DateTime.Now
                };
            }
            else
            {
                Employee = (await EmployeeDataService.GetEmployeeDetails(int.Parse(EmployeeId)));
            }
            //To make two way binding work on the Countries SelectList, in order to show the Employees country as the selecte value,
            //we need to convert the Employee.CountryId to a string, and put it in a helper field (CountryId), that can then be used by the SelectList.
            //Basically, when binding to a ddl etc. using an Id from a model, it needs to be converted to string.
            CountryId     = Employee.CountryId.ToString();
            JobCategoryId = Employee.JobCategoryId.ToString();
        }