using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Net.Http;
using System.Web.Http;
using EFDAL;
using DataModel;
using ServiceStack.Redis;
namespace EFExame_API.Controllers
{
public class WuLianWangController : ApiController
{
XueYuanClass dal = new XueYuanClass();
/// <summary>
/// 获取数据并存到redis里面
/// </summary>
/// <returns></returns>
[HttpGet]
[Route("api/GetWuLianWang")]
public List<WuLianWangInfo> WlWinfos(string name = "")
{
//定义变量list接受返回的集合
var list = new List<WuLianWangInfo>();
//定义redis
RedisClient redis = new RedisClient("127.0.0.1");
//将Redis赋值给list
list = redis.Get<List<WuLianWangInfo>>("products");
//判断Redis是否为空或者他的个数是否为0
if (list == null || list.Count == 0)
{
list = dal.WlWInfos(name);
redis.Set("products", list);
}
return list;
}
/// <summary>
/// 删除数据
/// </summary>
/// <param name="id"></param>
/// <returns></returns>
[HttpGet]
[Route("api/DeleInfo")]
public int DeletId(int id)
{
return dal.DeleInfo(id);
}
/// <summary>
/// 修改数据
/// </summary>
/// <param name="wuLianWang"></param>
/// <returns></returns>
[HttpPost]
[Route("api/UpdateInfo")]
public int UpdateInfo(WuLianWangInfo wuLianWang)
{
return dal.UpdateInfo(wuLianWang);
}
/// <summary>
/// 根据Id获取数据
/// </summary>
/// <param name="Id"></param>
/// <returns></returns>
[HttpGet]
[Route("api/GetId")]
public WuLianWangInfo FanTian(int Id)
{
return dal.FanTian(Id);
}
/// <summary>
/// 添加数据
/// </summary>
/// <param name="WuLian"></param>
/// <returns></returns>
[HttpPost]
[Route("api/AddInfo")]
public int AddInfo(WuLianWangInfo WuLian)
{
return dal.AddInfo(WuLian);
}
/// <summary>
/// 调用分页存储过程
/// </summary>
/// <param name="Pageindex"></param>
/// <param name="Pagesize"></param>
/// <returns></returns>
[HttpPost]
[Route("api/PageProc")]
public List<WuLianWangInfo> WPageProc(int Pageindex = 1, int Pagesize = 2)
{
return dal.WPageProc(Pageindex, Pagesize);
}
}
}
原文:https://www.cnblogs.com/li1999/p/13446052.html