public bool Save(risTabulky risContext) { bool success = false; try { var temp = from a in risContext.preklad where a.kod_jazyka == kod_jazyka && a.text_id == text_id select a; if (!temp.Any()) // INSERT { this.FillEntity(); risContext.preklad.Add(entityPreklad); risContext.SaveChanges(); success = true; } else // UPDATE { entityPreklad = temp.Single(); this.FillEntity(); risContext.SaveChanges(); success = true; } } catch (Exception ex) { throw new ApplicationException(String.Format("{0}.{1}", this.GetType(), "Save()"), ex); } return(success); }
public bool Save(risTabulky risContext) { bool success = false; try { if (kod_jazyka == "") // INSERT { this.FillEntity(); risContext.jazyk.Add(entityJazyk); risContext.SaveChanges(); success = true; } else // UPDATE { var temp = from a in risContext.jazyk where a.kod_jazyka == kod_jazyka select a; entityJazyk = temp.Single(); this.FillEntity(); risContext.SaveChanges(); success = true; } } catch (Exception ex) { throw new ApplicationException(String.Format("{0}.{1}", this.GetType(), "Save()"), ex); } return(success); }
public bool Save(risTabulky risContext) { bool success = false; try { var temp = from a in risContext.otvaracie_hodiny where a.id_podniku == id_podniku && a.cislo_dna == cislo_dna select a; if (!temp.Any()) // INSERT { this.FillEntity(); risContext.otvaracie_hodiny.Add(entityOtvaracieHodiny); risContext.SaveChanges(); success = true; } else // UPDATE { entityOtvaracieHodiny = temp.Single(); this.FillEntity(); risContext.SaveChanges(); success = true; } } catch (Exception ex) { throw new ApplicationException(String.Format("{0}.{1}", this.GetType(), "Save()"), ex); } return(success); }
public bool Save(risTabulky risContext) { bool success = false; try { if (zaciatok_platnosti == DateTime.MinValue) // INSERT { this.FillEntity(); risContext.zmena_otvaracich_hodin.Add(entityZmenaOtvaracichHodin); risContext.SaveChanges(); success = true; } else // UPDATE { var temp = from a in risContext.zmena_otvaracich_hodin where a.zaciatok_platnosti == zaciatok_platnosti select a; entityZmenaOtvaracichHodin = temp.Single(); this.FillEntity(); risContext.SaveChanges(); this.FillBObject(); success = true; } } catch (Exception ex) { throw new ApplicationException(String.Format("{0}.{1}", this.GetType(), "Save()"), ex); } return(success); }
public bool Save(risTabulky risContext) { bool success = false; try { if (id_menu == 0) // INSERT { this.FillEntity(); risContext.denne_menu.Add(entityDenneMenu); risContext.SaveChanges(); id_menu = entityDenneMenu.id_menu; success = true; } else // UPDATE { var temp = from a in risContext.denne_menu where a.id_menu == id_menu select a; entityDenneMenu = temp.Single(); this.FillEntity(); risContext.SaveChanges(); success = true; } } catch (Exception ex) { throw new ApplicationException(String.Format("{0}.{1}", this.GetType(), "Save()"), ex); } return(success); }
public bool Save(risTabulky risContext) { bool success = false; try { if (typ_platnosti == 0) // INSERT { this.FillEntity(); risContext.platnost_zaznamu.Add(entityPlatnostZaznamu); risContext.SaveChanges(); typ_platnosti = entityPlatnostZaznamu.typ_platnosti; success = true; } else // UPDATE { var temp = from a in risContext.platnost_zaznamu where a.typ_platnosti == typ_platnosti select a; entityPlatnostZaznamu = temp.Single(); this.FillEntity(); risContext.SaveChanges(); success = true; } } catch (Exception ex) { throw new ApplicationException(String.Format("{0}.{1}", this.GetType(), "Save()"), ex); } return(success); }
public bool Save(risTabulky risContext) { bool success = false; try { if (id_typu == -1) // INSERT { this.FillEntity(); risContext.typ_jedla.Add(entityTypJedla); risContext.SaveChanges(); this.FillBObject(); success = true; } else // UPDATE { var temp = from a in risContext.typ_jedla where a.id_typu == id_typu select a; entityTypJedla = temp.Single(); this.FillEntity(); risContext.SaveChanges(); success = true; } } catch (Exception ex) { throw new ApplicationException(String.Format("{0}.{1}", this.GetType(), "Save()"), ex); } return(success); }
public bool Save(risTabulky risContext) { bool success = false; try { var temp = from a in risContext.objednavka_menu where a.id_objednavky == id_objednavky && a.id_menu == id_menu select a; if (!temp.Any()) // INSERT { this.FillEntity(); risContext.objednavka_menu.Add(entityObjednavkaMenu); risContext.SaveChanges(); success = true; } else // UPDATE { entityObjednavkaMenu = temp.Single(); this.FillEntity(); risContext.SaveChanges(); success = true; } } catch (Exception ex) { throw new ApplicationException(String.Format("{0}.{1}", this.GetType(), "Save()"), ex); } return(success); }
public bool Save(risTabulky risContext) { bool success = false; try { if (text_id == 0) // INSERT { this.FillEntity(); risContext.text.Add(entityText); risContext.SaveChanges(); text_id = entityText.text_id; //treba ostestovat automaticke vygenerovanie id po ulozeni success = true; } else // UPDATE { var temp = from a in risContext.text where a.text_id == text_id select a; entityText = temp.Single(); this.FillEntity(); risContext.SaveChanges(); success = true; } } catch (Exception ex) { throw new ApplicationException(String.Format("{0}.{1}", this.GetType(), "Save()"), ex); } return(success); }
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(); }
/// <summary> /// Vytvorí novú entitu jedla podľa parametrov a uloží do databázy ak parameter risTabuľky nie je NULL /// </summary> /// <param name="nazov">Názov jedla</param> /// <param name="typ_jedla">Typ jedla</param> /// <param name="mnostvoKalorii">Množstvo kalorii jedla</param> /// <param name="dlzka_pripravy">Dĺžka prípravy jedla</param> /// <param name="risContext"></param> public BJedlo(BText nazov, BTyp_jedla typ_jedla, int mnostvoKalorii, int dlzka_pripravy, risTabulky risContext) { entity = new jedlo(); entity.id_typu = typ_jedla.id_typu; entity.nazov = nazov.text_id; entity.mnozstvo_kalorii = mnostvoKalorii; entity.dlzka_pripravy = dlzka_pripravy; if (risContext != null) { risContext.jedlo.Add(entity); risContext.SaveChanges(); } }
/// <summary> /// Vytvorí novú entitu jedla podľa parametrov a uloží do databázy ak parameter risTabuľky nie je NULL /// </summary> /// <param name="id_nazvu">id textu nazov jedla</param> /// <param name="id_typu">id typu jedla</param> /// <param name="mnozstvoKalorii">množstvo kalorii jedla</param> /// <param name="dlzka_pripravy">dĺžka prípravy jedla</param> /// <param name="risContext">kontext databázy</param> public BJedlo(int id_nazvu, int id_typu, int?mnozstvoKalorii, int?dlzka_pripravy, risTabulky risContext) { entity = new jedlo(); entity.id_typu = id_typu; entity.nazov = id_nazvu; entity.mnozstvo_kalorii = mnozstvoKalorii; entity.dlzka_pripravy = dlzka_pripravy; if (risContext != null) { risContext.jedlo.Add(entity); risContext.SaveChanges(); } }
/// <summary> /// Uloží zmeny do databázy /// </summary> /// <param name="risContext">kontext databázy</param> /// <returns></returns> public bool Save(risTabulky risContext) { bool success = false; try { risContext.SaveChanges(); } catch (Exception ex) { throw new ApplicationException(String.Format("{0}.{1}", this.GetType(), "Save()"), ex); } return(success); }
/// <summary> /// Metóda zmaže aktuálnu surovinu z databázy /// </summary> /// <param name="risContext">Kontext databázy</param> /// <returns> /// <c>TRUE</c> , ak došlo k úspešnému vymazaniu /// <c>FALSE</c> , ak nedošlo k úspešenému vymazaniu /// </returns> public bool Del(risTabulky risContext) { bool result = false; if (jedlo_surovina.Count > 0 || napoj_surovina.Count > 0) { entitySurovina.platna = 0; Save(risContext); result = true; } else { risContext.surovina.Remove(entitySurovina); risContext.SaveChanges(); Reset(); result = true; } return(result); }
public bool Del(risTabulky risContext) { bool success = false; try { var temp = risContext.platnost_zaznamu.First(i => i.typ_platnosti == typ_platnosti); risContext.platnost_zaznamu.Remove(temp); risContext.SaveChanges(); Reset(); success = true; } catch (Exception ex) { throw new ApplicationException(String.Format("{0}.{1}", this.GetType(), "Del()"), ex); } return(success); }
public bool Del(risTabulky risContext) { bool success = false; try { var temp = risContext.otvaracie_hodiny.First(i => i.id_podniku == id_podniku && i.cislo_dna == cislo_dna); risContext.otvaracie_hodiny.Remove(temp); risContext.SaveChanges(); Reset(); success = true; } catch (Exception ex) { throw new ApplicationException(String.Format("{0}.{1}", this.GetType(), "Del()"), ex); } return(success); }
public bool Del(risTabulky risContext) { bool success = false; try { var temp = risContext.preklad.First(i => i.kod_jazyka == kod_jazyka && i.text_id == text_id); risContext.preklad.Remove(temp); risContext.SaveChanges(); Reset(); success = true; } catch (Exception ex) { throw new ApplicationException(String.Format("{0}.{1}", this.GetType(), "Del()"), ex); } return(success); }
public bool Del(risTabulky risContext) { bool success = false; try { var temp = risContext.objednavka_menu.First(i => i.id_objednavky == id_objednavky && i.id_menu == id_menu); risContext.objednavka_menu.Remove(temp); risContext.SaveChanges(); Reset(); success = true; } catch (Exception ex) { throw new ApplicationException(String.Format("{0}.{1}", this.GetType(), "Del()"), ex); } return(success); }
/// <summary> /// Vymaže dané jedlo z databázy /// </summary> /// <param name="risContext">kontext databázy</param> /// <returns></returns> public bool Del(risTabulky risContext) { bool success = false; try { var temp = risContext.jedlo.First(i => i.id_jedla == ID); risContext.jedlo.Remove(temp); risContext.SaveChanges(); success = true; this.Reset(); } catch (Exception ex) { throw new ApplicationException(String.Format("{0}.{1}", this.GetType(), "Del()"), ex); } return(success); }
public bool Del(risTabulky risContext) { bool success = false; try { var temp = risContext.zmena_otvaracich_hodin.First(i => i.zaciatok_platnosti == zaciatok_platnosti); risContext.zmena_otvaracich_hodin.Remove(temp); risContext.SaveChanges(); success = true; this.Reset(); } catch (Exception ex) { throw new ApplicationException(String.Format("{0}.{1}", this.GetType(), "Del()"), ex); } return(success); }
public void updatefromTransferObject(TransferEntity transferEntity, risTabulky risContext) { if (transferEntity.GetType() == typeof(TJedlo)) { TJedlo jedlo = (TJedlo)transferEntity; if (jedlo.Id.HasValue) { if (!jedlo.DlzkaPripravy.Equals(dlzka_pripravy)) { entity.dlzka_pripravy = jedlo.DlzkaPripravy; } if (!jedlo.IdTypu.Equals(typ_jedla.id_typu)) { entity.id_typu = jedlo.IdTypu; } if (!jedlo.MnozstvoKalorii.Equals(mnozstvo_kalorii)) { entity.mnozstvo_kalorii = jedlo.MnozstvoKalorii; } foreach (var surovina in suroviny_jedla) { TSurovina tempSurovina = jedlo.ZoznamSurovin.First(p => p.Id == surovina.id_surovina); if (tempSurovina != null) { if (!surovina.mnozstvo.Equals(tempSurovina.Mnozstvo)) { surovina.mnozstvo = tempSurovina.Mnozstvo; } } else { entity.jedlo_surovina.Remove(surovina.entityJedloSurovina); } } foreach (var surovina in jedlo.ZoznamSurovin) { jedlo_surovina temp_bsurovina = entity.jedlo_surovina.First(p => p.id_surovina == surovina.Id); if (temp_bsurovina == null) { entity.jedlo_surovina.Add(risContext.jedlo_surovina.First(p => p.id_surovina == surovina.Id)); } } foreach (var preklad in jedlo.Preklady) { preklad temp_preklad = entity.text.preklad.First(p => p.kod_jazyka.Equals(preklad.Key)); if (temp_preklad == null) { preklad prkl = new preklad(); prkl.kod_jazyka = preklad.Key; prkl.preklad1 = preklad.Value; prkl.text = nazov.entityText; risContext.preklad.Add(prkl); entity.text.preklad.Add(prkl); } else { temp_preklad.preklad1 = preklad.Value; } } foreach (var preklad in nazov.preklad) { String temp_preklad = jedlo.Preklady.Keys.First(p => p.Equals(preklad.kod_jazyka)); if (temp_preklad == null) { nazov.preklad.Remove(preklad); } } risContext.SaveChanges(); } else { this.Reset(); entity = new jedlo(); entity.mnozstvo_kalorii = jedlo.MnozstvoKalorii; entity.dlzka_pripravy = jedlo.DlzkaPripravy; foreach (var suroviny in jedlo.ZoznamSurovin) { surovina surovinaTemp = risContext.surovina.First(p => p.id_surovina == suroviny.Id); if (surovinaTemp != null) { jedlo_surovina tempJedloSurovina = new jedlo_surovina(); tempJedloSurovina.jedlo = entity; tempJedloSurovina.surovina = surovinaTemp; tempJedloSurovina.mnozstvo = suroviny.Mnozstvo; entity.jedlo_surovina.Add(tempJedloSurovina); } } } } }