Ejemplo n.º 1
0
        public static void AddNewOffer(CarsInfo car, List <CarsFoto> fotos, Ownerinfo owner)
        {
            CarsSellingEntities context = new CarsSellingEntities();
            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();
        }
Ejemplo n.º 2
0
        public static void UpdateData(int carId)
        {
            CarsSellingEntities context = new CarsSellingEntities();

            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();
        }