public static bool LoadFile(FileStoreDTO fileStoreDTO, out MemoryStream stream, out string contentType) { stream = null; contentType = GetContentType(Path.GetExtension(fileStoreDTO.OrigFileName).ToLower()); if (fileStoreDTO == null) { return(false); } string tempDir = Path.GetTempPath(); if (UnZipFile(fileStoreDTO.FilePath, tempDir, fileStoreDTO.OrigFileName)) { var unZipFilePath = Path.Combine(tempDir, fileStoreDTO.OrigFileName); stream = new MemoryStream(); using (var st = new FileStream(unZipFilePath, FileMode.Open)) { st.CopyTo(stream); } stream.Position = 0; DeleteFileIfExist(unZipFilePath); return(true); } return(false); }
public async Task SubmitApplication(IConfiguration config, FilesSignViewModel model) { try { foreach (var file in model.files) { if (file.idFileStore != Guid.Empty) { var fileStore = DataService.GetEntity <FileStore>(x => x.Id == file.idFileStore).FirstOrDefault(); DataService.Remove(fileStore); await DataService.SaveChangesAsync(); var fileStoreNew = new FileStoreDTO { FileType = FileType.Unknown, OrigFileName = file.name + ".p7s", FileSize = FileSignHelper.GetOriginalLengthInBytes(file.file), Ock = file.isSystemFile, EntityId = fileStore.EntityId, EntityName = fileStore.EntityName, ContentType = ".p7s", Description = "Підписаний файл лікарських засобів" }; await FileSignHelper.SaveFile(config, file, fileStoreNew, DataService); } else { var fileStore = new FileStoreDTO { FileType = FileType.Unknown, OrigFileName = file.name + ".p7s", FileSize = FileSignHelper.GetOriginalLengthInBytes(file.file), Ock = file.isSystemFile, EntityId = model.id, EntityName = nameof(ImlApplication), ContentType = ".p7s", Description = "Підписаний PDF заяви" }; await FileSignHelper.SaveFile(config, file, fileStore, DataService); } } } catch (Exception e) { Log.Error(e.Message); throw; } var app = DataService.GetEntity <ImlApplication>(x => x.Id == model.id)?.FirstOrDefault(); app.AppState = "Submitted"; app.BackOfficeAppState = "Submitted"; app.IsCreatedOnPortal = true; await DataService.SaveChangesAsync(); }
public async Task SubmitBackOfficeApplication(IConfiguration config, Guid appId) { var application = DataService.GetEntity <PrlApplication>(x => x.Id == appId).FirstOrDefault(); if (application == null) { throw new Exception(); } byte[] file; try { file = await GetApplicationFile(appId, application.AppSort); } catch (Exception e) { throw e; } var fileStore = new FileStoreDTO { FileType = FileType.Pdf, OrigFileName = "PDF заяви.pdf", FileSize = file.Length, EntityId = appId, EntityName = nameof(PrlApplication), ContentType = ".pdf", Description = "PDF заяви" }; await FileSignHelper.SaveFile(config, new FilesViewModel() { name = "PDF заяви", file = Convert.ToBase64String(file) }, fileStore, DataService); application.AppState = "Submitted"; application.BackOfficeAppState = "Submitted"; await DataService.SaveChangesAsync(); }
public static FileStoreDTO SaveFile(IConfiguration config, IFormFile formFile, FileStoreDTO fileStoreDTO) { var folderForSave = config.GetSection("FileStorePath").Value + DateTime.Now.ToString("ddMMyyyy") + "/"; var filePath = Path.GetFullPath(folderForSave); if (!Directory.Exists(filePath)) { Directory.CreateDirectory(filePath); } if (formFile.Length > 0) { var fileExt = Path.GetExtension(formFile.FileName).ToLower(); var newName = Path.GetFileNameWithoutExtension(Path.GetRandomFileName()) + ".zip"; var tempfolder = Path.GetTempPath(); var fullOrigPath = tempfolder + formFile.FileName; string fullZipPath = filePath + newName; using (var stream = new FileStream(fullOrigPath, FileMode.Create)) { formFile.CopyTo(stream); } bool result = CreateZip(fullZipPath, fullOrigPath); DeleteFileIfExist(fullOrigPath); return(new FileStoreDTO() { EntityId = fileStoreDTO.EntityId, EntityName = fileStoreDTO.EntityName, FileType = GetFileType(fileExt), FileName = newName, FilePath = fullZipPath, OrigFileName = formFile.FileName, ContentType = GetTypeByContentType(formFile.ContentType), FileSize = formFile.Length, DocumentType = fileStoreDTO.DocumentType, Description = fileStoreDTO.Description }); } return(null); }
public async Task <List <string> > UploadMedicine(Guid?appId, IFormFile file) { var countOfErrors = 0; var cellErrors = new List <string>(); var medicines = new List <ImlMedicine>(); using (var excelPackage = new ExcelPackage(file.OpenReadStream())) { var workbook = excelPackage.Workbook; var worksheet = workbook.Worksheets.First(); var row = 9; var checkString = ""; var limsRps = await DataService.GetDtoAsync <LimsRPMinDTO>(x => x.EndDate > DateTime.Now && x.OffOrderDate == null, extraParameters : new object[] { "" }); do { var imlMedicine = new ImlMedicine(); var checkOnError = false; string cellNum = ""; for (var col = 1; col < 14; col++) { var cell = worksheet.Cells[row, col].First(); var valueObj = cell.Value; if (valueObj != null) { var value = valueObj.ToString(); switch (col) { case 1: cellNum = value; break; case 2: imlMedicine.MedicineName = value; checkString = value; break; case 3: if (string.IsNullOrEmpty(value)) { checkOnError = true; } imlMedicine.FormName = value; break; case 4: if (string.IsNullOrEmpty(value)) { checkOnError = true; } imlMedicine.DoseInUnit = value; break; case 5: if (string.IsNullOrEmpty(value)) { checkOnError = true; } imlMedicine.NumberOfUnits = value; break; case 6: if (string.IsNullOrEmpty(value)) { checkOnError = true; } imlMedicine.MedicineNameEng = value; break; case 7: if (string.IsNullOrEmpty(value)) { checkOnError = true; } var rplz = limsRps.FirstOrDefault(x => x.RegNum == value); if (rplz == null) { cellErrors.Add(cellNum); checkOnError = true; break; } else { imlMedicine.LimsRpId = rplz.Id; } imlMedicine.RegisterNumber = value; break; case 8: if (string.IsNullOrEmpty(value)) { checkOnError = true; } imlMedicine.AtcCode = value; break; case 9: if (string.IsNullOrEmpty(value)) { checkOnError = true; } imlMedicine.ProducerName = value; break; case 10: if (string.IsNullOrEmpty(value)) { checkOnError = true; } imlMedicine.ProducerCountry = value; break; case 11: if (string.IsNullOrEmpty(value)) { checkOnError = true; } imlMedicine.SupplierName = value; break; case 12: if (string.IsNullOrEmpty(value)) { checkOnError = true; } imlMedicine.SupplierCountry = value; break; case 13: if (string.IsNullOrEmpty(value)) { checkOnError = true; } imlMedicine.SupplierAddress = value; break; case 14: if (string.IsNullOrEmpty(value)) { checkOnError = true; } imlMedicine.Notes = value; break; } } else { if (col == 2) { checkString = string.Empty; checkOnError = true; break; } } //if (checkOnError) // break; } imlMedicine.ApplicationId = appId.Value; imlMedicine.CreatedByJson = _userInfo.PersonId; if (!checkOnError) { medicines.Add(imlMedicine); } //else // countOfErrors++; row++; } while (!string.IsNullOrEmpty(checkString)); await SaveMedicines(medicines); } var fileStore = new FileStoreDTO { FileType = FileType.Unknown, OrigFileName = file.Name + ".xlsx", FileSize = file.Length, Ock = false, EntityId = appId.Value, EntityName = nameof(ImlApplication), ContentType = ".xlsx", Description = "Medicines" }; var dto = FileStoreHelper.SaveFile(_configuration, file, fileStore); DataService.Add <FileStore>(dto); await DataService.SaveChangesAsync(); return(cellErrors); }
public static async Task SaveFile(IConfiguration config, FilesViewModel model, FileStoreDTO fileStoreDto, ICommonDataService dataService) { var folderForSave = config.GetSection("FileStorePath").Value + DateTime.Now.ToString("ddMMyyyy") + "/"; var filePath = Path.GetFullPath(folderForSave); if (!Directory.Exists(filePath)) { Directory.CreateDirectory(filePath); } var newName = Path.GetFileNameWithoutExtension(Path.GetRandomFileName()) + ".zip"; var tempfolder = Path.GetTempPath(); var fullOrigPath = tempfolder + model.name; string fullZipPath = filePath + newName; var directoryInfo = (new FileInfo(fullOrigPath)).Directory; directoryInfo?.Create(); await File.WriteAllBytesAsync(fullOrigPath, Convert.FromBase64String(model.file)); CreateZip(fullZipPath, fullOrigPath); FileStoreHelper.DeleteFileIfExist(fullOrigPath); fileStoreDto.FileName = newName; fileStoreDto.FilePath = fullZipPath; dataService.Add <FileStore>(fileStoreDto); }