Exemple #1
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="context"></param>
        /// <param name="next"></param>
        /// <returns></returns>
        public async Task InvokeAsync(HttpContext context, RequestDelegate next)
        {
            if (context.Request.Query.TryGetValue("level", out var _level) &&
                Enum.TryParse <AdministrativeDivisionCnLevel>(_level, out var level))
            {
                var data = service.Get(level);

                await options.SerializeToResponseAsync(context.Response, data);
            }
        }
Exemple #2
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="context"></param>
        /// <param name="next"></param>
        /// <returns></returns>
        public async Task InvokeAsync(HttpContext context, RequestDelegate next)
        {
            var query = context.Request.Query;
            var code  = query.TryGetValue("code", out var _code) && long.TryParse(_code, out var __code)
                ? __code : 0;
            var level = query.TryGetValue("level", out var _level) && Enum.TryParse <AdministrativeDivisionCnLevel>(_level, out var __level)
                ? __level : (AdministrativeDivisionCnLevel)0;
            var data = service.GetChildren(code, level);

            await options.SerializeToResponseAsync(context.Response, data);
        }
Exemple #3
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="context"></param>
        /// <param name="next"></param>
        /// <returns></returns>
        public async Task InvokeAsync(HttpContext context, RequestDelegate next)
        {
            var query = context.Request.Query;

            if (query.TryGetValue("code", out var _code) && long.TryParse(_code, out var code))
            {
                var ignoreNoName = bool.TryParse(query["ignoreNoName"], out var _absolutely) ? _absolutely : true;
                var trimSuffix   = bool.TryParse(query["trimSuffix"], out var _trimSuffix) ? _trimSuffix : true;
                var display      = service.Display(code, ignoreNoName, trimSuffix);

                await options.SerializeToResponseAsync(context.Response, display);
            }
        }