public bool Save(risTabulky risContext) { bool success = false; try { if (id_stola == 0) // INSERT { this.FillEntity(); risContext.stol.Add(entityStol); risContext.SaveChanges(); id_stola = entityStol.id_stola; success = true; } else // UPDATE { var temp = from a in risContext.stol where a.id_stola == id_stola select a; entityStol = temp.Single(); this.FillEntity(); risContext.SaveChanges(); success = true; } } catch (Exception ex) { throw new ApplicationException(String.Format("{0}.{1}", this.GetType(), "Save()"), ex); } return(success); }
private void Reset() { id_stola = 0; pocet_miest = 0; objednavka = new List <BObjednavka>(); entityStol = new stol(); }
public BStol(stol s) { id_stola = s.id_stola; pocet_miest = s.pocet_miest; objednavka = new List <BObjednavka>(); foreach (var objednavka1 in s.objednavka) { BObjednavka pom = new BObjednavka(objednavka1); objednavka.Add(pom); } entityStol = s; }
static void Main(string[] args) { risTabulky risContext = new risTabulky(); stol stol = new stol { id_stola = 1, pocet_miest = 6 }; //insert risContext.stol.Add(stol); risContext.SaveChanges(); //update try { stol stolUpdate = new stol { id_stola = 8, pocet_miest = 10 }; risContext.stol.Attach(stolUpdate); var entry = risContext.Entry(stolUpdate); entry.State = EntityState.Modified; entry.Property(e => e.pocet_miest).IsModified = true; risContext.SaveChanges(); } catch (Exception ex) { Console.WriteLine(ex.InnerException.ToString()); } //delete stol stolDelete = risContext.stol.First(i => i.id_stola == stol.id_stola); risContext.stol.Remove(stolDelete); risContext.SaveChanges(); }
public bool Get(risTabulky risContext, int id) { bool success = false; try { var temp = from a in risContext.stol where a.id_stola == id select a; entityStol = temp.Single(); this.FillBObject(); success = true; } catch (Exception ex) { throw new ApplicationException(String.Format("{0}.{1}", this.GetType(), "Get()"), ex); } return(success); }