12-控制器
using Yzs.Week04Car.BLL;
using Yzs.Week04Car.Entity;
using Newtonsoft.Json;
using System.IO;
public class CarHomeController : Controller
{
CarBLL bll = new CarBLL();
// GET: CarHome
public ActionResult Index()
{
return View();
}
public ActionResult Add()
{
return View();
}
public ActionResult AddImg()
{
return View();
}
public ActionResult CarList()
{
return View();
}
/// <summary>
/// 图片添加
/// </summary>
/// <param name="carImg"></param>
/// <returns></returns>
public int AddImged(CarImg carImg)
{
carImg.ImgTime = DateTime.Now;
return bll.AddImg(carImg);
}
public string GetCarImgType()
{
var dt = bll.GetCarImgType();
var json = JsonConvert.SerializeObject(dt);
return json;
}
/// <summary>
/// 添加房车信息
/// </summary>
/// <param name="car"></param>
/// <returns></returns>
public int CarAdd(Car car)
{
car.DataTable_Action_ = "Insert";
return bll.CarAdd(car);
}
/// <summary>
/// 汽车价格区间
/// </summary>
/// <returns></returns>
public string GetCarPinPai()
{
var dt = bll.GetCarPinPai();
var json = JsonConvert.SerializeObject(dt);
return json;
}
/// <summary>
/// 汽车价格区间
/// </summary>
/// <returns></returns>
public string GetCarPrice()
{
var dt = bll.GetCarPrice();
var json = JsonConvert.SerializeObject(dt);
return json;
}
/// <summary>
/// 汽车类型
/// </summary>
/// <returns></returns>
public string GetCarXingType()
{
var dt = bll.GetCarXingType();
var json = JsonConvert.SerializeObject(dt);
return json;
}
/// <summary>
/// 汽车分组
/// </summary>
/// <returns></returns>
public string GetCarGroup()
{
var dt = bll.GetCarGroup();
var json = JsonConvert.SerializeObject(dt);
return json;
}
public string Imgs()
{
HttpPostedFileBase http = Request.Files[0];
var path = Server.MapPath("" + Path.DirectorySeparatorChar + "Images" + Path.DirectorySeparatorChar + "");
if (!Directory.Exists(path))
Directory.CreateDirectory(path);
var name = http.FileName;
var newpath = Path.Combine(path, name);
http.SaveAs(newpath);
return "/Images/"+name;
}
public string Imgsed()
{
HttpPostedFileBase http = Request.Files[0];
if (http != null)
{
var path = Server.MapPath("" + Path.DirectorySeparatorChar + "Images" + Path.DirectorySeparatorChar + "");
if (!Directory.Exists(path))
Directory.CreateDirectory(path);
var name = http.FileName;
var newpath = Path.Combine(path, name);
http.SaveAs(newpath);
return "/Images/" + name;
}
else
return "0";
}
public string GetImgList(int pageindex = 1, string name = "")
{
var result = bll.GetImgList(pageindex,name);
var json = JsonConvert.SerializeObject(result);
return json;
}
public int Delete(int id)
{
return bll.Delete(id);
}
public string GetCarList(int pageindex = 1, string name = "")
{
var result = bll.GetCarList(pageindex, name);
var json = JsonConvert.SerializeObject(result);
return json;
}
}