internal List <ClubViewModel> GetAllClub() { try { using (dbEntities1 context = new dbEntities1()) { List <Club> clubList = context.Club.ToList(); List <ClubViewModel> list = new List <ClubViewModel>(); foreach (Club item in clubList) { list.Add(new ClubViewModel { ID = item.id, Name = item.name, Stadium_Name = item.Stadium != null? item.Stadium.name:String.Empty, RecordID = item.Record != null? item.Record.id:0 }); } return(list); } } catch (Exception e) { throw e; } }
internal List <Stadium> GetAllStadium() { try { using (dbEntities1 context = new dbEntities1()) { List <Stadium> stadium = context.Stadium.ToList(); return(stadium); } } catch (Exception e) { throw e; } }
public bool AddStadium(Stadium stadium) { try { using (dbEntities1 context = new dbEntities1()) { context.Stadium.Add(stadium); context.SaveChanges(); return(true); } } catch (Exception e) { throw e; } }
internal bool EditClub(string newName, int newStadiumID, int newRecordID, long oldClubID) { try { using (dbEntities1 context = new dbEntities1()) { Club club = context.Club.FirstOrDefault(x => x.id == oldClubID); club.name = newName; club.stadiumID = newStadiumID; club.recordID = newRecordID; context.Entry(club).State = System.Data.Entity.EntityState.Modified; context.SaveChanges(); return(true); } } catch (Exception e) { throw e; } }
internal bool EditStadium(string newName, string newCity, string newCountry, long iD) { try { using (dbEntities1 context = new dbEntities1()) { Stadium stadium = context.Stadium.FirstOrDefault(x => x.id == iD); stadium.name = newName; stadium.city = newCity; stadium.country = newCountry; context.Entry(stadium).State = System.Data.Entity.EntityState.Modified; context.SaveChanges(); return(true); } } catch (Exception e) { throw e; } }
public bool RemoveClub(int clubID) { try { using (dbEntities1 context = new dbEntities1()) { Club club = context.Club.FirstOrDefault(x => x.id == clubID); if (!CanRemoveClub(club))//nie posiada graczy ani członków sztabu { return(false); } context.Club.Remove(club); context.SaveChanges(); return(true); } } catch (Exception e) { throw e; } }
public bool RemoveStadium(long stadiumID) { try { using (dbEntities1 context = new dbEntities1()) { Stadium stadium = context.Stadium.FirstOrDefault(x => x.id == stadiumID); if (!CanRemoveStadium(stadium))//nie posiada przypisanych klubów { return(false); } context.Stadium.Remove(stadium); context.SaveChanges(); return(true); } } catch (Exception e) { throw e; } }
//public void AddClub(string name, Stadium stadium) //{ // try // { // using (dbEntities1 context = new dbEntities1()) // { // Club club = new Club // { // name = name, // }; // if (stadium!=null) // { // club.Stadium = stadium; // } // context.Club.Add(club); // context.SaveChanges(); // } // } // catch (Exception e) // { // throw e; // } //} public void AddClub(string name, long stadiumID, long recordID) { try { using (dbEntities1 context = new dbEntities1()) { Stadium stadium = context.Stadium.FirstOrDefault(x => x.id == stadiumID); Record record = context.Record.FirstOrDefault(x => x.id == recordID); Club club = new Club { name = name, Stadium = stadium, Record = record }; context.Club.Add(club); context.SaveChanges(); } } catch (Exception e) { throw e; } }