Example #1
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, Msg.ParamError));
            }
            var model = new TestTable1
            {
                Id          = Guid.NewGuid(),
                Name        = param.Name,
                IDNumber    = param.IDNumber,
                MobilePhone = param.MobilePhone,
                CreateTime  = DateTime.Now,
                T2          = 0,
                T3          = 0,
                T4          = true,
                T7          = 0,
                T9          = 0
            };
            var count = TestTableRepository.Insert(model);

            //设置缓存
            TestTableCache.SetUserModel(model);
            return(new BaseResult(count > 0, count, count > 0 ? "" : Msg.Line0));
        }
Example #2
0
        public BaseResult GetUserModel(TestTableParam param)
        {
            if (param.Id == null)
            {
                return(new BaseResult(false, null, Msg.ParamError));
            }
            //取缓存
            var model = TestTableCache.GetUserModel(param.Id.Value);

            if (model == null)
            {
                //如果缓存不存在,则从数据库获取
                model = TestTableRepository.First(d => d.Id == param.Id);
                TestTableCache.SetUserModel(model);
            }
            return(new BaseResult(true, model));
        }