예제 #1
0
        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();
        }
예제 #2
0
        public static void UpdateData(int carId)
        {
            CarsSellingEntities1 context = new CarsSellingEntities1();

            foreach (TbCarsInfo carsInfo in context.TbCarsInfoes)
            {
                if (carsInfo.Id == carId)
                {
                    carsInfo.Sold = true;
                    context.TbCarsInfoes.AddOrUpdate(carsInfo);
                    TbSellingInfo sellinfo = new TbSellingInfo();
                    sellinfo.CarId        = carId;
                    sellinfo.SellingPrice = carsInfo.Price;
                    sellinfo.Profit       = 5 * carsInfo.Price / 100;
                    sellinfo.SellingDate  = DateTime.Now;
                    context.TbSellingInfoes.AddOrUpdate(sellinfo);
                    break;
                }
            }

            context.SaveChanges();
        }