public Country AddCountry(Country cou) { using (SummitDBEntity summit = new SummitDBEntity()) { var count = summit.Countries .Where(s => s.Name == cou.Name) .Count(); if (count == 0) { summit.Countries.Add(cou); summit.SaveChanges(); } } return(cou); }
public Summit AddSummit(Summit sum) { using (SummitDBEntity summit = new SummitDBEntity()) { var count = summit.Summits .Where(s => s.Name == sum.Name) .Count(); if (count == 0) { summit.Summits.Add(sum); summit.SaveChanges(); } } return(sum); }
public Voice AddVoice(Voice vo) { using (SummitDBEntity summit = new SummitDBEntity()) { var count = summit.Voices .Where(s => s.User_ID == vo.User_ID) .Where(s => s.Variant_ID == vo.Variant_ID) .Count(); if (count == 0) { summit.Voices.Add(vo); summit.SaveChanges(); } return(vo); } }
public Variant AddVariant(Variant va) { using (SummitDBEntity summit = new SummitDBEntity()) { var count = summit.Variants .Where(s => s.User_ID == va.User_ID) .Where(s => s.Summit_ID == va.Summit_ID) .Where(s => s.Country_ID == va.Country_ID) .Count(); if (count == 0) { summit.Variants.Add(va); summit.SaveChanges(); } return(va); } }
public void DeleteAllVoices() { using (SummitDBEntity summit = new SummitDBEntity()) { using (var transaction = summit.Database.BeginTransaction()) { try { foreach (var s in summit.Voices) { summit.Voices.Remove(s); } summit.SaveChanges(); transaction.Commit(); } catch { transaction.Rollback(); } } } }