public async Task <TTSFile> UploadFile(string fileName, byte[] fileBytes) { fileName = NormalizeName(fileName); GeneratePath(fileName, out string filePath); System.IO.File.WriteAllBytes(filePath, fileBytes); TTSFile file = new TTSFile() { Name = fileName, Size = fileBytes.Length, Path = filePath, ContentType = ContentTypeHelper.GetContentType(Path.GetExtension(fileName)), }; await _iBaseLogic.Of <TTSFile>().Add(file); return(file); }
//public async Task<Guid> ZipFiles(List<AgroFile> files, string fileName, Guid fileTypeId, string appNumber, Guid? userId, Guid applicationId) //{ // if (files.Count == 0) // { // throw new ArgumentException("Список файлов не может быть пустым"); // } // GeneratePath(fileName, out string filePath); // byte[] fileBytes; // using (var memoryStream = new MemoryStream()) // { // using (var archive = new ZipArchive(memoryStream, ZipArchiveMode.Create, true)) // { // var i = 1; // foreach (var file in files) // { // string name = _dictionaryLogic.DictionaryRepo<DicFileType>().GetQueryable(x => x.Code.Equals(file.DocInformation.DocumentCode)).FirstOrDefault().NameRu; // archive.CreateEntryFromFile(file.Path, name + Path.GetExtension(file.Name)); // i++; // } // } // using (var fileStream = new FileStream(filePath, FileMode.Create)) // { // memoryStream.Seek(0, SeekOrigin.Begin); // memoryStream.CopyTo(fileStream); // fileBytes = memoryStream.ToArray(); // } // } // return await _agroFileRepo.Add( // new AgroFile() // { // Name = fileName, // FileTypeId = fileTypeId, // Size = fileBytes.Length, // Path = filePath, // ContentType = ContentTypeHelper.GetContentType(Path.GetExtension(fileName)), // CreatorUserId = userId, // ApplicationId = applicationId // }); //} //public async Task<bool> UpdateDocInformation(DocInformationsInDto model) //{ // if (model.Items.Count == 0) return false; // var applicationId = model.Items.First().ApplicationId; // var docs = await _agroFileRepo.Base() // .Include(x => x.DocInformation) // .Where(x => x.ApplicationId == applicationId) // .Select(x => x.DocInformation) // .ToListAsync(); // docs.ForEach(doc => // { // var m = model.Items.FirstOrDefault(x => x.Code == doc.DocumentCode); // if (m == null) return; // doc.IsOriginal = m.IsOriginal; // doc.PageCount = m.PageCount; // doc.PageInterval = m.PageInterval; // }); // await _agroFileRepo.Save(); // return true; //} public async Task <TTSFile> GetFileById(Guid id) { TTSFile res = await _iBaseLogic.Of <TTSFile>().GetQueryable(x => x.Id.Equals(id)).FirstOrDefaultAsync(); return(res); }