예제 #1
0
        /// <summary>
        /// 修改菜单
        /// </summary>
        /// <param name="parm"></param>
        /// <returns></returns>
        public async Task <ApiResult <string> > ModifyAsync(SysAdmin parm)
        {
            var res = new ApiResult <string>
            {
                statusCode = 200
            };

            try
            {
                //修改,判断用户是否和其它的重复
                var isExisteName = SysAdminDb.IsAny(m => m.LoginName == parm.LoginName && m.Guid != parm.Guid);
                if (isExisteName)
                {
                    res.message    = "用户名已存在,请更换~";
                    res.statusCode = (int)ApiEnum.ParameterError;
                    return(await Task.Run(() => res));
                }

                parm.LoginPwd = DES3Encrypt.EncryptString(parm.LoginPwd);
                if (!string.IsNullOrEmpty(parm.DepartmentGuid))
                {
                    // 说明有父级  根据父级,查询对应的模型
                    var model = SysOrganizeDb.GetById(parm.DepartmentGuid);
                    parm.DepartmentGuidList = model.ParentGuidList;
                }
                var dbres = Db.Updateable <SysAdmin>().UpdateColumns(m => new SysAdmin()
                {
                    LoginName          = parm.LoginName,
                    LoginPwd           = parm.LoginPwd,
                    DepartmentName     = parm.DepartmentName,
                    DepartmentGuid     = parm.DepartmentGuid,
                    DepartmentGuidList = parm.DepartmentGuidList,
                    TrueName           = parm.TrueName,
                    Number             = parm.Number,
                    Sex    = parm.Sex,
                    Mobile = parm.Mobile,
                    Email  = parm.Email,
                    Status = parm.Status
                }).Where(m => m.Guid == parm.Guid).ExecuteCommand();
                if (dbres > 1)
                {
                    res.statusCode = (int)ApiEnum.Error;
                    res.message    = "更新失败!";
                }
            }
            catch (Exception ex)
            {
                res.message    = ApiEnum.Error.GetEnumText() + ex.Message;
                res.statusCode = (int)ApiEnum.Error;
                Logger.Default.ProcessError((int)ApiEnum.Error, ex.Message);
            }
            return(await Task.Run(() => res));
        }
예제 #2
0
        /// <summary>
        /// 添加部门信息
        /// </summary>
        /// <param name="parm"></param>
        /// <returns></returns>
        public new async Task <ApiResult <string> > AddAsync(SysAdmin parm)
        {
            var res = new ApiResult <string>
            {
                statusCode = 200,
                data       = "1"
            };

            try
            {
                //判断用吗是否存在
                var isExisteName = SysAdminDb.IsAny(m => m.LoginName == parm.LoginName);
                if (isExisteName)
                {
                    res.message    = "用户名已存在,请更换~";
                    res.statusCode = (int)ApiEnum.ParameterError;
                    return(await Task.Run(() => res));
                }
                parm.LoginPwd = DES3Encrypt.EncryptString(parm.LoginPwd);
                if (string.IsNullOrEmpty(parm.HeadPic))
                {
                    parm.HeadPic = "/themes/img/avatar.jpg";
                }
                parm.Guid    = Guid.NewGuid().ToString();
                parm.AddDate = DateTime.Now;
                if (!string.IsNullOrEmpty(parm.DepartmentGuid))
                {
                    // 说明有父级  根据父级,查询对应的模型
                    var model = SysOrganizeDb.GetById(parm.DepartmentGuid);
                    parm.DepartmentGuidList = model.ParentGuidList;
                }
                SysAdminDb.Insert(parm);
            }
            catch (Exception ex)
            {
                res.message    = ApiEnum.Error.GetEnumText() + ex.Message;
                res.statusCode = (int)ApiEnum.Error;
                Logger.Default.ProcessError((int)ApiEnum.Error, ex.Message);
            }
            return(await Task.Run(() => res));
        }