ProductDto.cs 3.2 KB

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