/presentation/iPow.Presentation.jd/Controllers/HotelController.cs

https://bitbucket.org/JPomichael/miaow · C# · 298 lines · 185 code · 27 blank · 86 comment · 37 complexity · fae601c3586071156ac1f46b3299a329 MD5 · raw file

  1. using System.Linq;
  2. using System.Web;
  3. using System.Web.Mvc;
  4. using Webdiyer.WebControls.Mvc;
  5. namespace iPow.jd.Controllers
  6. {
  7. public class HotelController : ControllerBase
  8. {
  9. /// <summary>
  10. ///
  11. /// </summary>
  12. public const int picPageSize = 9;
  13. /// <summary>
  14. ///
  15. /// </summary>
  16. public const int commPageSize = 5;
  17. // GET: /Hotel/
  18. //[OutputCache(VaryByParam = "id")]
  19. /// <summary>
  20. /// Indexes the specified id.
  21. /// 酒店的基本信息
  22. /// </summary>
  23. /// <param name="id">The id.</param>
  24. /// <returns></returns>
  25. [HttpGet]
  26. public ActionResult Index(int id)
  27. {
  28. Models.HotelDetailHead hd = Bll.HotelDetail.GetHeadHotelDetailByIdentfiyId(id);
  29. if (hd != null)
  30. {
  31. ViewBag.hotelid = hd.HotelId;
  32. ViewBag.identfiyid = hd.IdentityId;
  33. try
  34. {
  35. Bll.DbSys.Db.Sys_HotelPropertyInfo.Where(e => e.ID == id).FirstOrDefault().VisitCount += 1;
  36. Bll.DbSys.Db.Sys_HotelPropertyInfo.Context.SaveChanges();
  37. }
  38. catch
  39. {
  40. }
  41. }
  42. return View(hd);
  43. }
  44. //[ChildActionOnly]
  45. //[OutputCache(Duration = 3600)]
  46. /// <summary>
  47. /// Hotels the room.
  48. /// 酒店房间信息
  49. /// </summary>
  50. /// <param name="id">The id.</param>
  51. /// <returns></returns>
  52. public ActionResult HotelRoom(int id)
  53. {
  54. ViewBag.hotelid = id;
  55. return PartialView("HotelRoomPartial");
  56. }
  57. /// <summary>
  58. /// Hotels the DES.
  59. /// 酒店具体的一些描述
  60. /// </summary>
  61. /// <param name="id">The id.</param>
  62. /// <returns></returns>
  63. [HttpGet]
  64. //[OutputCache(Duration = 3600 ,VaryByParam="id")]
  65. public ActionResult HotelDes(int id)
  66. {
  67. Models.HotelDetailMidHotelInfo hi = Bll.HotelDetail.GetHotelDetailMidHotelInfoByIdentfiyId(id);
  68. return PartialView("HotelDesPartial", hi);
  69. }
  70. //下面的都没有做的
  71. #region 已经做了 完成于2011.7.12.16.06
  72. /// <summary>
  73. /// Hotels the comm.
  74. /// 首次加载酒店评论
  75. /// </summary>
  76. /// <param name="id">The id.</param>
  77. /// <returns></returns>
  78. [HttpGet]
  79. public ActionResult HotelComm(int id)
  80. {
  81. int total = 0;
  82. IQueryable<iPow.DataSys.Sys_HotelComm> hc =Bll.HotelDetail.GetHotelCommPageListByHotelId(id, 1, 5, ref total);
  83. PagedList<iPow.DataSys.Sys_HotelComm> hcList = null;
  84. if (hc != null && hc.Count() > 0)
  85. {
  86. //ViewBag.id = id;
  87. //ViewBag.pagesize = commPageSize;
  88. //ViewBag.total = total;
  89. hcList = new PagedList<DataSys.Sys_HotelComm>(hc, 1, commPageSize, total);
  90. }
  91. ViewBag.hotelid = id;
  92. return PartialView("HotelCommPartial", hcList);
  93. }
  94. /// <summary>
  95. /// Hotels the comm list.
  96. /// 酒店评论分页
  97. /// </summary>
  98. /// <param name="id">The id.</param>
  99. /// <param name="pi">The pi.</param>
  100. /// <returns></returns>
  101. [HttpGet]
  102. public ActionResult HotelCommList(int id, int? pi)
  103. {
  104. int total = 0;
  105. int pageIdex = pi == null ? 1 : (int)pi;
  106. IQueryable<iPow.DataSys.Sys_HotelComm> hc = Bll.HotelDetail.GetHotelCommPageListByHotelId(id, pageIdex, 5, ref total);
  107. PagedList<iPow.DataSys.Sys_HotelComm> hcList = null;
  108. if (hc != null && hc.Count() > 0)
  109. {
  110. //ViewBag.id = id;
  111. //ViewBag.pagesize = commPageSize;
  112. //ViewBag.total = total;
  113. hcList = new PagedList<DataSys.Sys_HotelComm>(hc, pageIdex, commPageSize, total);
  114. }
  115. ViewBag.hotelid = id;
  116. return PartialView("HotelCommListPartial", hcList);
  117. }
  118. /// <summary>
  119. /// Adds the hotel comm.
  120. /// 添加酒店评论
  121. /// </summary>
  122. /// <param name="f">The f.</param>
  123. /// <returns></returns>
  124. [HttpPost]
  125. public ActionResult AddHotelComm(FormCollection f)
  126. {
  127. if (f != null)
  128. {
  129. try
  130. {
  131. iPow.DataSys.Sys_HotelComm hc = new DataSys.Sys_HotelComm();
  132. #region init
  133. hc.AddTime = System.DateTime.Now;
  134. hc.CommID = Bll.DbSys.Db.Sys_HotelComm.Max(e => e.CommID) + 1;
  135. if (f["Content"] != null)
  136. {
  137. hc.Content = f["Content"];
  138. }
  139. if (f["HotelID"] != null)
  140. {
  141. hc.HotelID = int.Parse(f["HotelID"].ToString());
  142. }
  143. hc.Ip = iPow.function.StringHelper.GetRealIP();
  144. if (hc.Ip == "::1")
  145. {
  146. hc.Ip = "127.0.0.1";
  147. }
  148. if (f["Sroce"] != null)
  149. {
  150. hc.Point = int.Parse(f["Sroce"].ToString());
  151. }
  152. hc.UserID = 0;
  153. if (f["UserName"] != null)
  154. {
  155. hc.UserName = f["UserName"].ToString();
  156. }
  157. #endregion
  158. Bll.DbSys.Db.AddToSys_HotelComm(hc);
  159. if (Bll.DbSys.Db.Sys_HotelComm.Context.SaveChanges() > 0)
  160. {
  161. var hotelInfo = Bll.DbSys.Db.Sys_HotelPropertyInfo.Where(e => e.ID == hc.HotelID).FirstOrDefault() ;
  162. hotelInfo.CommCount += 1;
  163. Bll.DbSys.Db.Sys_HotelPropertyInfo.Context.SaveChanges();
  164. int total = 0;
  165. IQueryable<iPow.DataSys.Sys_HotelComm> hcs = Bll.HotelDetail.GetHotelCommPageListByHotelId(hc.HotelID, 1, 5, ref total);
  166. PagedList<iPow.DataSys.Sys_HotelComm> hcList = null;
  167. if (hcs != null && hcs.Count() > 0)
  168. {
  169. hcList = new PagedList<DataSys.Sys_HotelComm>(hcs, 1, commPageSize, total);
  170. }
  171. ViewBag.hotelid = hc.HotelID;
  172. return PartialView("HotelCommListPartial", hcList);
  173. }
  174. }
  175. catch
  176. {
  177. return Json("", JsonRequestBehavior.AllowGet);
  178. }
  179. }
  180. return Json("", JsonRequestBehavior.AllowGet);
  181. }
  182. #endregion
  183. /// <summary>
  184. /// Hotels the pic.
  185. /// 酒店图片
  186. /// 首次加载
  187. /// </summary>
  188. /// <param name="id">The id.</param>
  189. /// <returns></returns>
  190. [HttpGet]
  191. public ActionResult HotelPic(int id)
  192. {
  193. IQueryable<iPow.DataSys.Sys_HotelPic> hp = null;
  194. PagedList<iPow.DataSys.Sys_HotelPic> hpList = null;
  195. int total = 0;
  196. hp = Bll.HotelDetail.GetHotelPicPageListByHotelId(id, 1, picPageSize, ref total);
  197. if (hp != null && hp.Count() > 0)
  198. {
  199. hpList = new PagedList<iPow.DataSys.Sys_HotelPic>(hp, 1, picPageSize, total);
  200. }
  201. return PartialView("HotelPicPartial", hpList);
  202. }
  203. /// <summary>
  204. /// Hotels the pic list.
  205. /// 酒店图片分页
  206. /// </summary>
  207. /// <param name="id">The id.</param>
  208. /// <param name="pi">Index of the page.</param>
  209. /// <returns></returns>
  210. [HttpGet]
  211. public ActionResult HotelPicList(int id, int? pi)
  212. {
  213. //不用写单独的东西出来了,直接用数据库里面的就是了 ,数据量也不大
  214. //随机9张
  215. //可能会改进那种分页的那种
  216. IQueryable<iPow.DataSys.Sys_HotelPic> hp = null;
  217. PagedList<iPow.DataSys.Sys_HotelPic> hpList = null;
  218. int pageIndex = (pi == null ? 1 : (int)pi);
  219. int total = 0;
  220. hp = Bll.HotelDetail.GetHotelPicPageListByHotelId(id, pageIndex, picPageSize, ref total);
  221. if (hp != null && hp.Count() > 0)
  222. {
  223. hpList = new PagedList<iPow.DataSys.Sys_HotelPic>(hp, pageIndex, picPageSize, total);
  224. }
  225. return PartialView("HotelPicListPartial", hpList);
  226. }
  227. //2011.7.10.17.42完成
  228. /// <summary>
  229. /// Adds the hotel live in.
  230. /// 酒店的我住过
  231. /// </summary>
  232. /// <param name="id">The id.</param>
  233. /// <returns></returns>
  234. [HttpGet]
  235. [NoCache]
  236. public JsonResult AddHotelLiveIn(int id)
  237. {
  238. bool tar = false;
  239. int? temp = 0;
  240. try
  241. {
  242. iPow.DataSys.Sys_HotelPropertyInfo hi = Bll.DbSys.Db.Sys_HotelPropertyInfo.Where(e => e.ID == id).FirstOrDefault();
  243. if (hi != null)
  244. {
  245. hi.LiveInCount += 1;
  246. temp = hi.LiveInCount;
  247. }
  248. Bll.DbSys.Db.Sys_HotelPropertyInfo.Context.SaveChanges();
  249. tar = true;
  250. }
  251. catch
  252. {
  253. }
  254. return Json(new { success = tar, livein = temp }, JsonRequestBehavior.AllowGet);
  255. }
  256. /// <summary>
  257. /// Hotels the traffic.
  258. /// 交通
  259. /// </summary>
  260. /// <param name="id">The id.</param>
  261. /// <returns></returns>
  262. //[HttpGet]
  263. [ChildActionOnly]
  264. public ActionResult HotelTraffic(int id)
  265. {
  266. ViewBag.hotelid = id;
  267. Models.HotelTraffic ht =Bll.HotelDetail.GetHotelTrafficByHotelId(id);
  268. return PartialView("HotelTrafficPartial", ht);
  269. }
  270. }
  271. }