/// <summary>
        /// 获取内容信息
        /// </summary>
        /// <returns></returns>
        public ActionResult GetSysIdCardInfo(long id)
        {
            var resultMode = new ResponseBaseModel <SysIdCardContentModel>
            {
                ResultCode = ResponceCodeEnum.Fail
            };
            var model = new SysIdCardContentModel();

            if (id < 1)
            {
                resultMode.Message    = "响应成功";
                resultMode.ResultCode = ResponceCodeEnum.Success;
                resultMode.Data       = model;
                return(Json(resultMode, JsonRequestBehavior.AllowGet));
            }

            model = new SysIdCardContentService().Get(id);
            resultMode.Message    = "响应成功";
            resultMode.ResultCode = ResponceCodeEnum.Success;
            resultMode.Data       = model;
            return(Json(resultMode, JsonRequestBehavior.AllowGet));
        }
        /// <summary>
        /// 添加信息
        /// </summary>
        /// <param name="model"></param>
        /// <returns></returns>
        public ActionResult SaveIdCardNumberInfo(SysIdCardContentModel model)
        {
            var resultMode = new ResponseBaseModel <SysIdCardContentModel>
            {
                ResultCode = ResponceCodeEnum.Fail
            };

            if (model == null)
            {
                return(Json(resultMode, JsonRequestBehavior.AllowGet));
            }
            if (string.IsNullOrEmpty(model.Name))
            {
                resultMode.Message = "姓名不能为空";
                return(Json(resultMode, JsonRequestBehavior.AllowGet));
            }
            if (string.IsNullOrEmpty(model.CardNumber))
            {
                resultMode.Message = "身份证号不能为空";
                return(Json(resultMode, JsonRequestBehavior.AllowGet));
            }

            if (!string.IsNullOrEmpty(model.Remarks))
            {
                var introduction = FilterHtmlHelper.NoHtml(model.Remarks);
                model.Remarks = introduction != null && introduction.Length > 200 ? introduction.Substring(0, 200) : introduction;
            }

            if (!IdCardValidatorHelper.CheckIdCard(model.CardNumber))
            {
                resultMode.Message = "身份证号有效性验证不通过";
                return(Json(resultMode, JsonRequestBehavior.AllowGet));
            }

            var cardModel = new IdCardNumber(model.CardNumber);
            var newModel  = new SysIdCardContentModel
            {
                Id         = model.Id,
                Age        = cardModel.Age,
                CardNumber = cardModel.CardNumber,
                Name       = model.Name,
                Remarks    = model.Remarks,
                City       = cardModel.City,
                Area       = cardModel.Area,
                CreateTime = DateTime.Now,
                Province   = cardModel.Province,
                Sex        = cardModel.Sex == 1 ? SexEnum.Boy : SexEnum.Grill
            };
            var server = new SysIdCardContentService();

            if (model.Id > 0)
            {
                var oldModel = server.Get(model.Id);
                if (oldModel == null)
                {
                    resultMode.Message = "不存在该内容记录";
                    return(Json(resultMode, JsonRequestBehavior.AllowGet));
                }

                newModel.CreateTime = oldModel.CreateTime;
            }
            else
            {
                var hadAdd = server.GetByCardNumber(model.CardNumber);
                if (hadAdd != null && hadAdd.CardNumber == model.CardNumber)
                {
                    resultMode.Message = "已经存在该身份证号码";
                    return(Json(resultMode, JsonRequestBehavior.AllowGet));
                }
            }

            try
            {
                server.SaveModel(newModel);
                resultMode.ResultCode = ResponceCodeEnum.Success;
                resultMode.Message    = "处理成功";
                return(Json(resultMode, JsonRequestBehavior.AllowGet));
            }
            catch (Exception e)
            {
                Console.WriteLine(e);
                resultMode.Message = "处理失败";
                return(Json(resultMode, JsonRequestBehavior.AllowGet));
            }
        }
Exemple #3
0
 /// <summary>
 /// 保存信息
 /// </summary>
 /// <param name="saveModel"></param>
 public void SaveModel(SysIdCardContentModel saveModel)
 {
     _idCardDataAccess.SaveModel(saveModel);
 }