using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Net.Http;
using System.Web.Http;
using DAL;
using Models;
namespace _1711B.Shopping.Controllers
{
public class ShoppingController : ApiController
{
ShoppingDAL dal = new ShoppingDAL();
//Linq分页显示加查询
public pageModel Get(int pageSize = 3, int currentPage = 1, string yhfs = “”, string hxzt = “”, string mc = “”)
{
if (currentPage<1)
{
currentPage = 1;
}
var list = dal.Show();
if (!string.IsNullOrEmpty(yhfs))
{
list = list.Where(s=>s.yhfsyhfs).ToList();
}
if (!string.IsNullOrEmpty(hxzt))
{
list = list.Where(s=>s.hxzthxzt).ToList();
}
if (!string.IsNullOrEmpty(mc))
{
list = list.Where(s => s.mc.Contains(mc)).ToList();
}
var count = list.Count();
int page;
if (count % pageSize==0)
{
page = count / pageSize;
}
else
{
page = count / pageSize + 1;
}
if (currentPage>page)
{
currentPage = page;
}
list = list.Skip((currentPage - 1) * pageSize).Take(pageSize).ToList();
var m = new pageModel();
m.list = list;
m.totalCount = count;
m.totalPage = page;
m.currentPage = currentPage;
return m;
}
//添加
public int Post([FromBody]yhjModels m)
{
if (m.sysjCheck == 1)
{
m.ksrq = DateTime.Now;
m.jsrq = DateTime.Now.AddDays(m.sysjAdd);
}
return dal.Add(m);
}
}
}