HomeFitnessController.cs 6.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198
  1. using NEducation.Code;
  2. using NEducation.Models;
  3. using System;
  4. using System.Collections.Generic;
  5. using System.Globalization;
  6. using System.Linq;
  7. using System.Threading;
  8. using System.Web;
  9. using System.Web.Mvc;
  10. using static NEducation.Controllers.UtilsController;
  11. namespace NEducation.Controllers
  12. {
  13. public class HomeFitnessController : BaseController
  14. {
  15. private static log4net.ILog log { get; set; } = log4net.LogManager.GetLogger(typeof(HomeFitnessController));
  16. // GET: HomeFitness
  17. public ActionResult Index()
  18. {
  19. Session["navitab"] = "HomeFitness";
  20. CultureInfo currentCulture = Thread.CurrentThread.CurrentCulture;
  21. HfModel model = new HfModel();
  22. model.hfDatas = new List<HfData>();
  23. try
  24. {
  25. // get menu
  26. HfDataRequest request = new HfDataRequest();
  27. request.parentId = Constant.PARENT_ID;
  28. String rs = UtilsController.SendPost(request, Session.SessionID, UtilsController.WsType.GetHfDatabyParentId);
  29. HfDataResponse res = new HfDataResponse(rs);
  30. if (res.status == Constant.SUCCESS)
  31. {
  32. model.hfDatas = res.data;
  33. Session["categories"] = model.hfDatas;
  34. }
  35. return View(model);
  36. }
  37. catch (Exception ex)
  38. {
  39. log.Error(ex.Message);
  40. }
  41. return Redirect("/HomeFitness");
  42. }
  43. public ActionResult Menu(String id)
  44. {
  45. if (!CheckAuthToken())
  46. {
  47. return Redirect("/HomeFitness");
  48. }
  49. Session["COURSE_NOW"] = UtilsController.Constant.HOMEFITNESS;
  50. HfModel model = new HfModel();
  51. model.hfDatas = new List<HfData>();
  52. try
  53. {
  54. List<HfData> categories = Session["categories"] as List<HfData>;
  55. if (categories == null || categories.Count == 0)
  56. {
  57. return Redirect("/HomeFitness");
  58. }
  59. model.hfDataParent = categories.Find(x => x.Id == id);
  60. if (model.hfDataParent == null)
  61. {
  62. return Redirect("/HomeFitness");
  63. }
  64. // check register
  65. // get menu
  66. HfDataRequest request = new HfDataRequest();
  67. request.parentId = id;
  68. String rs = UtilsController.SendPost(request, Session.SessionID, UtilsController.WsType.GetHfDatabyParentId);
  69. HfDataResponse res = new HfDataResponse(rs);
  70. if (res.status == Constant.SUCCESS)
  71. {
  72. model.hfDatas = res.data;
  73. Session["menu"] = model.hfDatas;
  74. }
  75. return View(model);
  76. }
  77. catch (Exception ex)
  78. {
  79. log.Error(ex.Message);
  80. }
  81. return Redirect("/HomeFitness");
  82. }
  83. public ActionResult MenuDetail(String id)
  84. {
  85. if (!CheckAuthToken())
  86. {
  87. return Redirect("/HomeFitness");
  88. }
  89. HfModel model = new HfModel();
  90. model.hfDatas = new List<HfData>();
  91. try
  92. {
  93. List<HfData> menu = Session["menu"] as List<HfData>;
  94. if (menu == null || menu.Count == 0)
  95. {
  96. return Redirect("/HomeFitness");
  97. }
  98. model.hfDataParent = menu.Find(x => x.Id == id);
  99. if (model.hfDataParent == null)
  100. {
  101. return Redirect("/HomeFitness");
  102. }
  103. // get menu
  104. HfDataRequest request = new HfDataRequest();
  105. request.parentId = id;
  106. String rs = UtilsController.SendPost(request, Session.SessionID, UtilsController.WsType.GetHfDatabyParentId);
  107. HfDataResponse res = new HfDataResponse(rs);
  108. if (res.status == Constant.SUCCESS)
  109. {
  110. model.hfDatas = res.data;
  111. Session["data"] = model.hfDatas;
  112. }
  113. return View(model);
  114. }
  115. catch (Exception ex)
  116. {
  117. log.Error(ex.Message);
  118. }
  119. return Redirect("/HomeFitness");
  120. }
  121. public ActionResult MenuContent(String id)
  122. {
  123. if (!CheckAuthToken())
  124. {
  125. return Redirect("/HomeFitness");
  126. }
  127. List<SubInfo> subInfo = Session["subInfo"] as List<SubInfo>;
  128. SubInfo homefitness = null;
  129. if (subInfo != null)
  130. {
  131. homefitness = subInfo.Find(x => x.subServiceName == UtilsController.Constant.EDU_HOME_FITNESS_REG);
  132. }
  133. if (homefitness == null)
  134. {
  135. return Redirect("/HomeFitness");
  136. }
  137. HfModel model = new HfModel();
  138. model.hfDatas = new List<HfData>();
  139. try
  140. {
  141. //List<HfData> data = Session["data"] as List<HfData>;
  142. //if (data == null || data.Count == 0)
  143. //{
  144. // HfDataRequest request = new HfDataRequest();
  145. // request.id = id;
  146. // String rs = UtilsController.SendPost(request, Session.SessionID, UtilsController.WsType.GetHfDatabyId);
  147. // HfDataResponse res = new HfDataResponse(rs);
  148. // if (res.status == Constant.SUCCESS)
  149. // {
  150. // model.hfDatas = res.data;
  151. // Session["data"] = model.hfDatas;
  152. // }
  153. //}
  154. //else
  155. //{
  156. // model.content = data.Find(x => x.Id == id);
  157. //}
  158. HfDataRequest request = new HfDataRequest();
  159. request.id = id;
  160. String rs = UtilsController.SendPost(request, Session.SessionID, UtilsController.WsType.GetHfDatabyId);
  161. HfDataResponse res = new HfDataResponse(rs);
  162. if (res.status == Constant.SUCCESS)
  163. {
  164. if (res.data.Count > 0)
  165. {
  166. model.content = res.data[0];
  167. }
  168. }
  169. else
  170. {
  171. return Redirect("/HomeFitness");
  172. }
  173. return View(model);
  174. }
  175. catch (Exception ex)
  176. {
  177. log.Error(ex.Message);
  178. }
  179. return Redirect("/HomeFitness");
  180. }
  181. }
  182. }