public ActionResult AddComment(int docId) { using (var db = new DocumentDbContext()) { Models.DocumentData.Document document = db.Documents.Where(x => x.DocumentId == docId).First(); return(View(document)); } }
public ActionResult MakeActive(int docId) { //4 status wydana na linie using (var db = new DocumentDbContext()) { var DocExcel = db.Documents.Where(x => x.DocumentId == docId).First().DocumentFileExcel; string pathUser = Environment.GetFolderPath(Environment.SpecialFolder.UserProfile); string pathDownload = Path.Combine(pathUser, "Downloads"); string title = "temp" + DateTime.Now; title = title.Replace("-", ""); title = title.Replace(":", ""); string title2 = "temp" + ".pdf"; string EndPathPDF = Path.Combine(pathDownload, title2); string EndPath = Path.Combine(pathDownload, title); int VersionCurrent = db.Documents.Where(x => x.DocumentId == docId).First().Version; int VersionPrevious = VersionCurrent - 1; if (VersionCurrent > 1) { string index = db.Documents.Where(x => x.DocumentId == docId).First().Index; Models.DocumentData.Document DocumentToArchive = db.Documents.Where(x => x.Index == index).Where(x => x.Version == VersionPrevious).First(); DocumentToArchive.Status = db.Status.Where(x => x.StatusId == 5).First(); db.SaveChanges(); } //stworzenie tablicy wielkosci System.IO.File.WriteAllBytes(EndPath, DocExcel); MyApp = new Microsoft.Office.Interop.Excel.Application(); MyApp.Visible = false; MyBook = MyApp.Workbooks.Open(EndPath); MyWorkSheet = (Microsoft.Office.Interop.Excel.Worksheet)MyBook.Sheets[1]; MyWorkSheet.Cells[3, 13] = DateTime.Now.ToShortDateString(); MyApp.Save(); MyBook.ExportAsFixedFormat(XlFixedFormatType.xlTypePDF, EndPathPDF); MyBook.Close(); byte[] f1 = new byte[15728640]; f1 = System.IO.File.ReadAllBytes(EndPath); byte[] fPDF = new byte[15728640]; fPDF = System.IO.File.ReadAllBytes(EndPathPDF); //zamiana indeksu z 4 na 5 w poprzedniej wersji db.Documents.Where(x => x.DocumentId == docId).First().DocumentFile = fPDF; db.Documents.Where(x => x.DocumentId == docId).First().DocumentFileExcel = f1; db.Documents.Where(x => x.DocumentId == docId).First().Status = db.Status.Where(c => c.StatusId == 4).First(); db.Documents.Where(x => x.DocumentId == docId).First().DateOfPublic = DateTime.Today; db.SaveChanges(); if (System.IO.File.Exists(EndPathPDF)) { System.IO.File.Delete(EndPathPDF); } if (System.IO.File.Exists(EndPath)) { System.IO.File.Delete(EndPath); } } return(RedirectToAction("Index")); }