public List <Entities.File> GetAll(int userId, int parentFolderId = -1) { FileDAO fileDAO = new FileDAO(); var files = fileDAO.GetAll(); var activeAndRootFiles = (from file in files where file.IsActive == true && file.ParenFolderId == parentFolderId && file.CreatedBy == userId select file).ToList <Entities.File>(); return(activeAndRootFiles); }
public void Delete(int id) { FolderDAO dao = new FolderDAO(); var folder = dao.GetById(id); folder.IsActive = false; folder.Update(); FileDAO fileDAO = new FileDAO(); var allfiles = fileDAO.GetAll(); var files = (from file in allfiles where file.ParenFolderId == id select file).ToList <Entities.File>(); foreach (var file in files) { file.IsActive = false; file.Update(); } }
public void GetAll__WithNoRows__ReturnsListOfZero() { var list = dao.GetAll(); Assert.AreEqual(list.Count, 0); }
public Object DownloadMeta(int id, int userid) { FolderDAO folderDAO = new FolderDAO(); FileDAO fileDAO = new FileDAO(); var allfolders = folderDAO.GetAll(); var folders = (from folder in allfolders where folder.CreatedBy == userid select folder).ToList(); var allfiles = fileDAO.GetAll(); var files = (from file in allfiles where file.CreatedBy == userid select file).ToList(); Folder currentFolder = null; if (id == -1) { currentFolder = new Folder(); currentFolder.Id = -1; } else { currentFolder = (from folder in folders where folder.Id == id select folder).FirstOrDefault(); if (currentFolder == null) { return(new HttpResponseMessage(HttpStatusCode.NotFound));; } } Document document = new Document(); Section section = document.AddSection(); TraverseFolders(currentFolder, ref folders, ref files, ref section); PdfDocumentRenderer pdf = new PdfDocumentRenderer(false, PdfSharp.Pdf.PdfFontEmbedding.Always); pdf.Document = document; pdf.RenderDocument(); var rootPath = HttpContext.Current.Server.MapPath("~/UploadedFiles"); var uid = Guid.NewGuid() + ".pdf"; var fileSavePath = Path.Combine(rootPath, uid); pdf.PdfDocument.Save(fileSavePath); HttpResponseMessage resp = new HttpResponseMessage(HttpStatusCode.OK); byte[] fileStream = System.IO.File.ReadAllBytes(fileSavePath); System.IO.File.Delete(fileSavePath); System.IO.MemoryStream ms = new MemoryStream(fileStream); resp.Content = new ByteArrayContent(fileStream); resp.Content.Headers.ContentDisposition = new System.Net.Http.Headers.ContentDispositionHeaderValue("attachment"); var type = MimeTypeMap.GetMimeType(".pdf"); resp.Content.Headers.ContentType = new System.Net.Http.Headers.MediaTypeHeaderValue(type); resp.Content.Headers.ContentDisposition.FileName = "meta-data.pdf"; return(resp); }