public static bool DownloadDocument(DocumentView document, string saveAs)
        {
            var req    = archiveManager.GetDocumentParams(document.id);
            var result = archiveManager.GetDocument(req, saveAs);

            return(result);
        }
        //Парсин и формирование Заявки на Каспи
        private void createOrder(int[] id)
        {
            var procuratoryRequisite = ArchiveManager.GetDocumentParams(id[0]);
            var techSpecRequisite    = ArchiveManager.GetDocumentParams(id[1]);
            var procuratoryPath      = procuratoryRequisite.GenerateFilePath();
            var techSpecPath         = techSpecRequisite.GenerateFilePath();

            if (ArchiveManager.GetDocument(procuratoryRequisite, procuratoryPath) && ArchiveManager.GetDocument(techSpecRequisite, techSpecPath))
            {
                var order    = ProcuratoryWithTechSpecService.ParseKaspiProcuratory(procuratoryPath);
                var techSpec = ProcuratoryWithTechSpecService.ParseKaspiTechSpec(techSpecPath);
                order.Auction.Lots[0].LotsExtended = techSpec;
            }
            else
            {
                throw new IOException();
            }
        }
        public HttpResponseMessage GetFile(int id)
        {
            HttpResponseMessage result = null;
            var docReq = ArchiveManager.GetDocumentParams(id);

            if (docReq != null)
            {
                var f = ArchiveManager.GetDocument(docReq);
                if (f != null)
                {
                    result         = new HttpResponseMessage(HttpStatusCode.OK);
                    result.Content = new StreamContent(f);
                    result.Content.Headers.ContentDisposition = new ContentDispositionHeaderValue("attachment");
                    result.Content.Headers.ContentDisposition.FileNameStar = docReq.fileName;
                    result.Content.Headers.ContentType         = new MediaTypeHeaderValue("application/octet-stream");
                    result.Content.Headers.ContentType.CharSet = "UTF-8";
                    result.Content.Headers.ContentLength       = f.Length;
                    return(result);
                }
            }
            return(Request.CreateResponse(HttpStatusCode.NotFound));
        }
        public HttpStatusCode PutFilesInSupplierOrder(int auctionId)
        {
            if (!Request.Content.IsMimeMultipartContent())
            {
                throw new HttpResponseException(HttpStatusCode.UnsupportedMediaType);
            }

            if (ArchiveManager == null)
            {
                throw new HttpResponseException(HttpStatusCode.InternalServerError);
            }

            var files = HttpContext.Current.Request.Files;

            var supplierOrder = DataManager.GetSupplierOrder(auctionId, CurrentUser.SupplierId);

            if (supplierOrder == null)
            {
                throw new HttpResponseException(HttpStatusCode.NotFound);
            }

            var auction        = DataManager.GetAuction(auctionId);
            var qualifications = DataManager.GetQualifications(auctionId);

            if (files.Get("supplierOrderScan") == null || files.Count < 1)
            {
                throw new HttpResponseException(HttpStatusCode.BadRequest);
            }

            JavaScriptSerializer        json_serializer = new JavaScriptSerializer();
            Dictionary <string, object> routes_list     =
                (Dictionary <string, object>)json_serializer.DeserializeObject(HttpContext.Current.Request.Form["form"]);

            var dictionaryFiles = new Dictionary <DocumentRequisite, Stream>();

            dictionaryFiles.Add(new DocumentRequisite()
            {
                date        = auction.Date,
                market      = (MarketPlaceEnum)auction.SiteId,
                filesListId = supplierOrder.fileListId,
                number      = auction.Number,
                fileName    = files.Get("supplierOrderScan").FileName,
                section     = DocumentSectionEnum.Auction,
                type        = DocumentTypeEnum.SupplierOrder
            }, files.Get("supplierOrderScan").InputStream);


            foreach (var qualification in qualifications.Where(q => q.file).ToList())
            {
                if (routes_list[qualification.id.ToString()] != null)
                {
                    var docReq     = ArchiveManager.GetDocumentParams(int.Parse(routes_list[qualification.id.ToString()].ToString()));
                    var streamFile = ArchiveManager.GetDocument(docReq);
                    if (docReq == null || streamFile == null)
                    {
                        throw new HttpResponseException(HttpStatusCode.BadRequest);
                    }
                    dictionaryFiles.Add(docReq, streamFile);
                }
                else
                {
                    var file = files.Get(String.Format("{0}", qualification.id));

                    if (file == null)
                    {
                        throw new HttpResponseException(HttpStatusCode.BadRequest);
                    }
                    dictionaryFiles.Add(new DocumentRequisite()
                    {
                        date        = auction.Date,
                        market      = (MarketPlaceEnum)auction.SiteId,
                        filesListId = supplierOrder.fileListId,
                        number      = auction.Number,
                        fileName    = String.Format("{0}_{1}_{2}.{3}", CurrentUser.SupplierId, qualification.id, qualification.name, Regex.Replace(file.FileName, @"^.*\.", "", RegexOptions.None)),
                        section     = DocumentSectionEnum.Auction,
                        type        = DocumentTypeEnum.Other
                    }, file.InputStream);
                }
            }
            foreach (var item in dictionaryFiles)
            {
                if (ArchiveManager.PutDocument(item.Value, item.Key) < 1)
                {
                    throw new HttpResponseException(HttpStatusCode.InternalServerError);
                }
            }

            DataManager.UpdateStatusOnSupplierOrder(supplierOrder.Id, 5);
            return(HttpStatusCode.OK);
        }