PageRenderTime 42ms CodeModel.GetById 13ms RepoModel.GetById 1ms app.codeStats 0ms

/trunk/Src/App/WebAdmin/Areas/Commerce/Controllers/SellerController.cs

http://xenta.codeplex.com
C# | 384 lines | 353 code | 31 blank | 0 comment | 6 complexity | 2aaa4615c13562838ec1505e83b86f81 MD5 | raw file
Possible License(s): Apache-2.0, BSD-3-Clause, LGPL-2.1
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Dynamic;
  4. using System.Web.Mvc;
  5. using Xenta.Utils;
  6. using Xenta.Attributes;
  7. using Xenta.Web.Controllers;
  8. namespace Xenta.Web.Areas.Commerce.Controllers
  9. {
  10. [Authenticate, InRole("ADMIN")]
  11. public sealed class SellerController : ExtController
  12. {
  13. #region GET/POST Actions
  14. [HttpGet]
  15. public ActionResult Index()
  16. {
  17. return View();
  18. }
  19. [HttpGet]
  20. public ActionResult GoTo(int? id, int? accountID)
  21. {
  22. if(!id.HasValue && accountID.HasValue)
  23. {
  24. var m = Svc.ProcessOperation("GetCustomerByAccount", new
  25. {
  26. AccountID = accountID
  27. });
  28. id = m != null ? JDM.Int32(m.EntityID) : null;
  29. }
  30. if(!id.HasValue)
  31. return HttpNotFound();
  32. return RedirectToAction(Loc.Act("Edit").Set(new
  33. {
  34. id
  35. }));
  36. }
  37. [HttpGet, RestoreState]
  38. public ActionResult Create()
  39. {
  40. return View();
  41. }
  42. [HttpPost, PersistState]
  43. public ActionResult Create(int accountID, string displayName, string[] flags)
  44. {
  45. try
  46. {
  47. var m = Svc.ProcessOperation("CreateSeller", new
  48. {
  49. AccountID = accountID,
  50. DisplayName = displayName,
  51. Flags = flags.Merge(",")
  52. });
  53. return RedirectToAction(Loc.Act("Edit").Set(new
  54. {
  55. id = JDM.Int32(m.EntityID)
  56. }));
  57. }
  58. catch(Exception ex)
  59. {
  60. ModelState.AddModelError("API", ex);
  61. }
  62. return RedirectToAction(Loc.Act("Create"));
  63. }
  64. [HttpGet, RestoreState]
  65. public ActionResult Edit(int id)
  66. {
  67. var m = Svc.ProcessOperation("GetSeller", new
  68. {
  69. EntityID = id,
  70. }, new
  71. {
  72. DisclosureLevel = "Entire"
  73. });
  74. if(m == null)
  75. return HttpNotFound();
  76. return View(m);
  77. }
  78. [HttpPost, PersistState]
  79. public ActionResult Update(int id, string displayName, string[] flags)
  80. {
  81. try
  82. {
  83. Svc.ProcessOperation("UpdateSeller", new
  84. {
  85. EntityID = id,
  86. DisplayName = displayName,
  87. Flags = flags.Merge(",")
  88. });
  89. }
  90. catch(Exception ex)
  91. {
  92. ModelState.AddModelError("API", ex);
  93. }
  94. return RedirectToAction(Loc.Act("Edit").Set(new
  95. {
  96. id
  97. }));
  98. }
  99. [HttpGet, PersistState]
  100. public ActionResult Delete(int id)
  101. {
  102. try
  103. {
  104. Svc.ProcessOperation("DeleteSeller", new
  105. {
  106. EntityID = id
  107. });
  108. return RedirectToAction(Loc.Act("Index"));
  109. }
  110. catch(Exception ex)
  111. {
  112. ModelState.AddModelError("API", ex);
  113. }
  114. return RedirectToAction(Loc.Act("Edit").Set(new
  115. {
  116. id
  117. }));
  118. }
  119. [HttpPost, PersistState]
  120. public ActionResult CreateAddress(int sellerID,
  121. int countryID,
  122. int regionID,
  123. string city,
  124. string address1,
  125. string address2,
  126. string entityName,
  127. string contactName,
  128. string postalCode,
  129. string phoneNumber,
  130. string faxNumber,
  131. string email,
  132. string website,
  133. string[] flags)
  134. {
  135. try
  136. {
  137. Svc.ProcessOperation("CreateSellerAddress", new
  138. {
  139. HolderID = sellerID,
  140. CountryID = countryID,
  141. RegionID = regionID,
  142. City = city,
  143. Address1 = address1,
  144. Address2 = address2,
  145. EntityName = entityName,
  146. ContactName = contactName,
  147. PostalCode = postalCode,
  148. PhoneNumber = phoneNumber,
  149. FaxNumber = faxNumber,
  150. Email = email,
  151. Website = website,
  152. Flags = flags.Merge(",")
  153. });
  154. }
  155. catch(Exception ex)
  156. {
  157. ModelState.AddModelError("API", ex);
  158. }
  159. return RedirectToAction(Loc.Act("Edit").Set(new
  160. {
  161. id = sellerID
  162. }));
  163. }
  164. [HttpPost, PersistState]
  165. public ActionResult UpdateAddress(int id,
  166. int sellerID,
  167. int countryID,
  168. int regionID,
  169. string city,
  170. string address1,
  171. string address2,
  172. string entityName,
  173. string contactName,
  174. string postalCode,
  175. string phoneNumber,
  176. string faxNumber,
  177. string email,
  178. string website,
  179. string[] flags)
  180. {
  181. try
  182. {
  183. Svc.ProcessOperation("UpdateSellerAddress", new
  184. {
  185. EntityID = id,
  186. CountryID = countryID,
  187. RegionID = regionID,
  188. City = city,
  189. Address1 = address1,
  190. Address2 = address2,
  191. EntityName = entityName,
  192. ContactName = contactName,
  193. PostalCode = postalCode,
  194. PhoneNumber = phoneNumber,
  195. FaxNumber = faxNumber,
  196. Email = email,
  197. Website = website,
  198. Flags = flags.Merge(",")
  199. });
  200. }
  201. catch(Exception ex)
  202. {
  203. ModelState.AddModelError("API", ex);
  204. }
  205. return RedirectToAction(Loc.Act("Edit").Set(new
  206. {
  207. id = sellerID
  208. }));
  209. }
  210. [HttpGet, PersistState]
  211. public ActionResult DeleteAddress(int id, int sellerID)
  212. {
  213. try
  214. {
  215. Svc.ProcessOperation("DeleteSellerAddress", new
  216. {
  217. EntityID = id
  218. });
  219. }
  220. catch(Exception ex)
  221. {
  222. ModelState.AddModelError("API", ex);
  223. }
  224. return RedirectToAction(Loc.Act("Edit").Set(new
  225. {
  226. id = sellerID
  227. }));
  228. }
  229. #endregion
  230. #region AJAX Actions
  231. [HttpPost]
  232. public ActionResult Grid(int? page,
  233. int? rows,
  234. string sord,
  235. string sidx,
  236. string searchTerm)
  237. {
  238. page = page.HasValue ? page.Value - 1 : 0;
  239. rows = rows.HasValue ? rows.Value : 30;
  240. sord = sord.Equals("desc") ? "Descending" : "Ascending";
  241. var m = Svc.ProcessOperation("SearchSellers", new
  242. {
  243. Term = new
  244. {
  245. Expression = searchTerm
  246. },
  247. Index = page * rows,
  248. Count = rows,
  249. SortBy = new[]
  250. {
  251. sidx
  252. },
  253. SortDir = sord
  254. }, new
  255. {
  256. DisclosureLevel = "Base"
  257. });
  258. var data = new List<Object>();
  259. foreach(var i in m.Items)
  260. {
  261. data.Add(new[] {
  262. JDM.Int32(i.EntityID),
  263. JDM.String(i.Account.Email),
  264. JDM.String(i.DisplayName),
  265. JDM.Int32(i.CommentCount),
  266. JDM.Int32(i.RatingCount),
  267. JDM.Byte(i.RatingAverage)
  268. });
  269. }
  270. return Json(new
  271. {
  272. pageIndex = page + 1,
  273. pageCount = Math.Ceiling(JDM.Double(m.TotalCount) / rows),
  274. totalCount = JDM.Int64(m.TotalCount),
  275. data = data.ToArray()
  276. });
  277. }
  278. [HttpPost]
  279. public ActionResult Autocomplete(string term)
  280. {
  281. var m = Svc.ProcessOperation("GetSellerDictionary", new
  282. {
  283. Term = new
  284. {
  285. Expression = String.Format("{0}%", term)
  286. },
  287. Count = 10
  288. });
  289. var data = new List<Object>();
  290. foreach(var i in m.Items)
  291. {
  292. data.Add(new
  293. {
  294. id = JDM.String(i.Key),
  295. value = JDM.String(i.Value)
  296. });
  297. }
  298. return Json(data.ToArray());
  299. }
  300. [HttpPost]
  301. public ActionResult Addresses(int sellerID)
  302. {
  303. var m = Svc.ProcessOperation("SearchSellerAddresses", new
  304. {
  305. HolderID = sellerID
  306. }, new
  307. {
  308. DisclosureLevel = "Base"
  309. });
  310. var data = new List<Object>();
  311. foreach(var i in m.Items)
  312. {
  313. data.Add(new
  314. {
  315. id = JDM.Int32(i.EntityID),
  316. value = JDM.String(i.ShortForm)
  317. });
  318. }
  319. return Json(data.ToArray());
  320. }
  321. #endregion
  322. #region Child Actions
  323. [ChildActionOnly]
  324. public ActionResult _Ratings(int sellerID)
  325. {
  326. dynamic m = new ExpandoObject();
  327. m.EntityID = sellerID;
  328. m.Ratings = Svc.ProcessOperation("SearchSellerRatings", new
  329. {
  330. HolderID = sellerID
  331. }, new
  332. {
  333. DisclosureLevel = "Extended"
  334. }).Items;
  335. return PartialView(m);
  336. }
  337. [ChildActionOnly]
  338. public ActionResult _Comments(int sellerID)
  339. {
  340. dynamic m = new ExpandoObject();
  341. m.EntityID = sellerID;
  342. m.Comments = Svc.ProcessOperation("SearchSellerComments", new
  343. {
  344. HolderID = sellerID
  345. }, new
  346. {
  347. DisclosureLevel = "Extended"
  348. }).Items;
  349. return PartialView(m);
  350. }
  351. #endregion
  352. }
  353. }