Beispiel #1
0
        /// <summary>
        /// 获取数据。此数据会持续增长,所以不建议一次性缓存。建议单个Model实体缓存。
        /// </summary>
        public BaseResult GetUser(TStudentParam param)
        {
            var where = new Where <TStudent>();
            #region 模糊搜索条件
            if (!string.IsNullOrWhiteSpace(param.SearchName))
            {
                where.And(d => !d.Name.Equals(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 = TStudentRepository.Count(where);//.SetCacheTimeOut(10)
            }
            #endregion
            var list = TStudentRepository.Query(where, d => d.CreateTime, "desc", null, param._PageSize, param._PageIndex);
            return(new BaseResult(true, list, "", dateCount));
        }
Beispiel #2
0
        /// <summary>
        /// 获取数据
        /// </summary>
        public JsonResult GetUser(TStudentParam param)
        {
            var result = new TStudentLogic().GetUser(param);
            var test   = Json(result);

            return(test);
        }
Beispiel #3
0
        /// <summary>
        /// 获取数据。
        /// </summary>
        public BaseResult GetUser(TStudentParam param)
        {
            var where = new Where <TStudent>();
            #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
            var fs = Db.Context.From <TStudent>()
                     .Where(where)
                     .OrderByDescending(d => new { d.CreateTime, d.Id });
            #region 是否分页
            var dateCount = 0;
            if (param._PageIndex != null && param._PageSize != null)
            {
                //取总数,以计算共多少页。
                dateCount = fs.Count();
                fs.Page(param._PageSize.Value, param._PageIndex.Value);
            }
            #endregion
            var list = fs.ToList();


            return(new BaseResult(true, list, "", dateCount));
        }
Beispiel #4
0
        /// <summary>
        /// 修改数据。必须传入Id
        /// </summary>
        public BaseResult UptUser(TStudentParam param)
        {
            if (param.Id == null)
            {
                return(new BaseResult(false, null, Msg.ParamError));
            }
            var model = new TStudent();

            if (param.Name != null)
            {
                model.Name = param.Name;
            }
            if (param.IDNumber != null)
            {
                model.IDNumber = param.IDNumber;
            }
            if (param.MobilePhone != null)
            {
                model.MobilePhone = param.MobilePhone;
            }
            var count = TStudentRepository.Update(model, d => d.Id == param.Id);

            //更新缓存
            TStudentCache.DelUserModel(param.Id.Value);
            return(new BaseResult(true));
        }
Beispiel #5
0
        /// <summary>
        /// 删除数据。必须传入Id
        /// </summary>
        public BaseResult DelUser(TStudentParam param)
        {
            if (param.Id == null)
            {
                return(new BaseResult(false, null, "参数错误!"));
            }
            var count = Db.Context.Delete <TStudent>(d => d.Id == param.Id);

            return(new BaseResult(count > 0, count, count > 0 ? "" : "数据库受影响行数为0!"));
        }
Beispiel #6
0
        /// <summary>
        /// 删除数据。必须传入Id
        /// </summary>
        public BaseResult DelUser(TStudentParam param)
        {
            if (param.Id == null)
            {
                return(new BaseResult(false, null, Msg.ParamError));
            }
            var count = TStudentRepository.Delete(param.Id);

            //更新缓存
            TStudentCache.DelUserModel(param.Id.Value);
            return(new BaseResult(count > 0, count, count > 0 ? "" : Msg.Line0));
        }
        /// <summary>
        /// 获取数据
        /// </summary>
        public JsonResult GetUser(TStudentParam param)
        {
            var bs = new TStudentLogic().GetUser(param);

            #region 以下逻辑可以重写Json()在内部实现
            //var data = bs.Data as List<TestTable1>;
            ////Map目的是过滤前端不需要的字段,如一张表有100个字段,但是前端grid只需要显示10个字段,那么就有90个字段前端其实是不需要的,所以需要在这里过滤掉那90个字段,即在TableMysql_Page1设置前端需要的字段。
            //var result = Common.Common.Map<TestTable1, TestTable_Page1>(data);
            //bs.Data = result;
            ////var test = Json(result);
            #endregion
            return(Json(bs));
        }
Beispiel #8
0
        public BaseResult GetUserModel(TStudentParam param)
        {
            if (param.Id == null)
            {
                return(new BaseResult(false, null, Msg.ParamError));
            }
            //取缓存
            var model = TStudentCache.GetUserModel(param.Id.Value);

            if (model == null)
            {
                //如果缓存不存在,则从数据库获取
                model = TStudentRepository.First(d => d.Id == param.Id);
                TStudentCache.SetUserModel(model);
            }
            return(new BaseResult(true, model));
        }
Beispiel #9
0
        /// <summary>
        /// 修改数据。必须传入Id
        /// </summary>
        public BaseResult UptUser(TStudentParam param)
        {
            if (param.Id == null)
            {
                return(new BaseResult(false, null, "参数错误!"));
            }
            var model = Db.Context.From <TStudent>().Where(d => d.Id == param.Id).First();

            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 = Db.Context.Update <TStudent>(model);

            return(new BaseResult(true));
        }
Beispiel #10
0
        /// <summary>
        /// 新增数据。必须传入姓名Name,手机号MobilePhone,身份证号IDNumber
        /// </summary>
        public BaseResult AddUser(TStudentParam param)
        {
            if (string.IsNullOrWhiteSpace(param.Name) || string.IsNullOrWhiteSpace(param.MobilePhone) ||
                string.IsNullOrWhiteSpace(param.IDNumber))
            {
                return(new BaseResult(false, null, "参数错误!"));
            }
            var model = new TStudent
            {
                Id          = Guid.NewGuid(),
                Name        = param.Name,
                IDNumber    = param.IDNumber,
                MobilePhone = param.MobilePhone,
                CreateTime  = DateTime.Now
            };
            var count = Db.Context.Insert <TStudent>(model);

            return(new BaseResult(count > 0, count, count > 0 ? "" : "数据库受影响行数为0!"));
        }
Beispiel #11
0
        /// <summary>
        /// 新增数据。必须传入姓名Name,手机号MobilePhone,身份证号IDNumber
        /// </summary>
        public BaseResult AddUser(TStudentParam param)
        {
            if (string.IsNullOrWhiteSpace(param.Name) || string.IsNullOrWhiteSpace(param.MobilePhone) ||
                string.IsNullOrWhiteSpace(param.IDNumber))
            {
                return(new BaseResult(false, null, Msg.ParamError));
            }
            var model = new TStudent
            {
                Id          = Guid.NewGuid(),
                Name        = param.Name,
                IDNumber    = param.IDNumber,
                MobilePhone = param.MobilePhone,
                CreateTime  = DateTime.Now
            };
            var count = TStudentRepository.Insert(model);

            //设置缓存
            TStudentCache.SetUserModel(model);
            return(new BaseResult(count > 0, count, count > 0 ? "" : Msg.Line0));
        }
Beispiel #12
0
        /// <summary>
        /// 删除数据
        /// </summary>
        public JsonResult DelUser(TStudentParam param)
        {
            var result = new TStudentLogic().DelUser(param);

            return(Json(result));
        }