Example #1
0
        public async Task <ProfileEditViewModel> EditProfile(string employeeId)
        {
            var viewModel = new ProfileEditViewModel();

            viewModel.Departments = await _employeeDetailService.GetDepartments();

            //viewModel.Sections = await _employeeDetailService.GetSections();
            viewModel.Shifts = await _employeeDetailService.GetShifts();

            viewModel.JobTitles = await _employeeDetailService.GetPositions();

            //viewModel.JobFunctions = await _employeeDetailService.GetJobFunctions();
            viewModel.JobLevels = await _employeeDetailService.GetLevels();

            viewModel.BusStations = await _employeeDetailService.GetBusStations();

            var employee = await _employeeService.GetByEmployeeIdAsync(employeeId);

            if (employee != null)
            {
                viewModel.EmployeeId    = employee.EmployeeId;
                viewModel.GlobalId      = employee.GlobalId;
                viewModel.CardId        = employee.CardId;
                viewModel.Title         = employee.Title;
                viewModel.TitleThai     = employee.TitleThai;
                viewModel.EmployeeType  = employee.EmployeeType;
                viewModel.FirstName     = employee.FirstName;
                viewModel.LastName      = employee.LastName;
                viewModel.FirstNameThai = employee.FirstNameThai;
                viewModel.LastNameThai  = employee.LastNameThai;
                viewModel.Gender        = employee.Gender;
                viewModel.BirthDate     = employee.BirthDate;
                viewModel.HireDate      = employee.HireDate;
            }

            var employeeState = await _employeeStateService.GetByEmployeeId(employeeId);

            if (employeeState != null)
            {
                viewModel.DepartmentId  = employeeState.DepartmentId;
                viewModel.SectionId     = employeeState.SectionId;
                viewModel.ShiftId       = employeeState.ShiftId;
                viewModel.JobPositionId = employeeState.PositionId;
                viewModel.JobFunctionId = employeeState.JobFunctionId;
                viewModel.LevelId       = employeeState.LevelId;
                viewModel.BusStationId  = employeeState.BusStationId;
                viewModel.JoinDate      = employeeState.JoinDate;
            }

            var address = await _employeeAddressService.GetByEmployeeId(employeeId);

            if (address != null)
            {
                viewModel.EmployeeAddressId = address.EmployeeAddressId;
                viewModel.HomeAddress       = address.HomeAddress;
                viewModel.City         = address.City;
                viewModel.Country      = address.Country;
                viewModel.PostalCode   = address.PostalCode;
                viewModel.PhoneNumber  = address.PhoneNumber;
                viewModel.EmailAddress = address.EmailAddress;
            }


            return(viewModel);
        }
        public async Task <ProfileEditViewModel> EditProfile(string employeeId)
        {
            var viewModel = new ProfileEditViewModel();

            viewModel.Departments = await _employeeDetailService.GetDepartments();

            viewModel.Shifts = await _employeeDetailService.GetShifts();

            viewModel.JobPosition = await _employeeDetailService.GetPositions();

            viewModel.JobLevels = await _employeeDetailService.GetLevels();

            viewModel.Routes = await _employeeDetailService.GetRoutes();

            viewModel.BusStations = await _employeeDetailService.GetBusStations();

            var employee = await _employeeService.GetByEmployeeIdWithDetailAsync(employeeId);

            if (employee != null)
            {
                viewModel.EmployeeId    = employee.EmployeeId;
                viewModel.GlobalId      = employee.GlobalId;
                viewModel.CardId        = employee.CardId;
                viewModel.Title         = employee.Title;
                viewModel.TitleThai     = employee.TitleThai;
                viewModel.EmployeeType  = employee.EmployeeType;
                viewModel.FirstName     = employee.FirstName;
                viewModel.LastName      = employee.LastName;
                viewModel.FirstNameThai = employee.FirstNameThai;
                viewModel.LastNameThai  = employee.LastNameThai;
                viewModel.Height        = employee.Height;
                viewModel.Hand          = employee.Hand;
                viewModel.Gender        = employee.Gender;
                viewModel.BirthDate     = employee.BirthDate;
                viewModel.HireType      = employee.HireType;
                viewModel.HireDate      = employee.HireDate;

                if (employee.EmployeeState != null)
                {
                    viewModel.DepartmentId  = employee.EmployeeState.JobFunction.Section.Department.DepartmentId;
                    viewModel.SectionId     = employee.EmployeeState.JobFunction.Section.SectionId;
                    viewModel.ShiftId       = employee.EmployeeState.ShiftId;
                    viewModel.JobPositionId = employee.EmployeeState.PositionId;
                    viewModel.JobFunctionId = employee.EmployeeState.JobFunctionId;
                    viewModel.LevelId       = employee.EmployeeState.LevelId;
                    viewModel.RouteId       = employee.EmployeeState.BusStation.Route.RouteId;
                    viewModel.BusStationId  = employee.EmployeeState.BusStationId;
                    viewModel.JoinDate      = employee.EmployeeState.JoinDate;
                }
            }

            var address = await _employeeAddressService.GetByEmployeeId(employeeId);

            if (address != null)
            {
                viewModel.EmployeeAddressId = address.EmployeeAddressId;
                viewModel.HomeAddress       = address.HomeAddress;
                viewModel.City         = address.City;
                viewModel.Country      = address.Country;
                viewModel.PostalCode   = address.PostalCode;
                viewModel.PhoneNumber  = address.PhoneNumber;
                viewModel.EmailAddress = address.EmailAddress;
            }

            var image = await _employeeImageService.GetByEmployeeId(employeeId);

            if (image != null)
            {
                var imageBase64Data = Convert.ToBase64String(image.Images);
                viewModel.ProfileImage = string.Format("data:image/png;base64,{0}", imageBase64Data);
            }

            return(viewModel);
        }