예제 #1
0
        /// <summary>
        /// 保存用户
        /// </summary>
        /// <param name="inObj"></param>
        /// <returns></returns>
        public async Task <ResultObj <int> > saveUser(WxUserEntity inObj, List <string> saveFieldList)
        {
            ResultObj <int> resultObj = new ResultObj <int>();
            var             saveEnt   = new DtoSave <WxUserEntity>()
            {
                data = inObj
            };
            string openid = inObj.openid;

            if (await dbHelper_user.Count(x => x.openid == openid) > 0)
            {
                saveEnt.ignoreFieldList = new List <string> {
                    "openid"
                };
                saveEnt.whereList = new List <string> {
                    "openid"
                };
                saveEnt.data.lastTime = DataTimeHelper.getDateLong(DateTime.Now);
                saveEnt.saveFieldList = saveFieldList;
                resultObj.data        = await dbHelper_user.Update(saveEnt);
            }
            else
            {
                saveEnt.data.createTime = DataTimeHelper.getDateLong(DateTime.Now);
                saveEnt.data.lastTime   = saveEnt.data.createTime;
                resultObj.data          = await dbHelper_user.Save(saveEnt);
            }

            resultObj.success = resultObj.data > 0;
            return(resultObj);
        }
예제 #2
0
        /// <summary>
        /// 替换账号
        /// </summary>
        /// <param name="inEnt"></param>
        /// <returns></returns>
        public async Task <Result> ChangeLoginName(ChangeLoginNameDto inEnt)
        {
            Result reObj = new Result();
            DapperHelper <SysUserEntity> userDapper = new DapperHelper <SysUserEntity>();

            userDapper.TranscationBegin();
            try
            {
                var loginDapper = new DapperHelper <SysLoginEntity>(userDapper.GetConnection(), userDapper.GetTransaction());
                if ((await loginDapper.Count(x => x.loginName == inEnt.newLoginName)) > 0 || (await userDapper.Count(x => x.loginName == inEnt.newLoginName)) > 0)
                {
                    userDapper.TranscationRollback();
                    reObj.success = false;
                    reObj.msg     = string.Format("账号{0}已经存在", inEnt.newLoginName);
                }
                else
                {
                    var pwd   = inEnt.password.Md5();
                    var login = await loginDapper.Single(x => x.loginName == inEnt.oldLoginName && x.password == pwd);

                    var user = await userDapper.Single(x => x.loginName == inEnt.oldLoginName);

                    if (login == null || user == null)
                    {
                        userDapper.TranscationRollback();
                        reObj.success = false;
                        reObj.msg     = string.Format("原账号有误");
                        return(reObj);
                    }

                    user.loginName  = inEnt.newLoginName;
                    login.loginName = inEnt.newLoginName;

                    reObj.success = await loginDapper.Update(new DtoSave <SysLoginEntity>
                    {
                        data             = login,
                        saveFieldListExp = x => new object[] { x.loginName },
                        whereList        = null
                    }) > 0;

                    if (!reObj.success)
                    {
                        userDapper.TranscationRollback();
                        reObj.success = false;
                        reObj.msg     = string.Format("更新账号失败");
                        return(reObj);
                    }

                    reObj.success = await userDapper.Update(new DtoSave <SysUserEntity>
                    {
                        data             = user,
                        saveFieldListExp = x => new object[] { x.loginName },
                        whereList        = null
                    }) > 0;

                    if (!reObj.success)
                    {
                        userDapper.TranscationRollback();
                        reObj.success = false;
                        reObj.msg     = string.Format("更新用户失败");
                        return(reObj);
                    }
                    reObj.success = true;
                    userDapper.TranscationCommit();
                }
            }
            catch (Exception e)
            {
                userDapper.TranscationRollback();
                reObj.success = false;
                reObj.msg     = e.Message;
            }
            return(reObj);
        }