Exemple #1
0
        /// <summary>
        /// 获取数据。
        /// </summary>
        public BaseResult GetUser(TestTableParam param)
        {
            var where = new Where<TableMysql>();
            #region 模糊搜索条件
            if (!string.IsNullOrWhiteSpace(param.SearchName))
            {
                where.And(d => d.Name.Like(param.SearchName));
            }
            if (!string.IsNullOrWhiteSpace(param.SearchIDNumber))
            {
                where.And(d => d.IDNumber.Like(param.SearchIDNumber));
            }
            if (!string.IsNullOrWhiteSpace(param.SearchMobilePhone))
            {
                where.And(d => d.MobilePhone.Like(param.SearchMobilePhone));
            }
            #endregion

            #region 是否分页
            var dateCount = 0;
            if (param.pageIndex != null && param.pageSize != null)
            {
                //取总数,以计算共多少页。自行考虑将总数缓存。
                dateCount = new TableMysqlRepository().Count(where);//.SetCacheTimeOut(10)
            }
            #endregion
            var list = new TableMysqlRepository().Query(where, d => d.CreateTime, EnumService.OrderBy.Desc, null, param.pageSize, param.pageIndex);
            return new BaseResult(true, list, "", dateCount);
        }
 /// <summary>
 /// 获取数据
 /// </summary>
 public JsonResult GetUser(TestTableParam param)
 {
     var bs = new TableMySqlLogic().GetUser(param);
     #region 以下逻辑可以重写Json()在内部实现
     var data = bs.Data as List<TableMysql>;
     var result = Common.Common.Map<TableMysql, TableMysql_Page1>(data);
     bs.Data = result;
     //var test = Json(result);
     #endregion
     return Json(bs);
 }
Exemple #3
0
 /// <summary>
 /// 删除数据。必须传入Id
 /// </summary>
 public BaseResult DelUser(TestTableParam param)
 {
     if (param.Id == null)
     {
         return new BaseResult(false, null, "参数错误!");
     }
     var count = new TableMysqlRepository().Delete(param.Id);
     //更新缓存
     new TableMysqlCache().DelUserModel(param.Id.Value);
     return new BaseResult(count > 0, count, count > 0 ? "" : "数据库受影响行数为0!");
 }
Exemple #4
0
 /// <summary>
 /// 新增数据。必须传入姓名Name,手机号MobilePhone,身份证号IDNumber
 /// </summary>
 public BaseResult AddUser(TestTableParam param)
 {
     if (string.IsNullOrWhiteSpace(param.Name) || string.IsNullOrWhiteSpace(param.MobilePhone)
             || string.IsNullOrWhiteSpace(param.IDNumber))
     {
         return new BaseResult(false, null, "参数错误!");
     }
     var model = new TableMysql
     {
         Id = Guid.NewGuid(),
         Name = param.Name,
         IDNumber = param.IDNumber,
         MobilePhone = param.MobilePhone,
         CreateTime = DateTime.Now
     };
     var count = new TableMysqlRepository().Insert(model);
     //设置缓存
     new TableMysqlCache().SetUserModel(model.Id, model);
     return new BaseResult(count > 0, count, count > 0 ? "" : "数据库受影响行数为0!");
 }
 /// <summary>
 /// 删除数据
 /// </summary>
 public JsonResult DelUser(TestTableParam param)
 {
     var result = new TableMySqlLogic().DelUser(param);
     return Json(result);
 }
 /// <summary>
 /// 获取数据
 /// </summary>
 public JsonResult GetUser(TestTableParam param)
 {
     var result = new TableMySqlLogic().GetUser(param);
     var test = Json(result);
     return test;
 }
Exemple #7
0
 /// <summary>
 /// 修改数据。必须传入Id
 /// </summary>
 public BaseResult UptUser(TestTableParam param)
 {
     if (param.Id == null)
     {
         return new BaseResult(false, null, "参数错误!");
     }
     //取缓存
     var model = new TableMysqlCache().GetUserModel(param.Id.Value);
     if (model == null)
     {
         //如果缓存不存在,则从数据库获取
         model = new TableMysqlRepository().First(d => d.Id == param.Id);
     }
     if (model == null)
     {
         return new BaseResult(false, null, "不存在要修改的数据!");
     }
     model.Name = param.Name ?? model.Name;
     model.IDNumber = param.IDNumber ?? model.IDNumber;
     model.MobilePhone = param.MobilePhone ?? model.MobilePhone;
     var count = new TableMysqlRepository().Update(model);
     //更新缓存
     new TableMysqlCache().DelUserModel(param.Id.Value);
     return new BaseResult(true);
 }