public DbError AddMatch(MatchModel match, BracketModel bracket) { MatchModel _match = new MatchModel(); throw new Exception("Don't Call this Function"); try { _match = match; _match.Challenger = context.Users.Find(match.ChallengerID); _match.Defender = context.Users.Find(match.DefenderID); //context.Matches.Load(); context.Users.Load(); context.Matches.Add(_match); context.Entry(_match).CurrentValues.SetValues(match); context.SaveChanges(); bracket.Matches.Add(_match); //context.SaveChanges(); context.Tournaments.Include(x => x.Brackets).Load(); //context.Users.Include(x => x.UserID).Load(); context.SaveChanges(); } catch (Exception ex) { interfaceException = ex; WriteException(ex); return(DbError.ERROR); } return(DbError.SUCCESS); }
public DbError BracketExists(BracketModel bracket) { try { BracketModel _bracket = context.Brackets.Find(bracket.BracketID); } catch (Exception ex) { interfaceException = ex; WriteException(ex); return(DbError.DOES_NOT_EXIST); } return(DbError.EXISTS); }
public BracketModel GetBracketByID(int id) { BracketModel bracket = new BracketModel(); try { bracket = context.Brackets.Single(b => b.BracketID == id); } catch (Exception ex) { interfaceException = ex; bracket.BracketID = -1; WriteException(ex); return(bracket); } return(bracket); }
// Adds the passed-in bracket to the databaase and also adds the bracket to the passed-in tournament's list of brackets public DbError AddBracket(ref BracketModel bracket, TournamentModel tournament) { try { context.Brackets.Add(bracket); tournament.Brackets.Add(bracket); bracket.Tournament = tournament; context.SaveChanges(); } catch (Exception ex) { interfaceException = ex; WriteException(ex); return(DbError.FAILED_TO_ADD); } return(DbError.SUCCESS); }
// Gets the user's seed in the passed-in bracket // Returns -1 if the user is not found in the bracket public int GetUserSeedInBracket(UserModel user, BracketModel bracket) { UserBracketSeedModel ubs = new UserBracketSeedModel(); int seed; try { seed = context.UserBracketSeeds.Single(e => e.UserID == user.UserID && e.BracketID == bracket.BracketID).Seed; } catch (Exception ex) { WriteException(ex); interfaceException = ex; return(-1); } return(seed); }
public DbError DeleteBracket(BracketModel bracket) { try { BracketModel _bracket = context.Brackets.Find(bracket.BracketID); foreach (var match in bracket.Matches.ToList()) { DeleteMatch(match); } context.Brackets.Remove(_bracket); context.SaveChanges(); } catch (Exception ex) { WriteException(ex); return(DbError.FAILED_TO_DELETE); } return(DbError.SUCCESS); }
public DbError UpdateBracket(BracketModel bracket, bool updateMatches = true) { try { BracketModel _bracket = context.Brackets.Find(bracket.BracketID); context.Entry(_bracket).CurrentValues.SetValues(bracket); if (updateMatches) { foreach (var match in bracket.Matches) { match.Challenger = context.Users.Find(match.ChallengerID); match.Defender = context.Users.Find(match.DefenderID); } } context.SaveChanges(); } catch (Exception ex) { interfaceException = ex; WriteException(ex); return(DbError.FAILED_TO_UPDATE); } return(DbError.SUCCESS); }