Ejemplo n.º 1
0
        public static bool RemoveVehicle(int idVehicle)
        {
            POJAZDY vehicle = new POJAZDY()
            {
                idPojazd = idVehicle
            };

            using (var entities = new DBEntities())
            {
                try
                {
                    entities.POJAZDY.Attach(vehicle);
                    entities.POJAZDY.Remove(vehicle);
                    entities.SaveChanges();
                }
                catch (Exception)
                {
                    if (!entities.POJAZDY.Any(p => p.idPojazd == idVehicle))
                    {
                        return(false);
                    }
                }
            }

            return(true);
        }
Ejemplo n.º 2
0
        public static bool AddVehicle(POJAZDY newVehile)
        {
            using (var entities = new DBEntities())
            {
                var licences = new List <KATEGORIEPJAZDY>();
                foreach (var lic in newVehile.KATEGORIEPJAZDY)
                {
                    var licence = entities.KATEGORIEPJAZDY.First(k => k.idKatPJ == lic.idKatPJ);
                    licences.Add(licence);
                }

                newVehile.KATEGORIEPJAZDY = licences;

                if (newVehile.MARKI_idMarki == 0)
                {
                    var brandID = CarBrandService.GetCarBrandId(newVehile.MARKA_Nazwa);
                    if (brandID == -1)
                    {
                        brandID = CarBrandService.AddCarBrand(new MARKI()
                        {
                            Nazwa = newVehile.MARKA_Nazwa
                        });
                    }

                    newVehile.MARKI_idMarki = brandID;
                }

                entities.POJAZDY.Add(newVehile);
                entities.SaveChanges();

                return(true);
            }
        }
Ejemplo n.º 3
0
 public VehicleListGrid(POJAZDY pojazd)
 {
     idPojazd = pojazd.idPojazd;
     Marka    = pojazd.MARKI.Nazwa;
     SetRodzaj(pojazd.Rodzaj);
     NrRejestr = pojazd.NrRejestr;
     ZaGodz    = pojazd.ZaGodz.ToString("C");
     Sprawny   = pojazd.Sprawny == 0 ? "Nie" : "Tak";
 }
Ejemplo n.º 4
0
        public static bool UpdateVehicle(POJAZDY updateVehicle)
        {
            using (var entities = new DBEntities())
            {
                var vehicle = entities.POJAZDY
                              .First(v => v.idPojazd == updateVehicle.idPojazd);

                entities.Entry(vehicle).CurrentValues.SetValues(updateVehicle);
                if (updateVehicle.ZDJECIA.First()?.idZdjecia == 0)
                {
                    entities.ZDJECIA.Add(updateVehicle.ZDJECIA.First());
                }

                entities.SaveChanges();

                return(true);
            }
            return(false);
        }
Ejemplo n.º 5
0
        private void button3_Click(object sender, EventArgs e)
        {
            //edycja
            firma.NAZWA_FIRMY = this.textBox1.Text;
            firma.NIP         = this.textBox2.Text;

            foreach (Control control in this.panel1.Controls)
            {
                if (control is TextBox)
                {
                    TextBox textBox = (TextBox)control;
                    if (!textBox.Name.Contains("text"))
                    {
                        POJAZDY pojazd = firma.POJAZDY.Where(poj => poj.ID_POJAZDU == int.Parse(textBox.Name)).First();
                        pojazd.NUMER_REJESTRACYJNY = textBox.Text;
                    }
                }
            }

            //usuwanie
            //db.FIRMY.Remove(firma);
            db.SaveChanges();
        }