blob: fac2be3660f27524f2078ec7949b5e8d3fc93701 (
plain)
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
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
|
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Tango.BL.Entities;
using Tango.BL.Enumerations;
using System.Data.Entity;
namespace Tango.BL.Catalogs
{
public static class CatalogLoader
{
public static async Task<Catalog> LoadCatalog(ColorSpaces colorSpace, Rml rml, ObservablesContext context)
{
var space = await context.ColorSpaces.SingleOrDefaultAsync(x => x.Code == (int)colorSpace);
var all_items = await context.ColorCatalogs.Where(x => x.RmlGuid == rml.Guid && x.ColorSpace.Code == (int)colorSpace).ToListAsync();
Catalog catalog = new Catalog();
catalog.ColorSpace = space;
catalog.Name = space.Description;
if (all_items.Count > 0)
{
all_items = all_items.DistinctBy(x => x.Name).OrderBy(x => x.ColorCode).ToList();
int index = 1;
foreach (var item in all_items.GroupBy(x => x.ColorGroup))
{
CatalogGroup group = new CatalogGroup();
group.Index = index++;
group.Name = item.First().ColorGroup;
foreach (var i in item)
{
group.Items.Add(new CatalogItem(i));
}
catalog.Groups.Add(group);
}
}
return catalog;
}
public static Catalog GetRecent(Catalog source, List<String> names)
{
var filtersItems = source.Groups.SelectMany(x => x.Items).Select(x => x.Entity).Where(x => names.Contains(x.Name)).ToList();
var first = filtersItems.FirstOrDefault();
Catalog catalog = new Catalog();
if (first != null)
{
catalog.ColorSpace = first.ColorSpace;
catalog.Name = first.ColorSpace.Description;
foreach (var item in filtersItems.GroupBy(x => x.ColorGroup))
{
CatalogGroup group = new CatalogGroup();
group.Name = item.First().ColorGroup;
foreach (var i in item)
{
group.Items.Add(new CatalogItem(i));
}
catalog.Groups.Add(group);
}
}
return catalog;
}
}
}
|