blob: d8a3d8be0f261a38d70b9d7e73dd2bfe551aa163 (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
|
using System.Collections.Generic;
using System.IO;
using System.Linq;
using VSH.Data.Enums;
using VSH.Data.Miscellaneous;
using VSH.Data.Static;
using VSH.Utilities;
namespace VSH.Data.Database;
public class Product : Base
{
public string Name { get; set; }
public string Description { get; set; }
public decimal Price { get; set; }
public PriceSuffix PriceSuffix { get; set; }
public ProductVisibility VisibilityState { get; set; }
public Category Category { get; set; }
public List<ProductImage> Images { get; set; }
public int Count { get; set; }
public string Slug { get; set; }
public bool ShowOnFrontpage { get; set; }
public string ReadablePriceSuffix => EnumName.ForPriceSuffix(PriceSuffix);
public AppPath GetPrimaryImage() {
var productImage = Images.OrderBy(c => c.Order).FirstOrDefault();
return productImage != default ? productImage.GetPath() : AppPaths.DefaultProductImage;
}
public string WebPath() => $"/produktar/{Category?.Slug}/{Slug}";
public bool IsVisible => VisibilityState == ProductVisibility.DEFAULT;
public bool IsAvailable => Count == -1 || Count >= 1;
}
public class ProductImage
{
public ProductImage(string fileName = default, int order = default) {
FileName = fileName;
Order = order;
}
public int Order { get; }
public string FileName { get; }
public AppPath GetPath() {
if (FileName == default) return AppPaths.DefaultProductImage;
return new AppPath {
WebPath = Path.Combine(AppPaths.ProductImages.WebPath, FileName),
HostPath = Path.Combine(AppPaths.ProductImages.HostPath, FileName),
};
}
}
|