Beispiel #1
0
        public IActionResult GetVatPDF(int id)
        {
            try
            {
                identityService.Token = Request.Headers["Authorization"].FirstOrDefault().Replace("Bearer ", "");
                var indexAcceptPdf = Request.Headers["Accept"].ToList().IndexOf("application/pdf");

                GarmentInvoice          model     = facade.ReadById(id);
                GarmentInvoiceViewModel viewModel = mapper.Map <GarmentInvoiceViewModel>(model);
                if (viewModel == null)
                {
                    throw new Exception("Invalid Id");
                }
                if (indexAcceptPdf < 0)
                {
                    return(Ok(new
                    {
                        apiVersion = ApiVersion,
                        statusCode = General.OK_STATUS_CODE,
                        message = General.OK_MESSAGE,
                        data = viewModel,
                    }));
                }
                else
                {
                    int clientTimeZoneOffset = int.Parse(Request.Headers["x-timezone-offset"].First());

                    /* tambahan */
                    /* get gsupplier */
                    string supplierUri = "master/garment-suppliers";
                    var    httpClient  = (IHttpClientService)serviceProvider.GetService(typeof(IHttpClientService));
                    var    response    = httpClient.GetAsync($"{Lib.Helpers.APIEndpoint.Core}{supplierUri}/{model.SupplierId}").Result.Content.ReadAsStringAsync();
                    Dictionary <string, object> result   = JsonConvert.DeserializeObject <Dictionary <string, object> >(response.Result);
                    SupplierViewModel           supplier = JsonConvert.DeserializeObject <SupplierViewModel>(result.GetValueOrDefault("data").ToString());
                    /* tambahan */

                    VatPDFTemplate PdfTemplateLocal = new VatPDFTemplate();
                    MemoryStream   stream           = PdfTemplateLocal.GeneratePdfTemplate(viewModel, supplier, clientTimeZoneOffset, DOfacade);

                    return(new FileStreamResult(stream, "application/pdf")
                    {
                        FileDownloadName = $"{viewModel.npn}.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));
            }
        }
Beispiel #2
0
        public IActionResult GetVatPDF(int id)
        {
            try
            {
                var indexAcceptPdf = Request.Headers["Accept"].ToList().IndexOf("application/pdf");

                GarmentInvoice          model     = facade.ReadById(id);
                GarmentInvoiceViewModel viewModel = mapper.Map <GarmentInvoiceViewModel>(model);
                if (viewModel == null)
                {
                    throw new Exception("Invalid Id");
                }
                if (indexAcceptPdf < 0)
                {
                    return(Ok(new
                    {
                        apiVersion = ApiVersion,
                        statusCode = General.OK_STATUS_CODE,
                        message = General.OK_MESSAGE,
                        data = viewModel,
                    }));
                }
                else
                {
                    int clientTimeZoneOffset = int.Parse(Request.Headers["x-timezone-offset"].First());

                    VatPDFTemplate PdfTemplateLocal = new VatPDFTemplate();
                    MemoryStream   stream           = PdfTemplateLocal.GeneratePdfTemplate(viewModel, clientTimeZoneOffset, DOfacade);

                    return(new FileStreamResult(stream, "application/pdf")
                    {
                        FileDownloadName = $"{viewModel.npn}.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));
            }
        }