public static void Insert(MissionDocumentAppendix model) { using (var context = new UpsilabEntities()) { model.DateCreated = DateTime.Now; context.MissionDocumentAppendix.AddObject(model); context.SaveChanges(); } }
public JsonResult UploadPjDocumentAnnexe() { var res = string.Empty; var lst = new List<MissionDocumentAppendix>(); Guid idMissionDocument = Guid.Empty; try { var customerId = GetTargetCustomer(); if (customerId.HasValue && Request.Form.Count > 0 && Request.Files.Count > 0) { var docType = DocumentTypeBL.GetDocumentTypeByCode("AX"); CustomerProspect customer = CustomerProspectBL.GetCustomerProspectById(customerId.Value); if (customer != null) { HttpPostedFileBase file = Request.Files[0]; string designation = Request.Form[0]; int idDocument = int.Parse(Request.Form[1].ToString()); idMissionDocument = new Guid(Request.Form[2].ToString()); var model = new MissionDocumentAppendix() { idMissionDocumentAppendix = Guid.NewGuid(), Designation = designation, idDocumentCategory = idDocument, idMissionDocument = idMissionDocument }; var documentPath = ElectronicSafeDocumentBL.BuildClientUploadDocumentPath(docType.DocumentNamePrefix, customer); string filename = ElectronicSafeDocumentBL.BuildDocumentName(docType.DocumentNamePrefix, (Guid)customerId, file.FileName); // 1- Sauvegarde dans le repertoire string filePath = System.IO.Path.Combine(documentPath, filename); file.SaveAs(filePath); string userPath = ElectronicSafeDocumentBL.BuildDocumentPath(docType.DocumentNamePrefix, customer, null, null, true); string relativePath = string.Format("/uploads/{0}/{1}", userPath, filename); relativePath = relativePath.Replace(@"\", "/"); model.Filename = relativePath; MissionDocumentAppendixBL.Insert(model); } } } catch (Exception ex) { res = ex.Message; } if (idMissionDocument != Guid.Empty) { lst = (List<MissionDocumentAppendix>)MissionDocumentAppendixBL.GetMissionDocumentAppendixByMissionDocument(idMissionDocument); } var result = new { Result = idMissionDocument.ToString() }; return Json(result, JsonRequestBehavior.AllowGet); //return PartialView("MissionDocumentAppendixListPartial", lst); }