PageRenderTime 89ms CodeModel.GetById 9ms RepoModel.GetById 2ms app.codeStats 0ms

/Passbook.Sample.Web/Controllers/PassController.cs

https://github.com/Comezon/dotnet-passbook
C# | 111 lines | 86 code | 21 blank | 4 comment | 0 complexity | a5017050e883cb50cb84ef3887e7e356 MD5 | raw file
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Configuration;
  4. using System.Linq;
  5. using System.Web;
  6. using System.Web.Mvc;
  7. using Passbook.Generator;
  8. using Passbook.Generator.Fields;
  9. using System.IO;
  10. using Passbook.Sample.Web.SampleRequests;
  11. namespace Passbook.Sample.Web.Controllers
  12. {
  13. public class PassController : Controller
  14. {
  15. public ActionResult EventTicket()
  16. {
  17. PassGenerator generator = new PassGenerator();
  18. EventPassGeneratorRequest request = new EventPassGeneratorRequest();
  19. request.Identifier = "pass.tomsamcguinness.events";
  20. request.CertThumbprint = ConfigurationManager.AppSettings["PassBookCertificateThumbprint"];
  21. request.CertLocation = System.Security.Cryptography.X509Certificates.StoreLocation.LocalMachine;
  22. request.SerialNumber = "121211";
  23. request.Description = "My first pass";
  24. request.OrganizationName = "Tomas McGuinness";
  25. request.TeamIdentifier = "R5QS56362W";
  26. request.LogoText = "My Pass";
  27. request.BackgroundColor = "rgb(255,255,255)";
  28. request.ForegroundColor = "rgb(0,0,0)";
  29. // override icon and icon retina
  30. request.Images.Add(PassbookImage.Icon, System.IO.File.ReadAllBytes(Server.MapPath("~/Icons/icon.png")));
  31. request.Images.Add(PassbookImage.IconRetina, System.IO.File.ReadAllBytes(Server.MapPath("~/Icons/icon@2x.png")));
  32. request.EventName = "Jeff Wayne's War of the Worlds";
  33. request.SeatingSection = 10;
  34. request.DoorsOpen = new DateTime(2012, 11, 03, 11, 30, 00);
  35. request.AddBarCode("01927847623423234234", BarcodeType.PKBarcodeFormatPDF417, "UTF-8", "01927847623423234234");
  36. byte[] generatedPass = generator.Generate(request);
  37. return new FileContentResult(generatedPass, "application/vnd.apple.pkpass");
  38. }
  39. public ActionResult BoardingCard()
  40. {
  41. PassGenerator generator = new PassGenerator();
  42. BoardingCardGeneratorRequest request = new BoardingCardGeneratorRequest();
  43. request.Identifier = "pass.tomsamcguinness.events";
  44. request.CertThumbprint = ConfigurationManager.AppSettings["PassBookCertificateThumbprint"];
  45. request.CertLocation = System.Security.Cryptography.X509Certificates.StoreLocation.LocalMachine;
  46. request.SerialNumber = "121212111";
  47. request.Description = "My first pass";
  48. request.OrganizationName = "Tomas McGuinness";
  49. request.TeamIdentifier = "R5QS56362W";
  50. request.LogoText = "My Pass";
  51. request.BackgroundColor = "rgb(255,255,255)";
  52. request.ForegroundColor = "rgb(0,0,0)";
  53. // Specific information
  54. //
  55. request.Origin = "San Francisco";
  56. request.OriginCode = "SFO";
  57. request.Destination = "London";
  58. request.DestinationCode = "LDN";
  59. request.Seat = "7A";
  60. request.BoardingGate = "F12";
  61. request.PassengerName = "John Appleseed";
  62. request.TransitType = TransitType.PKTransitTypeAir;
  63. request.AuthenticationToken = "vxwxd7J8AlNNFPS8k0a0FfUFtq0ewzFdc";
  64. request.WebServiceUrl = "http://192.168.1.59:82/api/";
  65. byte[] generatedPass = generator.Generate(request);
  66. return new FileContentResult(generatedPass, "application/vnd.apple.pkpass");
  67. }
  68. public ActionResult Coupon()
  69. {
  70. PassGenerator generator = new PassGenerator();
  71. CouponPassGeneratorRequest request = new CouponPassGeneratorRequest();
  72. request.Identifier = "pass.tomsamcguinness.events";
  73. request.CertThumbprint = ConfigurationManager.AppSettings["PassBookCertificateThumbprint"];
  74. request.CertLocation = System.Security.Cryptography.X509Certificates.StoreLocation.LocalMachine;
  75. request.SerialNumber = "121211";
  76. request.Description = "My first pass";
  77. request.OrganizationName = "Tomas McGuinness";
  78. request.TeamIdentifier = "R5QS56362W";
  79. request.LogoText = "My Pass";
  80. request.BackgroundColor = "rgb(0,0,0)";
  81. request.ForegroundColor = "rgb(255,255,255)";
  82. // override icon and icon retina
  83. request.Images.Add(PassbookImage.Icon, System.IO.File.ReadAllBytes(Server.MapPath("~/Icons/icon.png")));
  84. request.Images.Add(PassbookImage.IconRetina, System.IO.File.ReadAllBytes(Server.MapPath("~/Icons/icon@2x.png")));
  85. request.AddBarCode("01927847623423234234", BarcodeType.PKBarcodeFormatPDF417, "UTF-8", "01927847623423234234");
  86. byte[] generatedPass = generator.Generate(request);
  87. return new FileContentResult(generatedPass, "application/vnd.apple.pkpass");
  88. }
  89. }
  90. }