You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. using AutoMapper;
  2. using PuppeteerSharp;
  3. using BlackRock.Reporting.API.Core.Models;
  4. using BlackRock.Reporting.API.Models;
  5. namespace BlackRock.Reporting.API.Profiles
  6. {
  7. public class Profiler : Profile
  8. {
  9. public Profiler()
  10. {
  11. CreateMap<OptionsForPdf, PdfOptions>().ConvertUsing<OptionsForPdfConverter>();
  12. CreateMap<User, UserDto>().ReverseMap();
  13. CreateMap<User, UserForm>().ReverseMap();
  14. }
  15. }
  16. public class OptionsForPdfConverter : ITypeConverter<OptionsForPdf, PdfOptions>
  17. {
  18. public PdfOptions Convert(OptionsForPdf source, PdfOptions destination, ResolutionContext context)
  19. {
  20. if (source == null) return destination;
  21. if (destination == null)
  22. destination = new PdfOptions();
  23. destination.DisplayHeaderFooter = source.DisplayHeaderFooter;
  24. destination.HeaderTemplate = source.HeaderTemplate;
  25. destination.Height = source.Height;
  26. destination.Landscape = source.Landscape;
  27. destination.OmitBackground = source.OmitBackground;
  28. destination.PageRanges = source.PageRanges;
  29. destination.PreferCSSPageSize = source.PreferCSSPageSize;
  30. destination.PrintBackground = source.PrintBackground;
  31. destination.Scale = source.Scale;
  32. destination.Width = source.Width;
  33. destination.MarginOptions = new PuppeteerSharp.Media.MarginOptions()
  34. {
  35. Bottom = source.MarginBottom,
  36. Top = source.MarginTop,
  37. Right = source.MarginRight,
  38. Left = source.MarginLeft
  39. };
  40. switch (source.PaperFormatType)
  41. {
  42. case PaperFormatType.A4:
  43. destination.Format = PuppeteerSharp.Media.PaperFormat.A4;
  44. break;
  45. case PaperFormatType.A3:
  46. destination.Format = PuppeteerSharp.Media.PaperFormat.A3;
  47. break;
  48. case PaperFormatType.Letter:
  49. destination.Format = PuppeteerSharp.Media.PaperFormat.Letter;
  50. break;
  51. }
  52. return destination;
  53. }
  54. }
  55. }