public async Task ReplaceAsync(string token, Stream stream, Dictionary <string, string> parameters) { var user = await DWKitRuntime.Security.GetCurrentUserAsync(); string name = null; if (parameters.ContainsKey(FileProperties.Name)) { name = parameters[FileProperties.Name]; } string contentType = null; if (parameters.ContainsKey(FileProperties.ContentType)) { contentType = parameters[FileProperties.ContentType]; } UploadedFiles file; if (Guid.TryParse(token, out Guid id)) { file = await UploadedFiles.SelectByKey(id); } else { file = new UploadedFiles() { Id = id, CreatedBy = user?.Name, CreatedDate = DateTime.Now }; } if (name != null) { file.Name = name; } if (file.ContentType != null) { file.ContentType = contentType; } file.UpdatedBy = user?.Name; file.UpdatedDate = DateTime.Now; file.Used = true; file.Data = new byte[stream.Length]; if (stream != null) { await stream.WriteAsync(file.Data, 0, (int)stream.Length); file.AttachmentLength = stream.Length; } await file.ApplyAsync(); }
public async Task <(Stream Stream, Dictionary <string, string> Properties)> GetAsync(string token) { Guid id; if (Guid.TryParse(token, out id)) { var item = await UploadedFiles.SelectByKey(id); var stream = new MemoryStream(item.Data); var dic = new Dictionary <string, string> { { FileProperties.Name, item.Name }, { FileProperties.Length, item.AttachmentLength.ToString() }, { FileProperties.ContentType, item.ContentType }, { FileProperties.CreatedBy, item.CreatedBy }, { FileProperties.CreatedDate, item.CreatedDate.ToString() }, { FileProperties.UpdatedBy, item.UpdatedBy }, { FileProperties.UpdatedDate, item.UpdatedDate.ToString() } }; return(Stream : stream, Properties : dic); } return(Stream : null, Properties : null); }