public List <DocumentRequisite> GetFilesInList(int id, [FromUri] List <int> types) { var documentReqList = ArchiveManager.GetFilesFromList(id); if (types != null && types.Count() > 0) { return((from r in documentReqList where types.Contains((int)r.type) select r).ToList()); } return(documentReqList); }
public List <DocumentRequisite> GetDocuments(int auctionId) { var auction = DataManager.GetAuction(auctionId); if (auction == null || auction.CustomerId != CurrentUser.CustomerId) { throw new AltaHttpResponseException(System.Net.HttpStatusCode.Forbidden, "Not found auction"); } var documents = ArchiveManager.GetFilesFromList(auction.FilesListId); return(documents); }
public List <DocumentRequisite> getDocuments(int auctionId) { var supplierOrder = DataManager.GetSupplierOrder(auctionId, CurrentUser.SupplierId); if (supplierOrder == null) { return(new List <DocumentRequisite>()); } if (ArchiveManager == null) { throw new AltaHttpResponseException(HttpStatusCode.InternalServerError, "Not connection to archive manager."); } return(ArchiveManager.GetFilesFromList((int)supplierOrder.fileListId)); }
public HttpStatusCode RemoveDocument(int documentId) { var company = DataManager.GetCompany(CurrentUser.CompanyId); if (company == null) { throw new AltaHttpResponseException(HttpStatusCode.InternalServerError, "Not found \"company\"."); } var documentList = ArchiveManager.GetFilesFromList(company.filesListId); if (!documentList.Any(d => d.id == documentId)) { throw new AltaHttpResponseException(HttpStatusCode.NotFound, "Not found document in list company"); } return(DataManager.RemoveDocumentInList(company.filesListId, documentId) ? HttpStatusCode.OK : HttpStatusCode.InternalServerError); }
public HttpResponseMessage DonwloadZip([FromUri] List <int> list, [FromUri] List <int> docsType) { if ((list == null && (list.Count == 0 || list.Count > MAX_FILE_LIST_UPDALODED)) && (docsType == null && docsType.Count == 0)) { return(Request.CreateResponse(HttpStatusCode.BadRequest)); } var tempFolderArchive = HttpContext.Current.Server.MapPath(string.Format("~/App_Data/{0}", Guid.NewGuid())); var zipFileName = string.Format("{0}.zip", tempFolderArchive); var acrhive = new ArchiveManager(DataManager); int countFilesFound = 0; foreach (int listId in list) { var descriptionList = ArchiveManager.GetFileListDescription(listId); if (string.IsNullOrEmpty(descriptionList)) { descriptionList = string.Format("Папка № {0}", listId); } var files = ArchiveManager.GetFilesFromList(listId); foreach (var docReq in files) { if (!docsType.Any(d => d == (int)docReq.type)) { continue; } using (var file = ArchiveManager.GetDocument(docReq)) { if (file == null) { continue; } var dir = Directory.CreateDirectory(string.Format("{0}/{1}", tempFolderArchive, descriptionList.Replace("/", "_"))); if (dir != null) { using (var f = File.Open(string.Format("{0}/{1}", dir.FullName, docReq.fileName.Replace("/", "_")), FileMode.Create)) { file.CopyTo(f); countFilesFound++; } } } } } if (countFilesFound == 0) { return(new HttpResponseMessage(HttpStatusCode.NotFound)); } ZipFile.CreateFromDirectory(tempFolderArchive, zipFileName); var result = new HttpResponseMessage(HttpStatusCode.OK); Stream stream = File.OpenRead(zipFileName); result.Content = new StreamContent(stream); result.Content.Headers.ContentDisposition = new ContentDispositionHeaderValue("attachment"); result.Content.Headers.ContentDisposition.FileNameStar = string.Format("Архив файлов({0}).zip", DateTime.Now.ToShortDateString()); result.Content.Headers.ContentType = new MediaTypeHeaderValue("application/octet-stream"); result.Content.Headers.ContentType.CharSet = "UTF-8"; result.Content.Headers.ContentLength = stream.Length; Directory.Delete(tempFolderArchive, true); tempArhiveFiles.Add(zipFileName); return(result); }