public ActionResult _AddEditDocumentPrePO(Int32 PrePurcherseOrderId, Int32?FatherId) { var model = new _AddEditDocumentPrePOViewModel(); model.Fill(CargarDatosContext(), PrePurcherseOrderId, FatherId); return(View(model)); }
public ActionResult _AddEditDocumentPrePO(_AddEditDocumentPrePOViewModel model) { try { PrePurcherseOrder prePurcherseOrder = context.PrePurcherseOrder.FirstOrDefault(x => x.PrePurcherseOrderId == model.PrePurcherseOrderId); if (prePurcherseOrder != null) { byte[] data; using (Stream inputStream = model.File.InputStream) { MemoryStream memoryStream = inputStream as MemoryStream; if (memoryStream == null) { memoryStream = new MemoryStream(); inputStream.CopyTo(memoryStream); } data = memoryStream.ToArray(); } prePurcherseOrder.DocumentContentType = model.File.ContentType; prePurcherseOrder.DocumentName = model.DocumentName; prePurcherseOrder.DocumentPath = data; prePurcherseOrder.DocumentExtension = Path.GetExtension(model.File.FileName); context.SaveChanges(); PostMessage(MessageType.Success); } else { PostMessage(MessageType.Error); } } catch (Exception ex) { PostMessage(MessageType.Error); } return(RedirectToAction("ListPrePO", new { FatherId = model.FatherId })); }