//save a new shipment_note public shipment_attachment saveShipentFile(shipment_attachment model) { var file = new shipment_attachment(); try { using (var ctx = new transshipEntities()) { file = ctx.shipment_attachment.Add(model); ctx.SaveChanges(); return(file); } } catch (Exception e) { LogBook.TextLog.Info(string.Format("{0} {1}", e.Message, e.InnerException != null ? e.InnerException.Message : string.Empty)); throw e; } }
public shipment_attachment saveShipmentFile(shipment_attachment model) { return(file.saveShipentFile(model)); }
public HttpResponseMessage UploadFile() { var filePath = "~/shipmentUpload/"; shipment_attachment shipfile = new shipment_attachment(); shipment_attachment shipmentFile; BOShipmentFiles fileShip = new BOShipmentFiles(); var file = HttpContext.Current.Request.Files.AllKeys.Any(); //get paramaetes shipment files var shipmentId = HttpContext.Current.Request.Params["model.shipmentId"]; var file_typeId = HttpContext.Current.Request.Params["model.file_typeId"]; var userId = HttpContext.Current.Request.Params["model.userId"]; var description = HttpContext.Current.Request.Params["model.description"]; var customerId = HttpContext.Current.Request.Params["model.customerId"]; //var file_name = HttpContext.Current.Request.Params["model.file_name"]; try { if (HttpContext.Current.Request.Files.AllKeys.Any()) { // Get the uploaded image from the Files collection var httpPostedFile = HttpContext.Current.Request.Files["UploadedFile"]; if (httpPostedFile != null) { var file_name = httpPostedFile.FileName; // Get the complete file path string fileSave = DateTime.Now.ToString("yyyyMMddHHmmss") + file_name; // if the \pix directory doesn't exist - create it. if (!Directory.Exists(HttpContext.Current.Server.MapPath(filePath + "/" + customerId))) { Directory.CreateDirectory(HttpContext.Current.Server.MapPath(filePath + "/" + customerId)); } if (!Directory.Exists(HttpContext.Current.Server.MapPath(filePath + "/" + customerId + "/" + shipmentId))) { Directory.CreateDirectory(HttpContext.Current.Server.MapPath(filePath + "/" + customerId + "/" + shipmentId)); string path = filePath + "/" + customerId + "/" + shipmentId + "/" + fileSave; httpPostedFile.SaveAs(HttpContext.Current.Server.MapPath(path)); } else { string path = filePath + "/" + customerId + "/" + shipmentId + "/" + fileSave; httpPostedFile.SaveAs(HttpContext.Current.Server.MapPath(path)); } //var fileSavePath = Path.Combine(HttpContext.Current.Server.MapPath("~/shipmentUpload"),httpPostedFile.FileName); // Save the uploaded file to "UploadedFiles" folder //httpPostedFile.SaveAs(fileSavePath); shipfile.file_name = fileSave; } //map de parametes to model shipment attachment shipfile.shipmentId = Convert.ToDecimal(shipmentId); shipfile.userId = Convert.ToDecimal(userId); shipfile.file_typeId = Convert.ToDecimal(file_typeId); shipfile.description = description; shipfile.creation_date = DateTime.Today; } shipmentFile = fileShip.saveShipmentFile(shipfile); return(Request.CreateResponse(HttpStatusCode.OK, shipmentFile)); } catch (Exception e) { ErrorMessage mensaje = new ErrorMessage("2.1", "Exception to save shipment file - " + e.GetBaseException().Message, e.ToString()); return(Request.CreateResponse(HttpStatusCode.InternalServerError, mensaje)); } }