protected void gvDocuments_RowCommand(object sender, GridViewCommandEventArgs e) { CarrierDocument document = null; string appPath = ConfigurationManager.AppSettings["appPath"].ToString(); int documentID = Convert.ToInt32(e.CommandArgument); if (e.CommandName == "DoDelete") { document = CarrierDocumentManager.Get(documentID); if (document != null) { string documentPath = string.Format("{0}/CarrierDocuments/{1}/{2}", appPath, document.CarrierID, document.DocumentName); if (File.Exists(documentPath)) { File.Delete(documentPath); } CarrierDocumentManager.Delete(documentID); bindData(carrierID); } } }
public static CarrierDocument Get(int id) { CarrierDocument document = null; document = (from x in DbContextHelper.DbContext.CarrierDocument where x.CarrierDocumentID == id select x).FirstOrDefault <CarrierDocument>(); return(document); }
public static CarrierDocument Save(CarrierDocument document) { if (document.CarrierDocumentID == 0) { DbContextHelper.DbContext.Add(document); } DbContextHelper.DbContext.SaveChanges(); return(document); }
public static void Delete(int id) { // Create an entity to represent the Entity you wish to delete // Notice you don't need to know all the properties, in this // case just the ID will do. CarrierDocument document = Get(id); if (document != null) { // Do the delete the category DbContextHelper.DbContext.DeleteObject(document); // Apply the delete to the database DbContextHelper.DbContext.SaveChanges(); } }
public static void saveFile(int carrierID, string filePath, string documentDescription) { string carrierDocumentPath = null; string destinationFilePath = null; CarrierDocument document = null; // get application path string appPath = ConfigurationManager.AppSettings["appPath"].ToString(); // get file from temp folder string tempFilePath = HttpContext.Current.Server.MapPath(String.Format("~\\Temp\\{0}", filePath)); if (carrierID > 0 && File.Exists(tempFilePath)) { try { using (TransactionScope scope = new TransactionScope()) { document = new CarrierDocument(); document.CarrierID = carrierID; document.DocumentName = filePath; document.DocumentDescription = documentDescription; document.DocumentDate = DateTime.Now; CarrierDocumentManager.Save(document); carrierDocumentPath = string.Format("{0}/CarrierDocuments/{1}", appPath, carrierID); if (!Directory.Exists(carrierDocumentPath)) { Directory.CreateDirectory(carrierDocumentPath); } destinationFilePath = string.Format("{0}/CarrierDocuments/{1}/{2}", appPath, carrierID, filePath); System.IO.File.Copy(tempFilePath, destinationFilePath, true); // delete temp file File.Delete(tempFilePath); scope.Complete(); } } catch (Exception ex) { Core.EmailHelper.emailError(ex); } finally { } } }
public static void saveFile(int carrierID, string filePath, string documentDescription) { string carrierDocumentPath = null; string destinationFilePath = null; CarrierDocument document = null; // get application path string appPath = ConfigurationManager.AppSettings["appPath"].ToString(); // get file from temp folder string tempFilePath = HttpContext.Current.Server.MapPath(String.Format("~\\Temp\\{0}", filePath)); if (carrierID > 0 && File.Exists(tempFilePath)) { try { using (TransactionScope scope = new TransactionScope()) { document = new CarrierDocument(); document.CarrierID = carrierID; document.DocumentName = filePath; document.DocumentDescription = documentDescription; document.DocumentDate = DateTime.Now; CarrierDocumentManager.Save(document); carrierDocumentPath = string.Format("{0}/CarrierDocuments/{1}", appPath, carrierID); if (!Directory.Exists(carrierDocumentPath)) Directory.CreateDirectory(carrierDocumentPath); destinationFilePath = string.Format("{0}/CarrierDocuments/{1}/{2}", appPath, carrierID, filePath); System.IO.File.Copy(tempFilePath, destinationFilePath, true); // delete temp file File.Delete(tempFilePath); scope.Complete(); } } catch (Exception ex) { Core.EmailHelper.emailError(ex); } finally { } } }
protected void gvDocuments_RowDataBound(object sender, GridViewRowEventArgs e) { CarrierDocument document = null; // get application path string appPath = ConfigurationManager.AppSettings["appPath"].ToString(); string appUrl = ConfigurationManager.AppSettings["appURL"].ToString(); if (e.Row.RowType == DataControlRowType.DataRow) { HyperLink hlnkDocument = e.Row.FindControl("hlnkDocument") as HyperLink; document = e.Row.DataItem as CarrierDocument; if (document != null) { string documentPath = string.Format("{0}/CarrierDocuments/{1}/{2}", appPath, document.CarrierID, document.DocumentName); if (File.Exists(documentPath)) { hlnkDocument.NavigateUrl = string.Format("{0}/CarrierDocuments/{1}/{2}", appUrl, document.CarrierID, document.DocumentName); } } } }