1 | using System; |
---|
2 | using System.Collections.Generic; |
---|
3 | using System.Text; |
---|
4 | |
---|
5 | using Com.Piwigo.Lib.DTO; |
---|
6 | using Com.Piwigo.Lib.Proxy; |
---|
7 | using Com.Piwigo.Lib.Proxy.Response; |
---|
8 | using Com.Piwigo.Lib.DTO.Helper; |
---|
9 | |
---|
10 | namespace Com.Piwigo.Lib.Service |
---|
11 | { |
---|
12 | |
---|
13 | static public class PwgCategoriesService |
---|
14 | { |
---|
15 | /// <summary> |
---|
16 | /// Get the list of category the user is connected can access |
---|
17 | /// </summary> |
---|
18 | /// <param name="sortedByCounter"></param> |
---|
19 | /// <returns></returns> |
---|
20 | static public List<PwgCategory> GetListOfCategory(Int32? CatgeroryId, Boolean? Recursive, Boolean? PublicOnly) |
---|
21 | { |
---|
22 | List<PwgCategory> returnValue = new List<PwgCategory>(); |
---|
23 | |
---|
24 | try |
---|
25 | { |
---|
26 | PwgCategoriesProxyResponse response = PwgCategoriesProxy.pwg_categories_getList(CatgeroryId, Recursive, PublicOnly); |
---|
27 | |
---|
28 | if (response.Retour != PwgBaseProxyReponseRetourEnum.Ok) |
---|
29 | { |
---|
30 | if (response.Erreur != null) |
---|
31 | { |
---|
32 | throw new PwgServiceException("GetListOfCategory, the server has return the error.", |
---|
33 | response.Erreur.Code, |
---|
34 | response.Erreur.Message); |
---|
35 | } |
---|
36 | else |
---|
37 | { |
---|
38 | throw new PwgServiceException("GetListOfCategory : a error occurs during server process."); |
---|
39 | } |
---|
40 | } |
---|
41 | else |
---|
42 | { |
---|
43 | returnValue = ConvertProxyResponseToDTO(response); |
---|
44 | } |
---|
45 | } |
---|
46 | catch (PwgProxyException ex) |
---|
47 | { |
---|
48 | throw new PwgServiceException("GetListOfCategory : a error is raised by proxy.", ex); |
---|
49 | } |
---|
50 | return returnValue; |
---|
51 | } |
---|
52 | |
---|
53 | /// <summary> |
---|
54 | /// Get List of all Category, must be logged as admin |
---|
55 | /// </summary> |
---|
56 | /// <returns></returns> |
---|
57 | static public List<PwgCategory> GetAdminListOfCategory() |
---|
58 | { |
---|
59 | List<PwgCategory> returnValue = new List<PwgCategory>(); |
---|
60 | |
---|
61 | try |
---|
62 | { |
---|
63 | PwgCategoriesProxyResponse response = PwgCategoriesProxy.pwg_categories_getAdminList(); |
---|
64 | |
---|
65 | if (response.Retour != PwgBaseProxyReponseRetourEnum.Ok) |
---|
66 | { |
---|
67 | if (response.Erreur != null) |
---|
68 | { |
---|
69 | throw new PwgServiceException("GetAdminListOfCategory, the server has return the error.", |
---|
70 | response.Erreur.Code, |
---|
71 | response.Erreur.Message); |
---|
72 | } |
---|
73 | else |
---|
74 | { |
---|
75 | throw new PwgServiceException("GetAdminListOfCategory : a error occurs during server process."); |
---|
76 | } |
---|
77 | } |
---|
78 | else |
---|
79 | { |
---|
80 | returnValue = ConvertProxyResponseToDTO(response); |
---|
81 | } |
---|
82 | } |
---|
83 | catch (PwgProxyException ex) |
---|
84 | { |
---|
85 | throw new PwgServiceException("GetAdminListOfCategory : a error is raised by proxy.", ex); |
---|
86 | } |
---|
87 | return returnValue; |
---|
88 | } |
---|
89 | |
---|
90 | /// <summary> |
---|
91 | /// Add a Categorie |
---|
92 | /// </summary> |
---|
93 | /// <param name="tagName"></param> |
---|
94 | /// <returns></returns> |
---|
95 | static public Boolean AddCategory(String categoryName, Int32? upperCatId, ref Int32 newId, ref String messageInfo) |
---|
96 | { |
---|
97 | Boolean returnValue = false; |
---|
98 | |
---|
99 | try |
---|
100 | { |
---|
101 | PwgAddRequestProxyResponse response = PwgCategoriesProxy.pwg_categories_add(categoryName, upperCatId); |
---|
102 | |
---|
103 | if (response.Retour != PwgBaseProxyReponseRetourEnum.Ok) |
---|
104 | { |
---|
105 | if (response.Erreur != null) |
---|
106 | { |
---|
107 | throw new PwgServiceException("AddTag, the server has return the error.", |
---|
108 | response.Erreur.Code, |
---|
109 | response.Erreur.Message); |
---|
110 | } |
---|
111 | else |
---|
112 | { |
---|
113 | throw new PwgServiceException("AddTag : a error occurs during server process."); |
---|
114 | } |
---|
115 | } |
---|
116 | else |
---|
117 | { |
---|
118 | returnValue = true; |
---|
119 | newId = response.NewId; |
---|
120 | messageInfo = response.Message; |
---|
121 | } |
---|
122 | } |
---|
123 | catch (PwgProxyException ex) |
---|
124 | { |
---|
125 | throw new PwgServiceException("AddTag : a error is raised by proxy.", ex); |
---|
126 | } |
---|
127 | return returnValue; |
---|
128 | } |
---|
129 | |
---|
130 | /// <summary> |
---|
131 | /// private: convert response to dto object |
---|
132 | /// </summary> |
---|
133 | /// <param name="response"></param> |
---|
134 | /// <param name="session"></param> |
---|
135 | static public List<PwgCategory> ConvertProxyResponseToDTO(PwgCategoriesProxyResponse response) |
---|
136 | { |
---|
137 | List<PwgCategory> returnValue = new List<PwgCategory>(); |
---|
138 | |
---|
139 | foreach (PwgCategoryProxyResponse respCat in response.Categories) |
---|
140 | { |
---|
141 | returnValue.Add(ConvertProxyResponseToDTO(respCat)); |
---|
142 | } |
---|
143 | |
---|
144 | return returnValue; |
---|
145 | } |
---|
146 | |
---|
147 | |
---|
148 | /// <summary> |
---|
149 | /// private: convert response to dto object |
---|
150 | /// </summary> |
---|
151 | /// <param name="response"></param> |
---|
152 | /// <param name="session"></param> |
---|
153 | static public PwgCategory ConvertProxyResponseToDTO(PwgCategoryProxyResponse response) |
---|
154 | { |
---|
155 | PwgCategory returnValue = new PwgCategory(); |
---|
156 | |
---|
157 | try |
---|
158 | { |
---|
159 | returnValue.Id = response.Id; |
---|
160 | returnValue.Name = response.Name; |
---|
161 | |
---|
162 | returnValue.DeepImagesCount = response.DeepImagesCount; |
---|
163 | returnValue.ImagesCount = response.ImagesCount; |
---|
164 | returnValue.SubCategoriesCount = response.SubCategoriesCount; |
---|
165 | |
---|
166 | returnValue.UpperCategoriesId = new List<int>(); |
---|
167 | if (response.UpperCategoryId != null) |
---|
168 | { |
---|
169 | foreach (String stringId in response.UpperCategoryId.Split(',')) |
---|
170 | { |
---|
171 | returnValue.UpperCategoriesId.Add(Int32.Parse(stringId)); |
---|
172 | } |
---|
173 | } |
---|
174 | |
---|
175 | if (response.LastDate != null) |
---|
176 | { |
---|
177 | DateTime tryDate; |
---|
178 | if (DateTime.TryParse(response.LastDate, out tryDate)) |
---|
179 | { |
---|
180 | returnValue.LastDate = tryDate; |
---|
181 | } |
---|
182 | } |
---|
183 | |
---|
184 | if (String.IsNullOrEmpty(response.Url)) |
---|
185 | { |
---|
186 | returnValue.Url = null; |
---|
187 | } |
---|
188 | else |
---|
189 | { |
---|
190 | returnValue.Url = (new UriBuilder(response.Url)).Uri; |
---|
191 | } |
---|
192 | } |
---|
193 | catch (Exception ex) |
---|
194 | { |
---|
195 | throw new PwgServiceException("ConvertProxyResponseToDTO : a error is raised when converting PwgTagProxyResponse.", ex); |
---|
196 | } |
---|
197 | |
---|
198 | return returnValue; |
---|
199 | } |
---|
200 | } |
---|
201 | } |
---|