public void Add(TMessage message)
        {
            var messages     = _tempDataWrapper.Get <IEnumerable <TMessage> >(Key) ?? new List <TMessage>();
            var messagesList = messages.ToList();

            messagesList.Add(message);
            _tempDataWrapper.Add(Key, messagesList);
        }
Exemplo n.º 2
0
        public async Task <string> SignDocuments([FromForm] IFormFileCollection uploads, [FromForm] string firstName, [FromForm] string secondName)
        {
            var fileGuid = Guid.NewGuid();

            using (var archiveMemoryStream = new MemoryStream())
            {
                using (var archive = new ZipArchive(archiveMemoryStream, ZipArchiveMode.Create, true))
                {
                    foreach (var uploadedFile in uploads)
                    {
                        using (var fileMemoryStream = new MemoryStream())
                        {
                            await uploadedFile.CopyToAsync(fileMemoryStream);

                            fileMemoryStream.Seek(0, SeekOrigin.Begin);
                            _signature.SignDocument(fileMemoryStream, firstName, secondName);
                            fileMemoryStream.Seek(0, SeekOrigin.Begin);

                            var archiveFile = archive.CreateEntry(uploadedFile.FileName);
                            using (var entryStream = archiveFile.Open())
                            {
                                using (var streamWriter = new StreamWriter(entryStream))
                                {
                                    await fileMemoryStream.CopyToAsync(entryStream);
                                }
                            }
                        }
                    }
                }

                archiveMemoryStream.Seek(0, SeekOrigin.Begin);
                _tempDataService.Add(fileGuid, archiveMemoryStream.ToArray());
            }

            return(fileGuid.ToString());
        }