source: extensions/PiwigoLib/PiwigoWpf/DTO/Helper/PwgCategoryListWPFHelper.cs @ 11935

Last change on this file since 11935 was 11935, checked in by bayral, 13 years ago

root category handled

File size: 3.4 KB
Line 
1using System;
2using System.Collections.Generic;
3using System.Linq;
4using System.Text;
5using Com.Piwigo.Lib.DTO;
6
7namespace Com.Piwigo.Wpf.DTO.Helper
8{
9    public static class PwgCategoryListWPFHelper
10    {
11        public static void AddPwgCategoryToList(    PwgCategory aPwgCategory,
12                                                ref PwgCategoryListWPF aPwgCategoryListWPF)
13        {
14            if (aPwgCategory != null)
15            {
16                if (aPwgCategoryListWPF == null)
17                {
18                    aPwgCategoryListWPF = new PwgCategoryListWPF();
19                }
20
21                PwgCategoryWPF pwgCat = new PwgCategoryWPF();
22                PwgCategoryWPFHelper.ConvertPwgCategoryToPwgCategoryWPF(aPwgCategory, ref pwgCat);
23
24                aPwgCategoryListWPF.Add(pwgCat);
25            }
26        }
27
28        public static void ConvertPwgCategoryListToPwgCategoryListWPF(List<PwgCategory> aPwgCategoryList, ref PwgCategoryListWPF aPwgCategoryListWPF)
29        {
30            if (aPwgCategoryList != null)
31            {
32                if (aPwgCategoryListWPF == null)
33                {
34                    aPwgCategoryListWPF = new PwgCategoryListWPF();
35                }
36
37                foreach (PwgCategory pwgCat in aPwgCategoryList)
38                {
39                    AddPwgCategoryToList(pwgCat, ref aPwgCategoryListWPF);
40                }
41            }
42        }
43
44        public static void ConvertPwgCategoryListToPwgRootCategoryWPF(List<PwgCategory> aPwgCategoryList, ref PwgRootCategoryWPF aPwgRootCategory)
45        {
46            if (aPwgCategoryList != null)
47            {
48                if ((aPwgRootCategory == null)
49                    || (aPwgRootCategory.Childrens == null))
50                {
51                    throw new SystemException("The PwgCategoryListWPFHelper.InitRootCategory must be called before calling this.");
52                }
53
54                if (aPwgRootCategory.Childrens == null)
55                {
56                    aPwgRootCategory.Childrens = new PwgCategoryListWPF();
57                }
58
59                PwgCategoryListWPF aPwgCategoryListWPF = aPwgRootCategory.Childrens;
60                foreach (PwgCategory pwgCat in aPwgCategoryList)
61                {
62                    AddPwgCategoryToList(pwgCat, ref aPwgCategoryListWPF);
63                }
64            }
65        }
66
67        public static void InitRootCategory ()
68          {
69            if (PwgModelManager.Instance.CategoryList == null)
70            {
71                throw new SystemException("The PwgModelManager.Instance.CategoryList must be initialized from presentation tread before calling this.");
72            }
73            if (PwgModelManager.Instance.CategoryList.Count != 1)
74            {
75                PwgModelManager.Instance.CategoryList.Clear();
76                PwgRootCategoryWPF aRootCategory = new PwgRootCategoryWPF();
77                aRootCategory.Name = "Root";
78                aRootCategory.Childrens = new PwgCategoryListWPF();
79                PwgModelManager.Instance.CategoryList.Add(aRootCategory);
80                PwgModelManager.Instance.RootCategoryList = aRootCategory;
81            }
82
83            if (PwgModelManager.Instance.RootCategoryList == null)
84            {
85                PwgModelManager.Instance.RootCategoryList = PwgModelManager.Instance.CategoryList.ElementAtOrDefault(0);
86            }
87
88          }
89    }
90}
Note: See TracBrowser for help on using the repository browser.