protected async Task <OriginalDescription> SaveOriginalDescriptionAsync( Document document, OriginalDescription originalDescription) { // TODO: Validate original description _context.OriginalsDescriptions.Add(originalDescription); await SaveChangesAsync(); return(originalDescription); }
/// <summary> /// Add original to document /// </summary> /// <param name="document">Document object</param> /// <param name="original">Uploadable original</param> /// <returns></returns> public async Task <OriginalDescription> AddOriginalAsync(Document document, Original original) { if (document is null) { throw new ArgumentNullException(nameof(document)); } if (original is null) { throw new ArgumentNullException(nameof(document)); } // TODO: Original validation byte[] bytes; using (var ms = new MemoryStream()) { await original.File.CopyToAsync(ms); bytes = ms.ToArray(); } var id = Guid.NewGuid(); var extension = Path.GetExtension(original.File.FileName); var path = Path.Combine(document.ID.ToString(), $"{id}{extension}"); await _storage.UploadObjectAsync(path, bytes); var originalFileName = Path.GetFileNameWithoutExtension(original.File.FileName); var originalDescription = new OriginalDescription { ID = id, FileName = originalFileName, Extension = extension, StorageSource = _storage.Source, StoragePath = path, ForSign = original.ForSign, Size = original.File.Length, DocumentID = document.ID }; return(await SaveOriginalDescriptionAsync(document, originalDescription)); }
private async Task <IEnumerable <Document> > seedDocuments(CabinetContext _context, IStorage storage, int documentTypeID) { var files = Directory.GetFiles($"{_env.WebRootPath}/Seed"); foreach (var file in files) { var document = new Document { ID = Guid.NewGuid(), OrganizationID = 1, DocumentTypeID = documentTypeID, Name = Path.GetFileNameWithoutExtension(file) }; var fileInfo = new FileInfo(file); var originalId = Guid.NewGuid(); var originalDescription = new OriginalDescription { ID = originalId, DocumentID = document.ID, Extension = fileInfo.Extension, FileName = Path.GetFileNameWithoutExtension(file), ForSign = true, Size = fileInfo.Length, StoragePath = Path.Combine(document.ID.ToString(), $"{originalId}{fileInfo.Extension}"), StorageSource = storage.Source }; await storage.UploadObjectAsync(originalDescription.StoragePath, File.ReadAllBytes(file)); _context.Documents.Add(document); _context.OriginalsDescriptions.Add(originalDescription); } await _context.SaveChangesAsync(); return(await _context.Documents.ToListAsync()); }
public async Task ValidateOriginalDescriptionAsync(OriginalDescription originalDescription) { }