public static bool UploadTenderingFile(int tenderingId, TenderingIndex docIndex, int?contractorId, string version, Grid layoutRoot, int?advertisementId = null, int?meetingId = null, int?warrantyId = null) { TenderingDocumentFile f = new TenderingDocumentFile(); TenderingDocumentFileRelation rel = new TenderingDocumentFileRelation(); rel.ContractorId = contractorId; rel.TenderingDocumentId = DataManagement.RetrieveTenderingDocumentId(docIndex); if (rel.TenderingDocumentId == -1) { return(false); } rel.TenderingId = tenderingId; rel.AdvertisementId = advertisementId; rel.MeetingId = meetingId; rel.WarrantyId = warrantyId; f.Version = version; f.AttachedDate = DateTime.Now; f.FileGuid = Guid.NewGuid(); string fileLocation = OpenFileHandler.OpenFileToUpload(); if (fileLocation == null) { return(false); } layoutRoot.Children.Add(busy); Task <bool> .Factory.StartNew(delegate { f.FileContent = OpenFileHandler.GetFileFromLocation(fileLocation); f.Name = System.IO.Path.GetFileName(fileLocation); if (DataManagement.AddTenderingFile(f) != -1) { rel.TenderingDocumentFileId = f.TenderingDocumentFileId; if (DataManagement.AddTenderingFileRelation(rel) == -1) { return(false); } f = null; GC.Collect(); return(true); } else { return(false); } }).ContinueWith(prev => { layoutRoot.Children.Remove(busy); bool result = prev.Result; if (result) { ErrorHandler.NotifyUser("فایل با موفقیت ثبت شد."); if (TransactionFinished != null) { TransactionFinished(); } } else { ErrorHandler.ShowErrorMessage("ثبت فایل امکان پذیر نبود لطفا دوباره سعی کنید."); } }, TaskScheduler.FromCurrentSynchronizationContext()); return(true); }