Ejemplo n.º 1
0
        /// <summary>
        /// 将用户插入到数据库中
        /// </summary>
        /// <returns></returns>
        public JsonResult SaveUsersToDb()
        {
            var response = DingDingServices.GetAllUserList();

            if (response.ErroCode == 0 && response.Userlist != null && response.Userlist.Count > 0)
            {
                response.Userlist.ForEach(u => { if (u.Department != null)
                                                 {
                                                     u.Department.ToString();
                                                 }
                                          });
                string sqlStr = @"insert into DDUsers(
userid
,unionid
,[order]
,isAdmin
,isBoss
,isHide
,isLeader
,name
,active
,department
,position
,avatar
,jobnumber
) values(
@userid
,@unionid
,@order
,@isAdmin
,@isBoss
,@isHide
,@isLeader
,@name
,@active
,@department
,@position
,@avatar
,@jobnumber)";

                int m = DbHelper.Insert(sqlStr, response.Userlist);
                if (m > 0)
                {
                    return(Json(new
                    {
                        code = 0,
                        msg = "保存数据成功,共" + m + "条",
                        data = m
                    }, JsonRequestBehavior.AllowGet));
                }
            }
            return(Json(new
            {
                code = -1,
                msg = "保存数据失败"
            }, JsonRequestBehavior.AllowGet));
        }
Ejemplo n.º 2
0
        /// <summary>
        /// 从服务端更新数据库,有修改无插入
        /// </summary>
        /// <returns></returns>
        public JsonResult InsertOrUpdateUsersByUserId()
        {
            int mup = 0, min = 0;
            var response = DingDingServices.GetAllUserList();

            if (response.ErroCode == 0 && response.Userlist != null && response.Userlist.Count > 0)
            {
                response.Userlist.ForEach(u =>
                {
                    var user = DbHelper.QueryByUserId(u);
                    if (user != null)
                    {
                        mup += DbHelper.UpdateByUserId(u);
                    }
                    else
                    {
                        min += DbHelper.Insert(@"insert into DDUsers(
userid
,unionid
,[order]
,isAdmin
,isBoss
,isHide
,isLeader
,name
,active
,department
,position
,avatar
,jobnumber
) values(
@userid
,@unionid
,@order
,@isAdmin
,@isBoss
,@isHide
,@isLeader
,@name
,@active
,@department
,@position
,@avatar
,@jobnumber)", u);
                    }
                });
                if (mup > 0)
                {
                    return(Json(new
                    {
                        code = 0,
                        msg = "操作成功,共修改" + mup + "条,插入" + min + "条,更新完成",
                        data = mup + min
                    }, JsonRequestBehavior.AllowGet));
                }
            }
            return(Json(new
            {
                code = -1,
                msg = "更新失败"
            }, JsonRequestBehavior.AllowGet));
        }