Ejemplo n.º 1
0
        private static void CheckException(IInlineMessage message, Exception exception)
        {
            switch (exception)
            {
            case ArgumentException _:
                message.ResultData = ApiResultHelper.State(OperatorStatusCode.ArgumentError, $"参数错误.{exception.Message}");
                break;

            case DbException _:
                message.ResultData = ApiResultHelper.State(OperatorStatusCode.Ignore, $"数据库异常.{exception.Message}");
                break;

            case NotSupportedException _:
                message.ResultData = ApiResultHelper.State(OperatorStatusCode.Ignore, $"不支持的方法.{exception.Message}");
                break;

            case NullReferenceException _:
                message.ResultData = ApiResultHelper.State(OperatorStatusCode.Ignore, $"空引用错误.{exception.Message}");
                break;

            case SystemException _:
                message.ResultData = ApiResultHelper.State(OperatorStatusCode.Ignore, $"系统级错误.{exception.Message}");
                break;

            case MessageBusinessException mbe:
                CheckException(message, mbe.InnerException);
                break;

            default:
                message.ResultData = ApiResultHelper.State(OperatorStatusCode.UnhandleException, $"未知错误.{exception.Message}");
                break;
            }
        }
Ejemplo n.º 2
0
        public async Task <IApiResult> CustomSerialize(Argument argument)
        {
            logger.Information(() => $"Call {nameof(Argument)}({argument?.Value})");
            await Task.Delay(100);

            return(ApiResultHelper.Succees());
        }
Ejemplo n.º 3
0
        public Task <IApiResult <string> > TaskTest()
        {
            logger.LogInformation($"Call {nameof(TaskTest)}");
            var res = ApiResultHelper.Succees(nameof(TaskTest));

            return(Task.FromResult(res));
        }
Ejemplo n.º 4
0
 public IApiResult AuditPass(IdsArguent arg)
 {
     OnAuditPass();
     return(IsFailed
             ? ApiResultHelper.State(GlobalContext.Current.Status.LastState, GlobalContext.Current.Status.LastMessage)
             : ApiResultHelper.Succees());
 }
Ejemplo n.º 5
0
        public async Task <IApiResult> Async()
        {
            await Task.Yield();

            logger.LogInformation($"Call {nameof(Async)}");
            return(ApiResultHelper.Succees(nameof(Async)));
        }
Ejemplo n.º 6
0
        public async Task <IApiResult> Argument(Argument argument)
        {
            logger.LogInformation($"Call {nameof(Argument)}({argument.Value})");
            await Task.Delay(100);

            return(ApiResultHelper.Succees());
        }
Ejemplo n.º 7
0
        public async Task <ApiResult> Create(string name, string sex, string telnumber, string address, string units, string adminname, string adminpwd)
        {
            AdminInfo admin = new AdminInfo
            {
                Name      = name,
                Sex       = sex,
                TelNumber = telnumber,
                Address   = address,
                Units     = units,
                AdminName = adminname,
                AdminPwd  = MD5Helper.MD5Encrypt32(adminpwd) //MD5加密
            };
            //判断数据库中是否已经存在账号跟要添加的账号相同的数据
            var oldAdmin = await _iAdminInfoService.FindAsync(c => c.AdminName == adminname);

            if (oldAdmin != null)
            {
                return(ApiResultHelper.Error("账号已经存在"));
            }
            bool b = await _iAdminInfoService.CreateAsync(admin);

            if (!b)
            {
                return(ApiResultHelper.Error("添加失败"));
            }
            return(ApiResultHelper.Success(admin));
        }
Ejemplo n.º 8
0
        public async Task <ApiResult> Create(string name, string sex, string telnumber, string address, string units, string Counselorname, string Counselorpwd)
        {
            CounselorInfo Counselor = new CounselorInfo
            {
                Name      = name,
                Sex       = sex,
                TelNumber = telnumber,
                Address   = address,
                Units     = units,
                UserName  = Counselorname,
                UserPwd   = MD5Helper.MD5Encrypt32(Counselorpwd) //MD5加密
            };
            //判断数据库中是否已经存在账号跟要添加的账号相同的数据
            var oldCounselor = await _iCounselorInfoService.FindAsync(c => c.UserName == Counselorname);

            if (oldCounselor != null)
            {
                return(ApiResultHelper.Error("账号已经存在"));
            }
            bool b = await _iCounselorInfoService.CreateAsync(Counselor);

            if (!b)
            {
                return(ApiResultHelper.Error("添加失败"));
            }
            return(ApiResultHelper.Success(Counselor));
        }
Ejemplo n.º 9
0
        public async Task <ApiResult> Create(string name, string username, string userpwd)
        {
            //数据校验
            WriterInfo writer = new WriterInfo
            {
                Name = name,
                //加密密码
                UserPwd  = MD5Helper.MD5Encrypt32(userpwd),
                UserName = username
            };
            //判断数据库中是否已经存在账号跟要添加的账号相同的数据
            var oldWriter = await _iWriterInfoService.FindAsync(c => c.UserName == username);

            if (oldWriter != null)
            {
                return(ApiResultHelper.Error("账号已经存在"));
            }

            bool b = await _iWriterInfoService.CreateAsync(writer);

            if (!b)
            {
                return(ApiResultHelper.Error("添加失败"));
            }
            return(ApiResultHelper.Success(writer));
        }
        /// <summary>
        /// 获取市民卡持卡人的个人信息
        /// </summary>
        /// <param name="verify"></param>
        /// <returns></returns>
        public static ApiResult <CitizenCardPerson> GetCitizenCardPerson(string cardNo, string webUrl)
        {
            if (string.IsNullOrEmpty(cardNo))
            {
                return(ApiResultHelper <CitizenCardPerson> .getFailApiResult("市民卡号码不能为空", null));
            }
            if (string.IsNullOrEmpty(webUrl))
            {
                return(ApiResultHelper <CitizenCardPerson> .getFailApiResult("没有找到管理后台地址,请检查配置文件", null));
            }

            var gateUrl = ApiHelper.GetTicketGateWayUrl(webUrl);

            if (string.IsNullOrEmpty(gateUrl))
            {
                return(ApiResultHelper <CitizenCardPerson> .getFailApiResult("没有找到前置网关地址", null));
            }

            var result = ApiHelper.SendDataToApiService <CitizenCardPerson>(
                string.Format("{0}citizencard/api/citizencard/getcitizencardperson?cardNo={1}"
                              , gateUrl, System.Uri.EscapeUriString(cardNo))
                , "GET", string.Empty);

            return(result);
        }
Ejemplo n.º 11
0
        public async Task <ApiResult> Login(string username, string userpwd)
        {
            //加密后的密码 123456 =>sdlkfjkldsjidaifdaskfaj == sdlkfjkldsjidaifdaskfaj
            string pwd = MD5Helper.MD5Encrypt32(userpwd);
            //数据校验
            var writer = await _iWriterInfoService.FindAsync(c => c.UserName == username && c.UserPwd == pwd);

            if (writer != null)
            {
                //登陆成功
                var claims = new Claim[]
                {
                    new Claim(ClaimTypes.Name, writer.Name),
                    new Claim("Id", writer.Id.ToString()),
                    new Claim("UserName", writer.UserName)
                    //不能放敏感信息
                };
                var key = new SymmetricSecurityKey(Encoding.UTF8.GetBytes("SDMC-CJAS1-SAD-DFSFA-SADHJVF-VF"));
                //issuer代表颁发Token的Web应用程序,audience是Token的受理者
                var token = new JwtSecurityToken(
                    issuer: "http://localhost:6060",
                    audience: "http://localhost:5000",
                    claims: claims,
                    notBefore: DateTime.Now,
                    expires: DateTime.Now.AddHours(1),
                    signingCredentials: new SigningCredentials(key, SecurityAlgorithms.HmacSha256)
                    );
                var jwtToken = new JwtSecurityTokenHandler().WriteToken(token);
                return(ApiResultHelper.Success(jwtToken));
            }
            else
            {
                return(ApiResultHelper.Error("账号或密码错误"));
            }
        }
Ejemplo n.º 12
0
        /// <summary>
        /// 发送数据到Api服务接口
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="apiUrl"></param>
        /// <param name="requestType"></param>
        /// <param name="param"></param>
        /// <returns></returns>
        public static ApiResult <T> SendDataToApiService <T>(string apiUrl, string requestType, string param)
        {
            if (string.IsNullOrEmpty(apiUrl) || string.IsNullOrEmpty(requestType))
            {
                return(ApiResultHelper <T> .getFailApiResult("没有找到api接口地址", default(T)));
            }

            string          strJson  = string.Empty;
            HttpWebRequest  request  = null;
            HttpWebResponse response = null;

            try
            {
                ASCIIEncoding encoding = new ASCIIEncoding();
                request = WebRequest.Create(apiUrl) as HttpWebRequest;
                //request.ProtocolVersion = HttpVersion.Version11;
                //request.AllowAutoRedirect = true;
                //request.KeepAlive = true;
                //request.Headers.Add("Accept-Language", "zh-cn");
                //request.Accept = "*/*";
                //request.UserAgent = "Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 5.2; Trident/4.0;)";

                byte[] b = Encoding.UTF8.GetBytes(param);
                request.ContentType   = "application/json";
                request.ContentLength = b.Length;
                request.Method        = requestType;
                if (b.Length > 0)
                {
                    using (Stream stream = request.GetRequestStream())
                    {
                        stream.Write(b, 0, b.Length);
                        stream.Close();
                    }
                }

                //获取服务器返回的资源
                using (response = request.GetResponse() as HttpWebResponse)                                                     //自动关闭和释放
                {
                    using (StreamReader reader = new StreamReader(response.GetResponseStream(), Encoding.GetEncoding("utf-8"))) //自动关闭和释放
                    {
                        strJson = reader.ReadToEnd();
                        reader.Close();
                    }
                }
                return(JsonConvert.DeserializeObject <ApiResult <T> >(strJson));
            }
            catch (Exception exception)
            {
                //new Common.LogHelper().WriteLine(exception.ToString());
                return(ApiResultHelper <T> .getFailApiResult(exception.Message, default(T)));
            }
            finally
            {
                if (response != null)
                {
                    response.Close();
                }
            }
        }
Ejemplo n.º 13
0
        public async Task <ApiResult> FindAdmin([FromServices] IMapper iMapper)
        {
            var admin = await _iAdminInfoService.QueryAsync();

            var adminDTO = iMapper.Map <AdminDTO>(admin);

            return(ApiResultHelper.Success(adminDTO));
        }
Ejemplo n.º 14
0
        public async Task <ApiResult> FindWriter([FromServices] IMapper iMapper, int id)
        {
            var writer = await _iWriterInfoService.FindAsync(id);

            var writerDTO = iMapper.Map <WriterDTO>(writer);

            return(ApiResultHelper.Success(writerDTO));
        }
Ejemplo n.º 15
0
        public async Task <IApiResult> Argument2(Argument argument
                                                 , [ArgumentSerializeType(SerializeType.Json)] Argument arg2)
        {
            logger.LogInformation($"Call {nameof(Argument)}({argument.Value})");
            await Task.Delay(100);

            return(ApiResultHelper.Succees());
        }
Ejemplo n.º 16
0
 public IApiResult TaskTest()
 {
     LogRecorder.Trace(Task.CurrentId?.ToString());
     Task.Delay(100);
     LogRecorder.Trace(Task.CurrentId?.ToString());
     LogRecorder.Trace("VoidAsync");
     return(ApiResultHelper.Succees());
 }
Ejemplo n.º 17
0
        protected virtual ServiceResponseModel CreateResponse(ExecutionResult result, Action <ServiceResponseModel> builder)
        {
            var serviceResponseModel = ApiResultHelper.CreateResponse(result);

            ModelStateToResponse(serviceResponseModel);
            builder?.Invoke(serviceResponseModel);
            return(serviceResponseModel);
        }
Ejemplo n.º 18
0
        public async Task <ApiResult> FindCounselor([FromServices] IMapper iMapper)
        {
            var Counselor = await _iCounselorInfoService.QueryAsync();

            var counselorDTO = iMapper.Map <CounselorDTO>(Counselor);

            return(ApiResultHelper.Success(counselorDTO));
        }
Ejemplo n.º 19
0
        public async Task <ApiResult> Find([FromServices] IMapper iMapper)
        {
            int id    = Convert.ToInt32(this.User.FindFirst("Id").Value);
            var admin = await _iAdminInfoService.FindAsync(id);

            var adminDTO = iMapper.Map <AdminDTO>(admin);

            return(ApiResultHelper.Success(adminDTO));
        }
Ejemplo n.º 20
0
        public async Task <ApiResult> Find([FromServices] IMapper iMapper)
        {
            int id        = Convert.ToInt32(this.User.FindFirst("Id").Value);
            var Counselor = await _iCounselorInfoService.FindAsync(id);

            var counselorDTO = iMapper.Map <CounselorDTO>(Counselor);

            return(ApiResultHelper.Success(counselorDTO));
        }
Ejemplo n.º 21
0
        public async Task <ApiResult> Types()
        {
            var types = await _iTypeInfoService.QueryAsync();

            if (types.Count == 0)
            {
                return(ApiResultHelper.Error("没有更多的类型"));
            }
            return(ApiResultHelper.Success(types));
        }
Ejemplo n.º 22
0
 /// <summary>
 ///     数据校验
 /// </summary>
 /// <param name="message">status</param>
 /// <returns>成功则返回真</returns>
 public bool Validate(out IOperatorStatus status)
 {
     if (Value == null)
     {
         status = ApiResultHelper.State(OperatorStatusCode.ArgumentError, "参数不能为空");
         return(false);
     }
     status = null;
     return(true);
 }
Ejemplo n.º 23
0
        public Task <IApiResult <string> > Error()
        {
            logger.LogInformation($"Call {nameof(Error)}");
            var res = ApiResultHelper.State <string>(1);

            res = ApiResultHelper.State <string>(1, "测试失败");
            res = ApiResultHelper.State <string>(1, "测试失败", "内部信息");
            res = ApiResultHelper.State <string>(1, "测试失败", "内部信息", "这是测试", "没有解释");
            return(Task.FromResult(res));
        }
Ejemplo n.º 24
0
        public async Task <ActionResult <ApiResult> > Delete(int id)
        {
            bool b = await _iBlogNewsService.DeleteAsync(id);

            if (!b)
            {
                return(ApiResultHelper.Error("删除失败"));
            }
            return(ApiResultHelper.Success(b));
        }
Ejemplo n.º 25
0
        public async Task <ApiResult> Detele(int id)
        {
            bool b = await _iRoadInfoService.DeleteAsync(id);

            if (!b)
            {
                return(ApiResultHelper.Error("删除失败"));
            }
            return(ApiResultHelper.Success(b));
        }
Ejemplo n.º 26
0
        protected virtual ServiceResponseModel <TModel> CreateResponse <TModel>(ExecutionResult result, Action <ServiceResponseModel <TModel> > builder)
        {
            var serviceResponseModel = ApiResultHelper.CreateResponse <TModel>(result);

            ModelStateToResponse(serviceResponseModel);
            if (builder != null)
            {
                builder(serviceResponseModel);
            }
            return(serviceResponseModel);
        }
Ejemplo n.º 27
0
        public async Task <ActionResult <ApiResult> > GetBlogNews()
        {
            int id   = Convert.ToInt32(this.User.FindFirst("Id").Value);
            var data = await _iBlogNewsService.QueryAsync(c => c.WriterId == id);

            if (data == null)
            {
                return(ApiResultHelper.Error("没有更多的文章"));
            }
            return(ApiResultHelper.Success(data));
        }
Ejemplo n.º 28
0
        public async Task <ApiResult> Find()
        {
            int id   = Convert.ToInt32(this.User.FindFirst("Id").Value);
            var data = await _iRoadInfoService.QueryAsync(c => c.CounselorId == id);

            if (data.Count == 0)
            {
                return(ApiResultHelper.Error("没有更多的数据"));
            }
            return(ApiResultHelper.Success(data));
        }
Ejemplo n.º 29
0
        public async Task <ApiResult> GetNoticeInfo()
        {
            //int id = Convert.ToInt32(this.User.FindFirst("Id").Value);
            var data = await _iNoticeInfoService.QueryAsync();

            if (data.Count == 0)
            {
                return(ApiResultHelper.Error("没有更多数据"));
            }
            return(ApiResultHelper.Success(data));
        }
Ejemplo n.º 30
0
        public IApiResult Validate(IdsArguent arg)
        {
            if (!RequestArgumentConvert.TryGetIDs("selects", Convert, out List <TPrimaryKey> ids))
            {
                return(ApiResultHelper.Helper.ArgumentError);
            }

            DoValidate(ids);
            return(IsFailed
                    ? ApiResultHelper.State(GlobalContext.Current.Status.LastState, GlobalContext.Current.Status.LastMessage)
                    : ApiResultHelper.Succees());
        }