示例#1
0
        public async Task <IActionResult> ExportAsync([FromBody] SearchModel model)
        {
            try
            {
                if (model == null)
                {
                    var errorMessage = "Incorrect data";
                    Log.Error(errorMessage);

                    return(StatusCode(422, new ResultModel
                    {
                        is_successed = false,
                        error = errorMessage
                    }));
                }

                var fileContent = await _importExportService.CsvExportAsync(SearchModel.ToDto(model)).ConfigureAwait(false);

                var fileName = $"citizens_{DateTime.UtcNow.ToString("yyyy-MM-dd_HH_mm_ss")}.csv";

                return(File(fileContent, "text/csv", fileName));
            }
            catch (Exception ex)
            {
                Log.Error(ex, string.Empty);
                return(StatusCode(500, new ResultModel {
                    error = ex.Message
                }));
            }
        }