コード例 #1
0
        public async Task <ActionResult <RpGetCitizens> > GetCitizens([FromBody] RqGetCitizens rqGetCitizens)
        {
            try
            {
                if (!string.IsNullOrEmpty(rqGetCitizens.SearchRequest.Inn) && !ValidationsCollection.Validations.IsValidInnForIndividual(rqGetCitizens.SearchRequest.Inn))
                {
                    return(Json(ResponseHelper.ReturnBadRequest("Inn not valid")));
                }

                if (!string.IsNullOrEmpty(rqGetCitizens.SearchRequest.Snils) && !ValidationsCollection.Validations.IsValidSnils(StringConverter.GetNumbers(rqGetCitizens.SearchRequest.Snils)))
                {
                    return(Json(ResponseHelper.ReturnBadRequest("Snils not valid")));
                }

                var searchRequestParsed = new SearchRequestParsed();
                try
                {
                    searchRequestParsed = CitizenConverter.FromSearchRequestToSearchRequestParsed(rqGetCitizens.SearchRequest);
                }
                catch (Exception exception)
                {
                    LoggerStatic.Logger.Warn("Exception: " + exception);
                    return(Json(ResponseHelper.ReturnBadRequest(exception.Message)));
                }

                var rpGetCitizens = new RpGetCitizens
                {
                    Citizens = await _peopleService.GetCitizens(searchRequestParsed)
                };
                //return Json(rpGetCitizens);
                return(ControllersHelper.ReturnContentResult(SerializerJson.SerializeObjectToJsonString(rpGetCitizens)));
            }
            catch (Exception exception)
            {
                LoggerStatic.Logger.Error("Exception: " + exception);
                return(Json(ResponseHelper.ReturnInternalServerError(exception.Message)));
            }
        }
コード例 #2
0
        public async Task <FileContentResult> ExportCsv([FromBody] RqGetCitizens rqGetCitizens)
        {
            try
            {
                if (!string.IsNullOrEmpty(rqGetCitizens.SearchRequest.Inn) && !ValidationsCollection.Validations.IsValidInnForIndividual(rqGetCitizens.SearchRequest.Inn))
                {
                    return(File(new UTF8Encoding().GetBytes($"Exception: Inn not valid)"), "text/csv", "exception.txt"));
                }

                if (!string.IsNullOrEmpty(rqGetCitizens.SearchRequest.Snils) && !ValidationsCollection.Validations.IsValidSnils(StringConverter.GetNumbers(rqGetCitizens.SearchRequest.Snils)))
                {
                    return(File(new UTF8Encoding().GetBytes($"Exception: Snils not valid)"), "text/csv", "exception.txt"));
                }

                var searchRequestParsed = new SearchRequestParsed();
                try
                {
                    searchRequestParsed = CitizenConverter.FromSearchRequestToSearchRequestParsed(rqGetCitizens.SearchRequest);
                }
                catch (Exception exception)
                {
                    LoggerStatic.Logger.Warn("Exception: " + exception);
                    return(File(new UTF8Encoding().GetBytes($"Exception: {exception})"), "text/csv", "exception.txt"));
                }

                var citizens = await _peopleService.GetCitizens(searchRequestParsed);

                var csvBytes = await _peopleService.GetCsvResult(citizens);

                return(File(csvBytes, "text/csv", $"Citizens-{DateTime.Now:yyyy-MM-dd-H-mm-ss}.csv"));
            }
            catch (Exception exception)
            {
                LoggerStatic.Logger.Error("Exception: " + exception);
                return(File(new System.Text.UTF8Encoding().GetBytes($"Exception: {exception}"), "text/csv", "exception.txt"));
            }
        }