public static List <CarsInfo> GetAllOfferswithSoledOffers() { List <CarsInfo> infos = new List <CarsInfo>(); CarsSellingEntities1 context = new CarsSellingEntities1(); foreach (TbCarsInfo info in context.TbCarsInfoes) { CarsInfo car = new CarsInfo(); car.Modell = info.Modell; car.Adress = info.Adress; car.Status = info.Status; car.Price = Convert.ToDouble(info.Price); car.Insurance = Convert.ToDateTime(info.Insurance); car.Id = info.Id; car.Sold = info.Sold.Value; foreach (TbCarsFoto foto in context.TbCarsFotoes) { if (foto.CarId == info.Id) { car.DisplayFoto = foto.Foto; break; } } infos.Add(car); } return(infos); }
public static void AddNewOffer(CarsInfo car, List <CarsFoto> fotos, Ownerinfo owner) { CarsSellingEntities1 context = new CarsSellingEntities1(); TbCarsInfo newcar = new TbCarsInfo(); newcar.Modell = car.Modell; newcar.Status = car.Status; newcar.Insurance = car.Insurance; newcar.Adress = car.Adress; newcar.Price = car.Price; newcar.Sold = car.Sold; context.TbCarsInfoes.Add(newcar); context.SaveChanges(); int id = newcar.Id; foreach (CarsFoto carsFoto in fotos) { TbCarsFoto newCarsFoto = new TbCarsFoto(); newCarsFoto.CarId = id; newCarsFoto.Foto = carsFoto.Foto; context.TbCarsFotoes.Add(newCarsFoto); context.SaveChanges(); } TbOwnersInfo newowner = new TbOwnersInfo(); newowner.Vorname = owner.Vorname; newowner.nachname = owner.Nachname; byte[] telephonenumber = Encoding.ASCII.GetBytes(owner.Telephonenumber); newowner.TelephoneNumber = telephonenumber; newowner.EmailAdress = owner.Emailadress; newowner.CarId = id; context.TbOwnersInfoes.Add(newowner); context.SaveChanges(); }