public IHttpActionResult PrintLabel(TradelanePrintLabel PrintLabelObj) { var Tradelaneshipment = new TradelaneBookingRepository().GetTradelaneDetail(PrintLabelObj); if (PrintLabelObj.CartonList != null && Tradelaneshipment != null && Tradelaneshipment.TradelaneShipmentId > 0) { var ShipmentDetail = new TradelaneBookingRepository().GetTradelaneBookingDetails(Tradelaneshipment.TradelaneShipmentId, ""); var HawbCount = ShipmentDetail.HAWBPackages.Where(a => a.HAWB == PrintLabelObj.Hawb).FirstOrDefault().PackagesCount; var Result = new TradelaneBookingRepository().HawbUpdate(ShipmentDetail, PrintLabelObj); var Files = new TradelaneDocument().ShipmentCartonLabel(Tradelaneshipment.TradelaneShipmentId, HawbCount, Tradelaneshipment.TradelaneShipmentDetailId, PrintLabelObj.Hawb); TradelanePrintLabelResponseModel model = new TradelanePrintLabelResponseModel(); string filePhysicalPath = string.Empty; model.FileName = Files != null && Files.FileName != null ? Files.FileName : ""; model.FileExtension = ".png"; filePhysicalPath = HttpContext.Current.Server.MapPath("~/UploadFiles/Tradelane/" + Tradelaneshipment.TradelaneShipmentId + "/" + Files.FileName); using (MemoryStream ms = new MemoryStream()) { using (FileStream file = new FileStream(filePhysicalPath, FileMode.Open, FileAccess.Read)) { byte[] bytes = new byte[file.Length]; file.Read(bytes, 0, (int)file.Length); ms.Write(bytes, 0, (int)file.Length); //string test = ms.ToString(); //StreamReader sr = new StreamReader(filePhysicalPath); //string tsd = sr.ReadToEnd(); //var res = File.ReadAllBytes(filePhysicalPath); //string result = System.Text.Encoding.UTF8.GetString(res); HttpResponseMessage httpResponseMessage = new HttpResponseMessage(); httpResponseMessage.Content = new ByteArrayContent(bytes); httpResponseMessage.Content.Headers.Add("download-status", "downloaded"); httpResponseMessage.Content.Headers.Add("x-filename", model.FileName); httpResponseMessage.Content.Headers.ContentType = new MediaTypeHeaderValue("application/octet-stream"); httpResponseMessage.Content.Headers.ContentDisposition = new ContentDispositionHeaderValue("attachment"); httpResponseMessage.Content.Headers.ContentDisposition.FileName = model.FileName; httpResponseMessage.StatusCode = HttpStatusCode.OK; model.ByteArray = httpResponseMessage; } } return(Ok(model)); } else { return(BadRequest()); } }
public IHttpActionResult PrintLabelWithPath(TradelanePrintLabel PrintLabelObj) { var Tradelaneshipment = new TradelaneBookingRepository().GetTradelaneDetail(PrintLabelObj); if (PrintLabelObj.CartonList != null && Tradelaneshipment != null && Tradelaneshipment.TradelaneShipmentId > 0) { var ShipmentDetail = new TradelaneBookingRepository().GetTradelaneBookingDetails(Tradelaneshipment.TradelaneShipmentId, ""); var HawbCount = ShipmentDetail.HAWBPackages.Where(a => a.HAWB == PrintLabelObj.Hawb).FirstOrDefault().TotalCartons; var Result = new TradelaneBookingRepository().HawbUpdate(ShipmentDetail, PrintLabelObj); var Files = new TradelaneDocument().ShipmentCartonLabel(Tradelaneshipment.TradelaneShipmentId, HawbCount, Tradelaneshipment.TradelaneShipmentDetailId, PrintLabelObj.Hawb); TradelanePrintLabelResponseModel model = new TradelanePrintLabelResponseModel(); string filePhysicalPath = string.Empty; model.FileName = Files != null && Files.FileName != null ? Files.FileName : ""; model.FileExtension = ".jpeg"; // AppSettings.WebApiPath + "UploadFiles\\Tradelane\\ model.FilePath = AppSettings.WebApiPath + "UploadFiles\\Tradelane\\" + Tradelaneshipment.TradelaneShipmentId + "/" + Files.FileName; return(Ok(model)); } else { return(BadRequest()); } }