public Document GetDocumentById(int documentId) { var documents = new Document(); using (_db) { documents = _db.tblDocuments.Where(p => p.Id == documentId && p.Active == true).Select( p => new Document { DocumentId = p.Id, Name = p.Name, ServerPath = p.ServerPath, ServerName = p.ServerName, Active = true, LastUpdated = p.LastUpdated, DocumentType = new DocumentType { TypeId = p.tlbDocumentType.Id, Type = p.tlbDocumentType.Type } }).SingleOrDefault(); } return documents; }
private Document MoveFile(Document document) { var date = Convert.ToDateTime(document.DocumentDate); var serverPath = GetFileStore().Replace("\\","/") + date.Year + "/" + date.Month + "/" + date.Day + "/" + document.DocumentType.Type; var webPath = "/FileStore/" + date.Year + "/" + date.Month + "/" + date.Day + "/" + document.DocumentType.Type; var fileName = document.DocumentId + "_" + document.DocumentType.Type + Path.GetExtension(document.Name); var destFile = serverPath + "/" + fileName; var sourceFile = GetServerDriveLetter() + document.ServerPath + "/" + document.Name; if (!Directory.Exists(serverPath)) { Directory.CreateDirectory(serverPath); } File.Move(sourceFile, destFile); document.Name = fileName; document.ServerPath = webPath; return document; }
public void SaveDocument(Document document) { var d = new tblDocument(); using (_db) { d = _db.tblDocuments.SingleOrDefault(x => x.Id == document.DocumentId); d.ChartId = document.ChartId; d.Description = document.Description; d.DocumentDate = document.DocumentDate; d.LastUpdated = DateTime.Now; d.Name = document.Name; d.VisitId = document.Visit.VisitId; d.TypeId = document.DocumentType.TypeId; d.ServerPath = document.ServerPath; _db.SubmitChanges(); } }