/// <summary> /// 新添加一条车辆出售记录 /// </summary> /// <param name="brand"></param> /// <param name="carType"></param> /// <param name="price"></param> /// <param name="color"></param> /// <param name="year"></param> /// <returns></returns> public ActionResult AddCar(string brand,string carType,decimal price,string color,int year) { var session = Session["logID"]; if (session==null) { return RedirectToAction("Login", "Home"); } else { //================================================================= int userid = Int32.Parse(session.ToString()); CarBll bll=new CarBll(); int result = bll.AddCar(userid, brand, carType, price, color, year, "在售"); if (result==1) { CarSaleEntities context=new CarSaleEntities(); var car = context.Car.OrderByDescending(c => c.ID).First(); int carid = car.ID;//获取车辆ID HttpPostedFileBase file = Request.Files["file1"];//获取提交上来的图片文件 //存入文件 if (file.ContentLength > 0) { file.SaveAs(Server.MapPath("~/CarImgs/") + System.IO.Path.GetFileName(file.FileName)); string url = System.IO.Path.GetFileName(file.FileName); CarImgBll imgBll = new CarImgBll(); imgBll.AddCarImg(carid, url); return RedirectToAction("MyCars"); } else { return RedirectToAction("Failed", "PageHelper"); } } else { return RedirectToAction("Failed", "PageHelper"); } } }
public ActionResult AddToOrder(int carid) { var session = Session["logID"]; int userid = Int32.Parse(session.ToString()); OrderBll orderBll=new OrderBll(); CarBll carBll=new CarBll(); var car=carBll.GetCarById(carid); OrderModel newOrder=new OrderModel(); newOrder.BuyManID = userid; newOrder.CarID = carid; newOrder.Price = car.Price; newOrder.Date = DateTime.Now; newOrder.SaleManID = car.UserInfo_ID; int result=orderBll.AddOrder(newOrder); if (result==1) { return RedirectToAction("MyOrder", "Home"); } else { return RedirectToAction("Failed", "PageHelper"); } }
/// <summary> /// 获取该用户的全部出售车辆 /// </summary> /// <returns></returns> public ActionResult MyCars() { var session = Session["logID"]; if (session == null) { return RedirectToAction("Login", "Home"); } else { int userid = Int32.Parse(session.ToString()); CarBll bll=new CarBll(); var result=bll.GetCarsByUserId(userid); return View(result); } }
/// <summary> /// 卖家同意出售给购买人。 /// </summary> /// <returns></returns> public ActionResult OKToSale(int id) { OrderBll orderBll=new OrderBll(); var order = orderBll.GetOrderById(id); DealBll dealBll=new DealBll(); DealModel newDeal=new DealModel(); newDeal.BuyManID = order.BuyManID; newDeal.CarID = order.CarID; newDeal.Price = order.Price; newDeal.SaleManID = order.SaleManID; newDeal.Time = DateTime.Now; dealBll.AddDeal(newDeal);//添加到成交记录 CarBll carBll = new CarBll();//车辆信息修改为已售 carBll.ChageCarStatusToSold(order.CarID); orderBll.RemoveOrder(id);//从订单记录中删除 return RedirectToAction("MyOrders", "SaleMan"); }
/// <summary> /// 主页展示出售车辆列表 /// </summary> /// <returns></returns> public ActionResult Index() { CarSaleEntities context = new CarSaleEntities(); List<TempCar> list=new List<TempCar>(); CarBll carBll=new CarBll(); IndexViewModel viewModel=new IndexViewModel(); var cars=carBll.GetAllCars("在售", 1, 10); foreach (var car in cars) { TempCar model=new TempCar(); int userid = car.UserInfo_ID; var user=context.UserInfo.FirstOrDefault(u => u.ID == userid); var img = context.CarImg.FirstOrDefault(i => i.CarID == car.ID); model.ID = car.ID; model.BrandName = car.BrandName; model.CarType = car.CarType; model.Color = car.Color; model.Price = car.Price; model.Status = car.Status; model.Year = car.Year; if (user != null) model.UserName = user.RealName; if (img != null) model.imgUrl = img.Imgurl; list.Add(model); } viewModel.cars = list; viewModel.queryStr = " "; return View(viewModel); }
/// <summary> /// 查看详情页面 /// </summary> /// <param name="id"></param> /// <returns></returns> public ActionResult Details(int id) { CarSaleEntities context=new CarSaleEntities(); CarBll bll=new CarBll(); var car=bll.GetCarById(id); int userid = car.UserInfo_ID; var user = context.UserInfo.FirstOrDefault(u => u.ID == userid); DetailViewModel model=new DetailViewModel(); model.CarID = id; model.BrandName = car.BrandName; model.CarType = car.CarType; model.Phone = user.Phone; model.Price = car.Price; model.Status = car.Status; model.Year = car.Year; model.UserName = user.RealName; var img=context.CarImg.FirstOrDefault(c => c.CarID == id); model.imgUrl = img.Imgurl; return View(model); }