예제 #1
0
파일: CarDal.cs 프로젝트: CoryLiu/SaleCar
 public List<CarModel> GetAllCars(string status,int pageIndex, int pageSize)
 {
     try
     {
         List<CarModel> list=new List<CarModel>();
         IQueryable<Car> cars = context.Car.Where(c=>c.Statu==status).OrderBy(c => c.ID).Skip((pageIndex - 1) * pageSize).Take(pageSize);
         foreach (var car in cars)
         {
             CarModel model=new CarModel();
             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.UserInfo_ID = car.UserInfo_ID;
             model.Year = car.Year;
             list.Add(model);
         }
         return list;
     }
     catch (Exception)
     {
         return null;
     }
 }
예제 #2
0
 public void OwnCar(CarModel car)
 {
     if (Category.Any(category => category == car.Category) )
     {
         this.Car = car;
     }
     else
     {
         throw new NullReferenceException("У водителя нет прав данной категории");
     }
 }
예제 #3
0
파일: CarBll.cs 프로젝트: CoryLiu/SaleCar
 public int AddCar(int userID,string brandName,string carType,decimal price,string color,int year,string status)
 {
     var newCar = new CarModel();
     newCar.UserInfo_ID = userID;
     newCar.BrandName = brandName;
     newCar.CarType = carType;
     newCar.Price = price;
     newCar.Color = color;
     newCar.Year = year;
     newCar.Status = status;
     return dal.AddCar(newCar);
 }
예제 #4
0
파일: CarBll.cs 프로젝트: CoryLiu/SaleCar
 public int EditCar(int id,int userID, string brandName, string carType, decimal price, string color, int year, string status)
 {
     var editCar = new CarModel();
     editCar.ID = id;
     editCar.UserInfo_ID = userID;
     editCar.BrandName = brandName;
     editCar.CarType = carType;
     editCar.Price = price;
     editCar.Color = color;
     editCar.Year = year;
     editCar.Status = status;
     return dal.EditCar(editCar);
 }
예제 #5
0
        static void Main(string[] args)
        {
            var car = new CarModel("Лада",'D');
            Console.WriteLine("Автосалон приобрел автомобиль: {0}, Kатегории: {1}, Цвет: {2}\n", car.Model, car.Category,car.color.Name);

            car.color = Color.BlueViolet;
            Console.WriteLine("Автомобиль перекрашен в {0} цвет\n", car.color.Name);
            try
            {
            Console.WriteLine(car.CarPassport.Owner.Name);
            }
            catch (NullReferenceException ex)
            {
                Console.WriteLine("Невозможно вывести имя владельца Лады. Сообщение: {0}\n",ex.Message);
            }

            var driver = new DriverModel(new DateTime(2011,11,11), "Вольдемар" );

            Console.WriteLine("Нанят новый инструктор: {0} \n", driver.Name );
            driver.Category.Add('B');
            driver.Category.Add('C');
            Console.WriteLine("Инструктор Вольдемар имеет {0} {1} категории\n", driver.Category[0], driver.Category[1]);

            try
            {
                Console.WriteLine("Смена водителя Лады на Вольдемара;\n");
                car.ChangeOwner(driver, "о777о");
            }
            catch (NullReferenceException ex)
            {
                Console.WriteLine("Невозможно изменить водителя: {0};\n",ex.Message);

            }

            driver.Category.Add('D');
            Console.WriteLine("Вольдемар получил {0} категорию\n", driver.Category[2]);
            car.ChangeOwner(driver, "о777о");

            Console.WriteLine("Номер машины Вольдемара: {0}\n", car.CarNumber);

            Console.WriteLine("{0} владелец машины Лада\n", car.CarPassport.Owner.Name);
            Console.ReadLine();
        }
예제 #6
0
파일: CarDal.cs 프로젝트: CoryLiu/SaleCar
 public int EditCar(CarModel car)
 {
     try
     {
         int id = car.ID;
         var editCar = context.Car.FirstOrDefault(c => c.ID == id);
         editCar.BrandName = car.BrandName;
         editCar.CarType = car.CarType;
         editCar.Color = car.Color;
         editCar.Price = car.Price;
         editCar.Statu = car.Status;
         editCar.UserInfo_ID = car.UserInfo_ID;
         editCar.Year = car.Year;
         context.SaveChanges();
         return 1;
     }
     catch (Exception)
     {
         return 0;
     }
 }
예제 #7
0
파일: CarDal.cs 프로젝트: CoryLiu/SaleCar
 public int AddCar(CarModel car)
 {
     try
     {
         Car newCar=new Car();
         newCar.BrandName = car.BrandName;
         newCar.CarType = car.CarType;
         newCar.Color = car.Color;
         newCar.Price = car.Price;
         newCar.Statu = car.Status;
         newCar.UserInfo_ID = car.UserInfo_ID;
         newCar.Year = car.Year;
         context.AddToCar(newCar);
         context.SaveChanges();
         return 1;
     }
     catch (Exception)
     {
         return 0;
     }
 }
예제 #8
0
파일: CarDal.cs 프로젝트: CoryLiu/SaleCar
 public CarModel GetCarById(int id)
 {
     var car = context.Car.FirstOrDefault(c => c.ID == id);
     CarModel model=new CarModel();
     if (car != null)
     {
         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.UserInfo_ID = car.UserInfo_ID;
         model.Year = car.Year;
         return model;
     }
     else
     {
         return null;
     }
 }
예제 #9
0
파일: CarBll.cs 프로젝트: CoryLiu/SaleCar
 /// <summary>
 /// 根据出售者的ID获取该用户出售的所有车辆
 /// </summary>
 /// <param name="userid"></param>
 /// <returns></returns>
 public List<CarModel> GetCarsByUserId(int userid)
 {
     CarSaleEntities context=new CarSaleEntities();
     var cars=context.Car.Where(c => c.UserInfo_ID == userid);
     List<CarModel> list=new List<CarModel>();
     foreach (var car in cars)
     {
         CarModel model=new CarModel();
         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;
         list.Add(model);
     }
     return list;
 }
예제 #10
0
 public CarPassportModel(CarModel car)
 {
     Car = car;
 }