Advertisement
Guest User

Untitled

a guest
Jun 24th, 2019
79
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.37 KB | None | 0 0
  1. [ValidateAntiForgeryToken]
  2. [HttpPost]
  3. public async Task<ActionResult> Upload(TemplateOutputModel input)
  4. {
  5. var result = await Command.ApplyAsync(new UploadDocumentTemplateCommand
  6. {
  7. DocumentType = input.DocumentType,
  8. InputStream = input.File.InputStream,
  9. ContentLength = input.File.ContentLength,
  10. FileExtension = ".docx"
  11. });
  12.  
  13. if (result == Command.CommandResult.Succeeded)
  14. return RedirectToAction("List");
  15. throw new Exception("Template not uploaded");
  16. }
  17.  
  18. public class UploadDocumentTemplateCommand:ICommand
  19. {
  20. public DocumentType DocumentType { get; set;}
  21. public Stream InputStream { get; set; }
  22. public int ContentLength { get; set; }
  23. public string FileExtension { get; set; }
  24. }
  25.  
  26. public async Task<Command.CommandResult> Apply(UploadDocumentTemplateCommand command)
  27. {
  28. if (command.ContentLength <= 0) return Command.CommandResult.Failed;
  29. switch (command.FileExtension)
  30. {
  31. case ".pdf":
  32. documentService.SaveStaticDocument(command.DocumentType, command.InputStream);
  33. break;
  34. case ".docx":
  35. var versionNumber = documentRepository.GetDocumentTemplateVersion(command.DocumentType);
  36. documentRepository.QuickTemplateUpload(command.DocumentType, command.InputStream, versionNumber + 1);
  37. break;
  38. }
  39. return Command.CommandResult.Succeeded;
  40. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement