ProductDto.cs 3.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  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. public bool IsParentValid {get;set;}
  42. 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);
  43. public bool IsVariant => string.Equals(Type, CS_ITEM_TYPE_VARIANT, StringComparison.InvariantCultureIgnoreCase);
  44. public string VariantAndPrice => $"{VariantName}-{Price}";
  45. public string TypeAsString => IsVariant ? "Varianta" : "Produkt";
  46. public string GetIdentifier()
  47. {
  48. var sb = new StringBuilder();
  49. sb.Append(Id).Append("_");
  50. sb.Append(ProductName);
  51. return sb.ToString().ToLower();
  52. }
  53. public void CopyTo(ProductDto destination, bool includeId = false)
  54. {
  55. if (includeId)
  56. destination.Id = Id;
  57. destination.Type = Type;
  58. destination.Sku = Sku;
  59. destination.ProductName = ProductName;
  60. destination.ParentName = ParentName;
  61. destination.ShortDescription = ShortDescription;
  62. destination.Description = Description;
  63. destination.VariantType = VariantType;
  64. destination.VariantName = VariantName;
  65. destination.Category = Category;
  66. destination.Uri = Uri;
  67. destination.Price = Price;
  68. }
  69. bool IEquatable<IIdentifierGetter>.Equals(IIdentifierGetter? other)
  70. {
  71. return other != null && other.GetIdentifier() == GetIdentifier();
  72. }
  73. }
  74. }