Пример #1
0
 public void Add(EmployeeBaseInfo entity)
 {
     if (entity == null)
     {
         throw new ArgumentNullException("entity");
     }
     _employeeBaseInfoRepository.Add(entity);
 }
Пример #2
0
        //解析成员工信息,并更新或插入
        private void ParseToEntity(List <string> values, ref List <ImportErrorColModel> errors, bool isCoverData)
        {
            //判断源数据是否有身份证号
            if (!string.IsNullOrEmpty(values[1]))
            {
                //判断是否有EmployeeBaseInfo
                var baseInfo = _employeeBaseInfoRepository.GetByIDCard(values[1]);
                if (baseInfo == null)
                {
                    baseInfo = new EmployeeBaseInfo();
                    try
                    {
                        ParseToEmployeeBaseInfo(values, ref baseInfo, ref errors);

                        if (baseInfo != null)
                        {
                            _employeeBaseInfoRepository.Add(baseInfo);
                        }
                    }
                    catch (Exception e)
                    {
                        throw e;
                    }
                }
                else
                {
                    try
                    {
                        ParseToEmployeeBaseInfo(values, ref baseInfo, ref errors);
                    }
                    catch (Exception e)
                    {
                        throw e;
                    }
                }
                //_currentUserCompany = _companyService.GetById(_workContext.CurrentMembershipUser.Companies.FirstOrDefault(x => x.IsDefault == true).Id);
                _currentUserCompany = _companyService.GetById(_workContext.CurrentMembershipUser.Company.Id);
                //这里有问题,应先获取公司,再从公司获取员工
                var entity = _companyEmployeeRepository.GetEmployee(baseInfo.IDCard, _currentUserCompany.Id);
                //创建新员工
                if (entity == null)
                {
                    entity = new CompanyEmployee();
                    try
                    {
                        entity.EmployeeBaseInfo = baseInfo;
                        ParseToCompanyEmployee(values, ref entity, errors);
                        if (entity != null)
                        {
                            //是否覆盖
                            if (isCoverData)
                            {
                                _companyEmployeeRepository.DeleteByCompanyID(entity.Company.Id);
                            }
                            entity.EmployeeBaseInfo = baseInfo;
                            _companyEmployeeRepository.Add(entity);
                        }
                    }
                    catch (Exception e)
                    {
                        throw e;
                    }
                }
                else
                {
                    try
                    {
                        entity.EmployeeBaseInfo = baseInfo;
                        ParseToCompanyEmployee(values, ref entity, errors);
                    }
                    catch (Exception e)
                    {
                        throw e;
                    }
                }
            }
            else
            {
                //没有身份证号
                errors.Add(new ImportErrorColModel()
                {
                    ColIndex = 2,
                    Message  = ERROR_IDCARD_EMPTY,
                });
                //继续查看是否有其他错误
                var entity = new CompanyEmployee();
                try
                {
                    ParseToCompanyEmployee(values, ref entity, errors);
                }
                catch (Exception e)
                {
                    throw e;
                }
            }
        }
Пример #3
0
        //解析成员工信息,并更新或插入
        private void ParseToEntity(List <string> values, ref List <ImportErrorColModel> errors, bool isCoverData)
        {
            //判断源数据是否有身份证号
            if (!string.IsNullOrEmpty(values[1]))
            {
                //判断是否有EmployeeBaseInfo
                var baseInfo = _employeeBaseInfoRepository.GetByIDCard(values[1]);
                if (baseInfo == null)
                {
                    baseInfo = new EmployeeBaseInfo();
                    try
                    {
                        ParseToEmployeeBaseInfo(values, ref baseInfo, ref errors);
                        if (baseInfo != null)
                        {
                            _employeeBaseInfoRepository.Add(baseInfo);
                        }
                    }
                    catch (Exception e)
                    {
                        throw e;
                    }
                }
                else
                {
                    try
                    {
                        ParseToEmployeeBaseInfo(values, ref baseInfo, ref errors);
                    }
                    catch (Exception e)
                    {
                        throw e;
                    }
                }

                var entity = _employeeWorkHistoryRepository.GetByIDCard(values[1]);
                //创建新员工
                if (entity == null)
                {
                    entity = new EmployeeWorkHistory();
                    try
                    {
                        ParseToEmployeeWorkHistory(values, ref entity, ref errors);
                        if (entity != null)
                        {
                            entity.EmployeeBaseInfo = baseInfo;
                            _employeeWorkHistoryRepository.Add(entity);
                        }
                    }
                    catch (Exception e)
                    {
                        throw e;
                    }
                }
                else
                {
                    try
                    {
                        ParseToEmployeeWorkHistory(values, ref entity, ref errors);
                    }
                    catch (Exception e)
                    {
                        throw e;
                    }
                }
            }
            else
            {
                //没有身份证号
                errors.Add(new ImportErrorColModel()
                {
                    ColIndex = 2,
                    Message  = ERROR_IDCARD_EMPTY,
                });
                //继续查看是否有其他错误
                var entity = new EmployeeWorkHistory();
                try
                {
                    ParseToEmployeeWorkHistory(values, ref entity, ref errors);
                }
                catch (Exception e)
                {
                    throw e;
                }
            }
        }