Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- [ValidateAntiForgeryToken]
- [HttpPost]
- public async Task<ActionResult> Upload(TemplateOutputModel input)
- {
- var result = await Command.ApplyAsync(new UploadDocumentTemplateCommand
- {
- DocumentType = input.DocumentType,
- InputStream = input.File.InputStream,
- ContentLength = input.File.ContentLength,
- FileExtension = ".docx"
- });
- if (result == Command.CommandResult.Succeeded)
- return RedirectToAction("List");
- throw new Exception("Template not uploaded");
- }
- public class UploadDocumentTemplateCommand:ICommand
- {
- public DocumentType DocumentType { get; set;}
- public Stream InputStream { get; set; }
- public int ContentLength { get; set; }
- public string FileExtension { get; set; }
- }
- public async Task<Command.CommandResult> Apply(UploadDocumentTemplateCommand command)
- {
- if (command.ContentLength <= 0) return Command.CommandResult.Failed;
- switch (command.FileExtension)
- {
- case ".pdf":
- documentService.SaveStaticDocument(command.DocumentType, command.InputStream);
- break;
- case ".docx":
- var versionNumber = documentRepository.GetDocumentTemplateVersion(command.DocumentType);
- documentRepository.QuickTemplateUpload(command.DocumentType, command.InputStream, versionNumber + 1);
- break;
- }
- return Command.CommandResult.Succeeded;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement