controller:
using System;
using System.Linq;using System.Web;
using System.Web.Mvc;
using System.Collections.Generic;
using LoanSystem.WEB.Controllers;
using LoanSystem.Common;
using Comm;
namespace LoanSystem.WEB.Areas.Home.Controllers
{
public class HelpCenterController : ReceBaseController
{
ZYXModel.DataEntities db = new ZYXModel.DataEntities();//数据上下文对象
public HelpCenterController()
: base(typeof(HelpCenterController))
{
}
/// <summary>
/// 前台首页
/// </summary>
/// <returns></returns>
public ActionResult Index(string helpTypeId = null, int page = 1)
{
var callback = Request.QueryString.Get("callback");//调试是否能获取前端数据
helpTypeId = StrHelper.Trim(helpTypeId);
if (String.IsNullOrEmpty(helpTypeId))
{
List<ZYXModel.ls_help_type> list = (from d in db.ls_help_type select d).ToList();
int typeCount = SqlDB.Count("ls_help_type");//数据表总记录条数
var r = Comm.JsonHelper.ToStr(new { result = true, typeList = list, typeCount });//把list集合,查询结果,数据条数等转化为json
return Content(string.IsNullOrEmpty(callback) ? r : string.Format("{0}({1})", callback, r));//把json数据返回前端
}
else
{
List<ZYXModel.ls_help_question> Questions = SqlDB.GetPage<ZYXModel.ls_help_question>("helpTypeId=" + helpTypeId, "id DESC", page, 5, "id", "[id],[questionDescribe],[helpTypeId]");
int pageCount = 5;
int questionCount = SqlDB.Count("ls_help_question", "helpTypeId=" + helpTypeId);
var r = Comm.JsonHelper.ToStr(new { result = true, Questions = Questions,questionCount,pageCount });
return Content(string.IsNullOrEmpty(callback) ? r : string.Format("{0}({1})", callback, r));
}
}
/// <summary>
/// 问题答案查看
/// </summary>
public ActionResult AnswerView(string helpQuestionId = "1")
{
var callback = Request.QueryString.Get("callback");
helpQuestionId = StrHelper.Trim(helpQuestionId);
ZYXModel.ls_help_answer model = SqlDB.GetOne<ZYXModel.ls_help_answer>(null, "[helpAnswer]", "helpQuestionId=" + helpQuestionId);
if (null != model)
{
SqlDB.UpdateByKey<ZYXModel.ls_help_answer>(model);
}
var r = Comm.JsonHelper.ToStr(new { result = true, answerModel = model });
return Content(string.IsNullOrEmpty(callback) ? r : string.Format("{0}({1})", callback, r));