public async Task <IActionResult> SaveDateUpdate() { try { string controlMessage; if (NewDateUpdate != null) { using var fs = new FileStream("lastdateupdate.json", FileMode.OpenOrCreate); await JsonSerializer.SerializeAsync(fs, NewDateUpdate); controlMessage = $"Дата обновления реестра '{NewDateUpdate}' сохранена в файле 'lastdateupdate.json'"; } else { controlMessage = "Загрузите реестр препаратов"; } return(new JsonResult(new { message = controlMessage }) { StatusCode = 200 }); } catch (Exception e) { return(new JsonResult(new { message = e.Message }) { StatusCode = 500 }); } }
public async Task <IActionResult> GenerateInvoice([Required][FromBody] GetInvoiceRequest request) { Invoice invoice; try { invoice = await _equipmentService.GenerateInvoice(request.Equipment); } catch (Exception e) { _logger.LogError(e, "Exception occured while generating invoice"); return(RedirectError("Exception occured while generating invoice. Please try again later")); } _logger.LogInformation($"Sending invoice: {JsonConvert.SerializeObject(invoice)}"); var stream = new MemoryStream(); await JsonSerializer.SerializeAsync(stream, invoice); var cd = new ContentDisposition { FileName = invoice.Title, Inline = true }; Response?.Headers?.Add("Content-Disposition", cd.ToString()); stream.Seek(0, 0); return(new FileStreamResult(stream, "application/octet-stream")); }
public static async Task <Stream> CreateStreamForRequest(TestLambdaMessage request) { var stream = new MemoryStream(); await SystemTextJsonSerializer.SerializeAsync(stream, request); stream.Position = 0; return(stream); }