コード例 #1
0
        public GuYuanUser UpdateSingle(int id, GuYuanUserReq data)
        {
            GuYuanUser model = db.GuYuanUser.Find(id);

            SetGuYuanUser(model, data);
            db.SaveChanges();
            return(model);
        }
コード例 #2
0
ファイル: DingTalkBLL.cs プロジェクト: Liuzhangxi/maxliu
        private static GuYuanUser SyncUser(string dingUserId)
        {
            GuYuanUser gyUser = null;

            try
            {
                var db         = new Context();
                var corpClient = GetCorpClient();
                var dingUser   = corpClient.GetUser(dingUserId);
                gyUser = SetLocalUser(dingUser, db);
                db.SaveChanges();
            }
            catch (Exception ex)
            {
                System.Diagnostics.Debug.WriteLine(ex.Message);
            }

            return(gyUser ?? new GuYuanUser {
                Name = "未知"
            });
        }
コード例 #3
0
ファイル: DingTalkBLL.cs プロジェクト: Liuzhangxi/maxliu
        private static GuYuanUser SetLocalUser(User dingUser, Context db)
        {
            GuYuanUser dbGyUser = null;

            //--钉钉员工表--

            var dbDingUser = db.DingTalkUser.FirstOrDefault(n => n.userid == dingUser.userid);

            if (dbDingUser == null)
            {
                dbDingUser = new DingTalkUser {
                    Guid = Guid.NewGuid()
                };
                dbDingUser = db.DingTalkUser.Add(dbDingUser);
                dbGyUser   = db.GuYuanUser.FirstOrDefault(n => n.Phone == dingUser.mobile);
            }
            else
            {
                dbGyUser = db.GuYuanUser.FirstOrDefault(n => n.Guid == dbDingUser.Guid);
            }

            db.Entry(dbDingUser).CurrentValues.SetValues(dingUser);

            //--雇员所在部门--

            GuYuanDepartment gyDep = null;

            if (dingUser.department?.Any() == true)
            {
                var depId = dingUser.department.First();
                gyDep = db.GuYuanDepartment.FirstOrDefault(n => n.DingId == depId) ?? SyncDepartment(depId);
            }

            //--雇员信息表--

            if (dbGyUser == null)
            {
                dbGyUser = new GuYuanUser
                {
                    DepartmentName = gyDep?.DepartmentName,
                    OptName        = "钉钉同步",
                    OptId          = 0,
                    Name           = dingUser.name,
                    createdate     = DateTime.Now,
                    PositionName   = dingUser.position,
                    projectid      = gyDep?.ProjectId,
                    ProjectName    = gyDep?.ProjectName,
                    Guid           = dbDingUser.Guid,
                    Phone          = dingUser.mobile
                };
                db.GuYuanUser.Add(dbGyUser);
            }
            else
            {
                dbGyUser.DepartmentName = gyDep?.DepartmentName;
                dbGyUser.OptName        = "钉钉同步";
                dbGyUser.Name           = dingUser.name;
                dbGyUser.PositionName   = dingUser.position;
                dbGyUser.projectid      = gyDep?.ProjectId;
                dbGyUser.ProjectName    = gyDep?.ProjectName;
                dbGyUser.Phone          = dingUser.mobile;
            }

            return(dbGyUser);
        }
コード例 #4
0
        /// <summary>
        /// 设置model,如果不为空就设置,如果为空则和之前一样
        /// </summary>
        /// <param name="target"></param>
        /// <param name="source"></param>
        /// <returns></returns>
        public GuYuanUser SetGuYuanUser(GuYuanUser model, GuYuanUserReq data)
        {
            if (!string.IsNullOrEmpty(data.DepartmentName))
            {
                model.DepartmentName = data.DepartmentName;
            }
            if (!string.IsNullOrEmpty(data.State))
            {
                model.State = data.State;
            }
            if (!string.IsNullOrEmpty(data.OptName))
            {
                model.OptName = data.OptName;
            }
            if (data.OptId != null)
            {
                model.OptId = data.OptId.Value;
            }
            if (data.createdate != null && data.createdate != DateTime.MinValue && data.createdate != SqlDateTime.MinValue.Value)
            {
                model.createdate = data.createdate.Value;
            }
            if (!string.IsNullOrEmpty(data.Name))
            {
                model.Name = data.Name;
            }
            if (!string.IsNullOrEmpty(data.PositionName))
            {
                model.PositionName = data.PositionName;
            }
            if (!string.IsNullOrEmpty(data.Sex))
            {
                model.Sex = data.Sex;
            }
            if (data.OnboardDate != null && data.OnboardDate != DateTime.MinValue && data.OnboardDate != SqlDateTime.MinValue.Value)
            {
                model.OnboardDate = data.OnboardDate.Value;
            }
            if (data.FullMemberDate != null && data.FullMemberDate != DateTime.MinValue && data.FullMemberDate != SqlDateTime.MinValue.Value)
            {
                model.FullMemberDate = data.FullMemberDate.Value;
            }
            if (!string.IsNullOrEmpty(data.Nationality))
            {
                model.Nationality = data.Nationality;
            }
            if (!string.IsNullOrEmpty(data.Polity))
            {
                model.Polity = data.Polity;
            }
            if (data.Birthday != null && data.Birthday != DateTime.MinValue && data.Birthday != SqlDateTime.MinValue.Value)
            {
                model.Birthday = data.Birthday.Value;
            }
            if (!string.IsNullOrEmpty(data.IDCard))
            {
                model.IDCard = data.IDCard;
            }
            if (data.Age != null)
            {
                model.Age = data.Age.Value;
            }
            if (!string.IsNullOrEmpty(data.Phone))
            {
                model.Phone = data.Phone;
            }
            if (!string.IsNullOrEmpty(data.Marry))
            {
                model.Marry = data.Marry;
            }
            if (!string.IsNullOrEmpty(data.Education))
            {
                model.Education = data.Education;
            }
            if (!string.IsNullOrEmpty(data.EmergencyName))
            {
                model.EmergencyName = data.EmergencyName;
            }
            if (!string.IsNullOrEmpty(data.EmergencyRelation))
            {
                model.EmergencyRelation = data.EmergencyRelation;
            }
            if (!string.IsNullOrEmpty(data.EmergencyPhone))
            {
                model.EmergencyPhone = data.EmergencyPhone;
            }
            if (!string.IsNullOrEmpty(data.YongGongType))
            {
                model.YongGongType = data.YongGongType;
            }
            if (data.ContractExpireDate != null && data.ContractExpireDate != DateTime.MinValue && data.ContractExpireDate != SqlDateTime.MinValue.Value)
            {
                model.ContractExpireDate = data.ContractExpireDate.Value;
            }
            if (data.ContractMoney != null)
            {
                model.ContractMoney = data.ContractMoney.Value;
            }
            if (!string.IsNullOrEmpty(data.Mark))
            {
                model.Mark = data.Mark;
            }
            if (!string.IsNullOrEmpty(data.HuJi))
            {
                model.HuJi = data.HuJi;
            }
            if (!string.IsNullOrEmpty(data.CurrentLiving))
            {
                model.CurrentLiving = data.CurrentLiving;
            }
            if (!string.IsNullOrEmpty(data.HuJiLiving))
            {
                model.HuJiLiving = data.HuJiLiving;
            }
            if (!string.IsNullOrEmpty(data.HuJiType))
            {
                model.HuJiType = data.HuJiType;
            }
            if (!string.IsNullOrEmpty(data.SheBaoType))
            {
                model.SheBaoType = data.SheBaoType;
            }
            if (data.BaseSheBaoMoney != null)
            {
                model.BaseSheBaoMoney = data.BaseSheBaoMoney.Value;
            }
            if (data.SheBaoStartDate != null && data.SheBaoStartDate != DateTime.MinValue && data.SheBaoStartDate != SqlDateTime.MinValue.Value)
            {
                model.SheBaoStartDate = data.SheBaoStartDate.Value;
            }
            if (!string.IsNullOrEmpty(data.GongJiJingNumber))
            {
                model.GongJiJingNumber = data.GongJiJingNumber;
            }
            if (!string.IsNullOrEmpty(data.HeTongQiXian))
            {
                model.HeTongQiXian = data.HeTongQiXian;
            }
            if (!string.IsNullOrEmpty(data.WorkAge))
            {
                model.WorkAge = data.WorkAge;
            }
            if (!string.IsNullOrEmpty(data.BankCard))
            {
                model.BankCard = data.BankCard;
            }
            if (data.projectid != null)
            {
                model.projectid = data.projectid.Value;
            }
            if (!string.IsNullOrEmpty(data.ProjectName))
            {
                model.ProjectName = data.ProjectName;
            }
            if (!string.IsNullOrEmpty(data.FuZhuangChiCun))
            {
                model.FuZhuangChiCun = data.FuZhuangChiCun;
            }
            if (!string.IsNullOrEmpty(data.XieMa))
            {
                model.XieMa = data.XieMa;
            }
            if (data.JinShengDate != null && data.JinShengDate != DateTime.MinValue && data.JinShengDate != SqlDateTime.MinValue.Value)
            {
                model.JinShengDate = data.JinShengDate.Value;
            }
            if (data.LiZhiDate != null && data.LiZhiDate != DateTime.MinValue && data.LiZhiDate != SqlDateTime.MinValue.Value)
            {
                model.LiZhiDate = data.LiZhiDate.Value;
            }

            return(model);
        }