UserInfoController

复制代码
  [HandlerLogin]
    public class UserInfoController : BaseController<UserInfo, UserInfoV>
    {

        UserInfoDal UserInfoDal = new UserInfoDal();

        // GET: Administration/UserInfo
        public ActionResult Index()
        {
            return View();
        }

        public ActionResult Edit()
        {
            return View();
        }



        public override ActionResult GetPageListForSQL(FormCollection collection)
        {
            JObject obj = new JObject();

            try
            {
                UserInfoV t = new UserInfoV();

                TryUpdateModel<UserInfoV>(t, collection);
                int CurrentPage = Convert.ToInt32(collection["page"]);
                int limit = Convert.ToInt32(collection["limit"]);

                PageDataView<UserInfoV> dailies = UserInfoDal.GetPageListForSQL(CurrentPage, limit, t);

                LayUIDataResult<UserInfoV> layUIDataResult = new LayUIDataResult<UserInfoV>()
                {
                    code = 0,
                    count = dailies.TotalNum,
                    msg = "",
                    data = dailies.Items.ToList()
                };

                obj.Add("code", "0");
                obj.Add("msg", "成功");
                obj.Add("data", dailies.ToJson());

                return Json(layUIDataResult, JsonRequestBehavior.AllowGet);
            }
            catch (Exception ex)
            {
                obj.Add("code", "-1");
                obj.Add("msg", ex.ToString());
                LoggerHelper._.Error(ex.ToString());
            }


            return Json("", JsonRequestBehavior.AllowGet);
        }





        /// <summary>
        /// 新增、修改
        /// </summary>
        /// <param name="model"></param>
        /// <returns></returns>
        public ActionResult InsertForUpdate2(UserInfoV t)
        {
            try
            {
                if (t.IsEnable == null)
                {
                    t.IsEnable = 0;
                }

                int res = UserInfoDal.InsertForUpdate(t);
                return Content(res.ToString());
            }
            catch (Exception ex)
            {

                LoggerHelper._.Error(ex.ToString());

                return Content("0");
            }


        }

        /// <summary>
        /// 删除用户 逻辑删除
        /// </summary>
        /// <param name="list"></param>
        /// <returns></returns>
        public ActionResult LogicDeleteBatch(List<UserInfo> list)
        {

            try
            {
                int res = UserInfoDal.LogicDeleteBatch(list);

                return Content(res.ToString());
            }
            catch (Exception ex)
            {

                LoggerHelper._.Error(ex.ToString());

                return Content("0");
            }
        }


        public override ActionResult UpdateNotNull(UserInfo t)
        {
            ResponseResult result = new ResponseResult();
            result.code = 0;
            result.msg = "成功";
            try
            {
                bool res = UserInfoDal.UpdateNotNull(t);

                result.data = res;

                return Json(result, JsonRequestBehavior.AllowGet);
            }
            catch (Exception ex)
            {
                LoggerHelper._.Error(ex.ToString());
                result.code = -1;
                result.msg = ex.Message;

                return Json(result, JsonRequestBehavior.AllowGet);
            }

        }

        [HttpPost]
        public override ActionResult QueryFirstOrDefaultView(FormCollection collection)
        {
            try
            {
                UserInfoV t = new UserInfoV();

                TryUpdateModel<UserInfoV>(t, collection);

                UserInfoV res = UserInfoDal.QueryFirstOrDefaultView(t);


                return Json(res, JsonRequestBehavior.AllowGet);

            }
            catch (Exception ex)
            {

                LoggerHelper._.Error(ex.ToString());
                return Json("", JsonRequestBehavior.AllowGet);
            }
        }



        /// <summary>
        /// 是否存在 工号
        /// </summary>
        /// <param name="model"></param>
        /// <returns></returns>
        [HttpPost]
        public ActionResult IsExist(UserInfoV model)
        {
            try
            {
                UserInfoV t = new UserInfoV();

                //TryUpdateModel<UserInfoV>(t, collection);

                List<UserInfoV> res = UserInfoDal.QueryForSQL(model);

                string b = (res == null || res.Where(p => p.Id != model.Id).Count() == 0) ? "0" : "1";

                return Content(b);

            }
            catch (Exception ex)
            {

                LoggerHelper._.Error(ex.ToString());
                return Content("0");
            }
        }


        /// <summary>
        /// 验证原密码是否正确
        /// </summary>
        /// <param name="model"></param>
        /// <returns></returns>
        [HttpPost]
        public ActionResult OriginalPassword(UserInfoV model)
        {
            ResponseResult result = new ResponseResult();
            result.code = 0;
            result.msg = "成功";

            try
            {
                UserInfo userInfo = CacheObjHelper.GetUserInfo();

                string pwd = EncryptionHelper.GetUserPwd(model.Password);

                result.data = userInfo;

                if (userInfo.Password != pwd)
                {
                    result.code = -1;
                    result.msg = "原密码错误";
                }

                return Json(result, JsonRequestBehavior.AllowGet);

            }
            catch (Exception ex)
            {

                LoggerHelper._.Error(ex.ToString());

                result.code = -1;
                result.msg = ex.Message;
                return Json(result, JsonRequestBehavior.AllowGet);

            }
        }


        /// <summary>
        /// 初始化密码
        /// </summary>
        /// <returns></returns>
        [HttpPost]
        public virtual ActionResult InitializationPassword(UserInfo t)
        {
            try
            {
                UserInfo userInfo = CacheObjHelper.GetUserInfo();
                t.LastModifyBy = userInfo.UserName + "|" + userInfo.Id;
                t.LastModifyTime = DateTime.Now;
                t.Password = EncryptionHelper.GetUserPwd("123456");
                bool res = UserInfoDal.UpdateNotNull(t);

                return Content(res.ToString());
            }
            catch (Exception ex)
            {
                LoggerHelper._.Error(ex.ToString());
                return Content("false");
            }


        }

        /// <summary>
        /// 修改角色
        /// </summary>
        /// <param name="t"></param>
        /// <returns></returns>
        //public ActionResult ExecuteUpdateRole(UserInfoV t)
        //{
        //    try
        //    {
        //        int res = UserInfoDal.ExecuteUpdateRole(t);

        //        return Content(res.ToString());
        //    }
        //    catch (Exception ex)
        //    {

        //        LoggerHelper._.Error(ex.ToString());

        //        return Content("0");
        //    }

        //}

    }
复制代码

 

posted @   妖狐鬼魅  阅读(12)  评论(0编辑  收藏  举报
编辑推荐:
· AI与.NET技术实操系列:基于图像分类模型对图像进行分类
· go语言实现终端里的倒计时
· 如何编写易于单元测试的代码
· 10年+ .NET Coder 心语,封装的思维:从隐藏、稳定开始理解其本质意义
· .NET Core 中如何实现缓存的预热?
阅读排行:
· 25岁的心里话
· 闲置电脑爆改个人服务器(超详细) #公网映射 #Vmware虚拟网络编辑器
· 基于 Docker 搭建 FRP 内网穿透开源项目(很简单哒)
· 零经验选手,Compose 一天开发一款小游戏!
· 一起来玩mcp_server_sqlite,让AI帮你做增删改查!!
点击右上角即可分享
微信分享提示