public void shouldSuccessPDFTemplateWithCurrencyIDR()
        {
            GarmentFinanceMemorialPDFTemplate PdfTemplate = new GarmentFinanceMemorialPDFTemplate();
            MemoryStream result = PdfTemplate.GeneratePdfTemplate(viewModel, 7);

            Assert.NotNull(result);
        }
Beispiel #2
0
        public async Task <IActionResult> GetById([FromRoute] int id)
        {
            try
            {
                var indexAcceptPdf = Request.Headers["Accept"].ToList().IndexOf("application/pdf");
                var model          = await Service.ReadByIdAsync(id);

                GarmentFinanceMemorialViewModel viewModel = Mapper.Map <GarmentFinanceMemorialViewModel>(model);

                if (model == null)
                {
                    Dictionary <string, object> Result =
                        new ResultFormatter(ApiVersion, General.NOT_FOUND_STATUS_CODE, General.NOT_FOUND_MESSAGE)
                        .Fail();
                    return(NotFound(Result));
                }

                if (indexAcceptPdf < 0)
                {
                    return(Ok(new
                    {
                        apiVersion = ApiVersion,
                        data = viewModel,
                        message = General.OK_MESSAGE,
                        statusCode = General.OK_STATUS_CODE
                    }));
                }
                else
                {
                    int clientTimeZoneOffset = int.Parse(Request.Headers["x-timezone-offset"].First());

                    GarmentFinanceMemorialPDFTemplate PdfTemplate = new GarmentFinanceMemorialPDFTemplate();
                    MemoryStream stream = PdfTemplate.GeneratePdfTemplate(viewModel, clientTimeZoneOffset);

                    return(new FileStreamResult(stream, "application/pdf")
                    {
                        FileDownloadName = $"Memorial {viewModel.MemorialNo}.pdf"
                    });
                }
            }
            catch (Exception e)
            {
                Dictionary <string, object> Result =
                    new ResultFormatter(ApiVersion, General.INTERNAL_ERROR_STATUS_CODE, e.Message)
                    .Fail();
                return(StatusCode(General.INTERNAL_ERROR_STATUS_CODE, Result));
            }
        }