3-商品管理Co

using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using MEH.Month.Test.BLL;
using MEH.Month.Test.Model;
using MEH.Month.Test.Models;
using System.Linq.Expressions;
using Newtonsoft.Json;
using MEH.Month.Test.Unit;

namespace MEH.Month.Test.Controllers
{
public class HomeController : Controller
{
// GET: Home
public ActionResult Index()
{
return View();
}
[HttpGet]
public string Show(int PageIndex, int PageSize, string Name, int State)
{
Expression<Func<ProductInfo, bool>> expression = t => true;
if (Name != "")
{
expression = expression.And(t => t.ProductTitle.Contains(Name));
}
if (State!=-1)
{
expression = expression.And(t => t.State.Equals(State));
}
List<ProductInfo> List = new CommonBLL().Show(expression).ToList();
ViewModel vm = new ViewModel();
vm.PageCount = List.Count();
List=List.Skip((PageIndex - 1) * PageSize).Take(PageSize).ToList();
vm.List = List;
return JsonConvert.SerializeObject(vm);
}

public ActionResult Add()
{
return View();

}
public ActionResult Update(int ID)
{
ProductInfo List = new CommonBLL().Fill(ID);
return View(List);

}
[HttpPost]
[ValidateInput(false)]
public ActionResult UpdateData(ProductInfo m)
{
m.State = 1;
if (new CommonBLL().Update(m) < 1)
{
return Content("<script>alert('修改出现错误')</script>");
}
return Content("<script>alert('修改成功');location.href='/Home/Index'</script>");
}

[HttpPost]
[ValidateInput(false)]
public ActionResult Insert(ProductInfo m)
{
m.State = 1;
if (new CommonBLL().Add(m) < 1)
{
return Content("<script>alert('添加出现错误')</script>");
}
return Content("<script>alert('添加成功');location.href='/Home/Index'</script>");
}
/// <summary>
/// 上传文件
/// </summary>
/// <returns></returns>
[HttpPost]

public JsonResult UpLoadFiles()
{
string Path = Server.MapPath("/Files");
if (!Directory.Exists(Path))
{
Directory.CreateDirectory(Path);
}
HttpFileCollectionBase Files = Request.Files;
IList<string> ImgList = new List<string>();
for (int i = 0; i < Files.Keys.Count; i++)
{
var EveFiles = Request.Files[i];
string ImgPath = Path + "/" + EveFiles.FileName;
EveFiles.SaveAs(ImgPath);
ImgList.Add(EveFiles.FileName);
}
return Json(ImgList, JsonRequestBehavior.AllowGet);
}
public int Del(int ID )
{
return new CommonBLL().Del(ID);
}
[HttpGet]
public int UpdateState(int ID,int State)
{

return new CommonBLL().UpdateState(ID,State);

}
[HttpPost]
public int Dels(string IDs)
{
return new CommonBLL().Dels(IDs);
}


}
}

posted @ 2018-12-20 09:34  平生。  阅读(74)  评论(0编辑  收藏  举报