Esempio n. 1
0
        public static List <CarImg> GetAllCars()
        {
            try
            {
                using (var ctx = new carShopEntities())
                {
                    List <CarImg> carImgs = new List <CarImg>();


                    foreach (var item in ctx.Cars)
                    {
                        CarImg carImg = new CarImg
                        {
                            Car = item
                        };

                        List <Image> images = (from query in ctx.Images where query.CarId == item.CarId select query).ToList();
                        carImg.Images = images;
                        carImgs.Add(carImg);
                    }
                    return(carImgs);
                }
            }
            catch (Exception)
            {
                return(null);
            }
        }
Esempio n. 2
0
        public static CarImg GetCarById(int id)
        {
            try
            {
                using (var ctx = new carShopEntities())
                {
                    CarImg carImgs = new CarImg();
                    Car    carItem = (from query in ctx.Cars where query.CarId == id select query).First();
                    carImgs.Car = carItem;
                    List <Image> images = (from query in ctx.Images where query.CarId == id select query).ToList();
                    carImgs.Images = images;


                    return(carImgs);
                }
            }
            catch (Exception)
            {
                return(null);
            }
        }