/
Product.cs
executable file
·57 lines (44 loc) · 1.51 KB
/
Product.cs
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
55
56
57
using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using System.Linq;
namespace Ebuy
{
[MetadataType(typeof(Category.Metadata))]
public class Product : Entity<long>
{
public string Name { get; set; }
public string Description { get; set; }
public double Rating
{
get { return _rating.Value; }
}
private readonly Lazy<double> _rating;
public virtual ICollection<Auction> Auctions { get; set; }
public virtual ICollection<Category> Categories { get; set; }
public virtual ICollection<WebsiteImage> Images { get; set; }
public virtual ICollection<Review> Reviews { get; set; }
public Product()
{
_rating = new Lazy<double>(() => Reviews.Average(x => x.Rating));
}
protected override string GenerateKey()
{
if (string.IsNullOrWhiteSpace(Name))
// TODO: Localize
throw new EntityKeyGenerationException(GetType(), "Name is empty");
return KeyGenerator.Generate(Name);
}
public class Metadata
{
[Required]
public object Categories;
[Required]
public object Description;
[Required, StringLength(2000)]
public object ImageUrl;
[Required, StringLength(500)]
public object Name;
}
}
}