Advertisement
Guest User

Untitled

a guest
Jul 16th, 2019
138
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.04 KB | None | 0 0
  1. if (voucher.ServiceType == ServiceType.VaccineCompany)
  2. {
  3. if (voucher.Asignee == null)
  4. {
  5. throw new ArgumentNullException("Asignee is required for company vaccine voucher");
  6. }
  7. if (!voucher.BookingTime.HasValue)
  8. {
  9. throw new ArgumentNullException("Booking time is required for company vaccine voucher");
  10. }
  11. if (!voucher.FixedPrice.HasValue)
  12. {
  13. throw new ArgumentNullException("Fixed price is required for company vaccine voucher");
  14. }
  15. if (voucher.Discount.HasValue)
  16. {
  17. throw new ArgumentNullException("Discount is not a valid argument for company vaccine type voucher");
  18. }
  19. }
  20.  
  21. if (voucher.ServiceType == ServiceType.Vaccine)
  22. {
  23. if (voucher.Asignee != null)
  24. {
  25. throw new ArgumentException("Invalid argument asignee");
  26. }
  27. if (voucher.BookingTime.HasValue)
  28. {
  29. throw new ArgumentNullException("Invalid argument booking time");
  30. }
  31. if (voucher.FixedPrice.HasValue && voucher.Discount.HasValue)
  32. {
  33. throw new ArgumentException("Fixed price and discount cannot be set simultaneously");
  34. }
  35. }
  36.  
  37. using System;
  38. using System.Collections.Generic;
  39. using System.ComponentModel.DataAnnotations;
  40. using System.Runtime.Serialization;
  41.  
  42. namespace Remoting.VoucherService
  43. {
  44. [DataContract]
  45.  
  46. public sealed class Voucher
  47. {
  48. [Required(ErrorMessage = "Code is required")]
  49. [DataMember(Name = "code")]
  50. public string Code { get; set; }
  51.  
  52. [Required(ErrorMessage = "Description is required")]
  53. [DataMember(Name = "description")]
  54. public string Description { get; set; }
  55.  
  56. [Required(ErrorMessage = "ServiceType is required")]
  57. [DataMember(Name = "serviceType")]
  58. public ServiceType ServiceType { get; set; }
  59.  
  60. [DataMember(Name = "discount")]
  61. public double? Discount { get; set; }
  62.  
  63. [DataMember(Name = "fixedPrice")]
  64. public double? FixedPrice { get; set; }
  65.  
  66. [DataMember(Name = "isValid")]
  67. public bool Valid {
  68. get { return TimesUsed < MaxUsage; }
  69. set { }
  70. }
  71.  
  72. [DataMember(Name = "maxUsage")]
  73. public uint MaxUsage { get; set; } = 1;
  74.  
  75. [DataMember(Name = "asignee")]
  76. public string Asignee;
  77.  
  78. [DataMember(Name = "bookingTime")]
  79. public DateTime? BookingTime;
  80.  
  81. [DataMember(Name = "timesUsed")]
  82. public uint TimesUsed { get; set; } = 0;
  83.  
  84. public void IncreaseUsage()
  85. {
  86. TimesUsed += 1;
  87. }
  88.  
  89. private ExtensionDataObject data;
  90.  
  91. public ExtensionDataObject ExtensionData
  92. {
  93. get => data;
  94. set => data = value;
  95. }
  96. }
  97. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement