public static employee_info GetById(int id)
 {
     return(repository.GetById(id));
 }
Esempio n. 2
0
        public virtual ActionResult Edit(EmployeeInfoViewModel viewModel)
        {
            //validate birthdate
            if (!viewModel.EmployeeInfo.Employee.BirthDate.IsValidBirthDate())
            {
                GetDropDowns(viewModel, viewModel.EmployeeInfo.EmployeeId);
                ModelState.AddModelError("", ErrorMessages.INVALID_DATE);
                return(View("Details", viewModel));
            }

            var employeeInfo = _employeeInfoRepository.GetById(viewModel.EmployeeInfo.EmploymentInfoId);

            _employeeInfoRepository.Update(employeeInfo);

            employeeInfo.Allowance        = viewModel.EmployeeInfo.Allowance;
            employeeInfo.CustomDate1      = viewModel.EmployeeInfo.CustomDate1;
            employeeInfo.DateHired        = viewModel.EmployeeInfo.DateHired;
            employeeInfo.Dependents       = viewModel.EmployeeInfo.Dependents;
            employeeInfo.EmploymentStatus = viewModel.EmployeeInfo.EmploymentStatus;
            employeeInfo.GSIS             = viewModel.EmployeeInfo.GSIS;
            employeeInfo.Married          = viewModel.EmployeeInfo.Married;
            employeeInfo.PAGIBIG          = viewModel.EmployeeInfo.PAGIBIG;
            employeeInfo.EmploymentStatus = viewModel.EmployeeInfo.EmploymentStatus;
            employeeInfo.PhilHealth       = viewModel.EmployeeInfo.PhilHealth;
            employeeInfo.SSS              = viewModel.EmployeeInfo.SSS;
            employeeInfo.Salary           = viewModel.EmployeeInfo.Salary;
            employeeInfo.TIN              = viewModel.EmployeeInfo.TIN;
            employeeInfo.EmploymentStatus = viewModel.EmploymentStatus;

            employeeInfo.PositionId      = viewModel.PositionId;
            employeeInfo.SalaryFrequency = (FrequencyType)viewModel.PaymentFrequency;
            var picture = employeeInfo.Employee.Picture;

            employeeInfo.Employee.InjectFrom(viewModel.EmployeeInfo.Employee);
            employeeInfo.Employee.Gender  = viewModel.Gender;
            employeeInfo.Employee.Picture = picture;

            var employeeDeductions = viewModel.CheckedEmployeeDeductions != null
                                    ? JsonConvert.DeserializeObject <List <EmployeeDeduction> >(viewModel.CheckedEmployeeDeductions)
                                    : new List <EmployeeDeduction>();

            _employeeDeductionService.UpdateEmployeeDeduction(employeeDeductions, viewModel.EmployeeInfo.EmployeeId);

            var departments = viewModel.CheckedDepartments != null
                            ? viewModel.CheckedDepartments.Split(',').Select(Int32.Parse)
                            : new List <int>();

            //work schedules
            _employeeWorkScheduleService.Update(viewModel.WorkScheduleId, viewModel.EmployeeInfo.EmployeeId);

            _employeeRepository.UpdateDepartment(departments, viewModel.EmployeeInfo.EmployeeId);
            _employeeInfoHistoryRepository.Add(employeeInfo.MapItem <EmployeeInfoHistory>());
            _unitOfWork.Commit();

            //upload the picture and update the record
            var imagePath = UploadImage(viewModel.EmployeeInfo.EmployeeId);

            if (!String.IsNullOrEmpty(imagePath))
            {
                var employee = employeeInfo.Employee;
                _employeeRepository.Update(employee);
                employee.Picture = imagePath;
                _unitOfWork.Commit();
            }

            _logger.Info(LoggerMessages.INFO_USER_UPDATE, employeeInfo.EmployeeId, User.Identity.GetUserId());
            return(RedirectToAction("Index"));
        }