ProductDto.cs 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103
  1. 
  2. using qdr.app.studiou.orders2printpack.Extensions;
  3. using System.Security.Policy;
  4. using System.Text;
  5. namespace qdr.app.studiou.orders2printpack.ProductStorage
  6. {
  7. public class ProductDto : IIdentifierGetter
  8. {
  9. public const string CS_ITEM_TYPE_VARIANT = "variation";
  10. public const string CS_ITEM_TYPE_PRODUCT = "variable";
  11. [CsvColumn("ID")]
  12. public int Id { get; set; }
  13. [CsvColumn("Typ")]
  14. public string Type { get; set; } = string.Empty;
  15. [CsvColumn("Katalogové číslo")]
  16. public string Sku { get; set; } = string.Empty;
  17. [CsvColumn("Jméno")]
  18. public string ProductName { get; set; } = string.Empty;
  19. [CsvColumn("Nadřazené")]
  20. public string ParentName { get; set; } = string.Empty;
  21. [CsvColumn("Krátký popis")]
  22. public string ShortDescription { get; set; } = string.Empty;
  23. [CsvColumn("Popis")]
  24. public string Description { get; set; } = string.Empty;
  25. [CsvColumn("Název 1 vlastnosti")]
  26. public string VariantType { get; set; } = string.Empty;
  27. [CsvColumn("Hodnota(y) 1 vlastnosti")]
  28. public string VariantName { get; set; } = string.Empty;
  29. [CsvColumn("Kategorie")]
  30. public string Category { get; set; } = string.Empty;
  31. [CsvColumn("Obrázky")]
  32. public string Uri { get; set; } = string.Empty;
  33. [CsvColumn("Běžná cena")]
  34. public decimal Price { get; set; }
  35. [CsvColumn("Vlastnost 1 viditelnost")]
  36. public int Hidden1 { get; set; } = 1;
  37. [CsvColumn("Vlastnost 1 globální")]
  38. public int Hidden2 { get; set; } = 1;
  39. [CsvColumn("Povolit zákaznické recenze?")]
  40. public int Hidden3 { get; set; } = 0;
  41. [CsvColumn("Minimum Quantity")]
  42. public int QuantityMinimum { get; set; } = 0;
  43. [CsvColumn("Maximum Quantity")]
  44. public int QuantityMaximum { get; set; } = 0;
  45. public bool IsParentValid {get;set;}
  46. public bool IsValid => ((IsVariant && IsParentValid) || !IsVariant) && ((IsVariant && Price > 0) || !IsVariant) && !string.IsNullOrEmpty(Sku) && !string.IsNullOrEmpty(Uri) && ((!IsVariant && !string.IsNullOrEmpty(Category)) || IsVariant) && ((IsVariant && !string.IsNullOrEmpty(VariantName)) || !IsVariant);
  47. public bool IsVariant => string.Equals(Type, CS_ITEM_TYPE_VARIANT, StringComparison.InvariantCultureIgnoreCase);
  48. public string VariantAndPrice => $"{VariantName}-{Price}";
  49. public string TypeAsString => IsVariant ? "Varianta" : "Produkt";
  50. public string GetIdentifier()
  51. {
  52. var sb = new StringBuilder();
  53. sb.Append(Id).Append("_");
  54. sb.Append(ProductName);
  55. return sb.ToString().ToLower();
  56. }
  57. public void CopyTo(ProductDto destination, bool includeId = false)
  58. {
  59. if (includeId)
  60. destination.Id = Id;
  61. destination.Type = Type;
  62. destination.Sku = Sku;
  63. destination.ProductName = ProductName;
  64. destination.ParentName = ParentName;
  65. destination.ShortDescription = ShortDescription;
  66. destination.Description = Description;
  67. destination.VariantType = VariantType;
  68. destination.VariantName = VariantName;
  69. destination.Category = Category;
  70. destination.Uri = Uri;
  71. destination.Price = Price;
  72. }
  73. bool IEquatable<IIdentifierGetter>.Equals(IIdentifierGetter? other)
  74. {
  75. return other != null && other.GetIdentifier() == GetIdentifier();
  76. }
  77. }
  78. }