-
Notifications
You must be signed in to change notification settings - Fork 15
/
Copy pathModel.cs
61 lines (53 loc) · 2.38 KB
/
Model.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
58
59
60
61
using System.Collections.ObjectModel;
namespace PullToRefresh {
public class Product {
string name;
string resourceName;
public string Name {
get { return name; }
set {
name = value;
if (Photo == null) {
resourceName = value.ToLower();
if (!String.IsNullOrEmpty(resourceName))
Photo = ImageSource.FromResource(resourceName);
}
}
}
public Product(string name) {
this.Name = name;
}
public ImageSource Photo { get; set; }
public string Description { get; set; }
}
public class ProductData {
readonly List<Product> products;
public ObservableCollection<Product> Products { get; set; }
public ProductData() : base() {
this.products = new List<Product>();
GenerateAllProducts();
int index = new Random().Next(0, 5);
Products = GenerateAvailableProducts(index);
}
ObservableCollection<Product> GenerateAvailableProducts(int number) {
ObservableCollection<Product> availableProducts = new ObservableCollection<Product>();
for (int i = 0; i < 4; i++)
availableProducts.Add(products[number + i]);
return availableProducts;
}
public void RefreshProducts() {
int index = new Random().Next(0, 5);
Products = GenerateAvailableProducts(index);
}
void GenerateAllProducts() {
products.Add(new Product("Beverages") { Description = "Soft drinks, coffees, teas, beers, and ales" });
products.Add(new Product("Condiments") { Description = "Sweet and savory sauces, relishes, spreads, and seasonings" });
products.Add(new Product("Confections") { Description = "Desserts, candies, and sweet breads" });
products.Add(new Product("DairyProducts") { Description = "Cheeses" });
products.Add(new Product("Grains") { Description = "Breads, crackers, pasta, and cereal" });
products.Add(new Product("MeatPoultry") { Description = "Prepared meats" });
products.Add(new Product("Produce") { Description = "Dried fruit and bean curd" });
products.Add(new Product("Seafood") { Description = "Seaweed and fish" });
}
}
}