Exemple #1
0
        public ActionResult Query(string condition)
        {
            CarSaleEntities context = new CarSaleEntities();
            List<TempCar> list = new List<TempCar>();

            IndexViewModel viewModel = new IndexViewModel();
            var cars =
                context.Car.Where(
                    c => c.BrandName.Contains(condition) || c.CarType.Contains(condition) || c.Color.Contains(condition));//根据输入的条件进行近似查找
            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.Statu;
                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);
        }
Exemple #2
0
 /// <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);
 }