CzLinkController.cs 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  1. using CP.Model;
  2. using Newtonsoft.Json;
  3. using NIU.Core;
  4. using NIU.Core.Log;
  5. using System;
  6. using System.Collections.Generic;
  7. using System.Linq;
  8. using System.Web;
  9. using System.Web.Mvc;
  10. namespace CP.Admin.Controllers
  11. {
  12. public class CzLinkController : AdminBaseController
  13. {
  14. // GET: CzLink
  15. public ActionResult Index()
  16. {
  17. return View();
  18. }
  19. public ActionResult Edit(long? id)
  20. {
  21. if (id == null)
  22. {
  23. return View(new CzLink());
  24. }
  25. else
  26. {
  27. var info = CzLinkData.GetById(long.Parse(id.ToString()));
  28. return View(info);
  29. }
  30. //return View(new CzLink());
  31. }
  32. /// <summary>
  33. /// 编辑
  34. ///// </summary>
  35. //[HttpGet]
  36. //public ActionResult Edit(long? id)
  37. //{
  38. // var info = AreaData.GetById(id);
  39. // return View(info);
  40. //}
  41. /// <summary>
  42. /// 获取所有的链接
  43. /// </summary>
  44. /// <returns></returns>
  45. [HttpPost]
  46. public JsonResult GetList(int page, int rows)
  47. {
  48. var czList = CzLinkData.GetPager(page, rows);
  49. var easyUIPages = new Dictionary<string, object>();
  50. easyUIPages.Add("total", czList.TotalItems);
  51. easyUIPages.Add("rows", czList.Items);
  52. return Json(easyUIPages, JsonRequestBehavior.AllowGet);
  53. }
  54. /// <summary>
  55. /// 保存
  56. /// </summary>
  57. [HttpPost, ValidateAntiForgeryToken]
  58. public JsonResult Edit(CzLink model)
  59. {
  60. var apiResult = new APIResult();
  61. try
  62. {
  63. CzLinkData.AddOrUpdate(model);
  64. }
  65. catch (Exception ex)
  66. {
  67. apiResult.Ret = -1;
  68. apiResult.Msg = ex.Message;
  69. if (!(ex is OperationExceptionFacade))
  70. LogFactory.GetLogger().Log(LogLevel.Error, ex);
  71. }
  72. return Json(apiResult);
  73. }
  74. /// <summary>
  75. /// 删除
  76. /// </summary>
  77. public ActionResult Delete(int id)
  78. {
  79. var apiResult = new APIResult();
  80. try
  81. {
  82. CzLinkData.Delete(id);
  83. }
  84. catch (Exception ex)
  85. {
  86. apiResult.Ret = -1;
  87. apiResult.Msg = ex.Message;
  88. if (!(ex is OperationExceptionFacade))
  89. LogFactory.GetLogger().Log(LogLevel.Error, ex);
  90. }
  91. return Json(apiResult);
  92. }
  93. }
  94. }