public DbError AddBracket(BracketModel bracket)
 {
     try
     {
         context.BracketModels.Add(bracket);
         context.SaveChanges();
     }
     catch (Exception ex)
     {
         interfaceException = ex;
         WriteException(ex);
         return(DbError.FAILED_TO_ADD);
     }
     return(DbError.SUCCESS);
 }
        public BracketModel GetBracket(int id)
        {
            BracketModel bracket = new BracketModel();

            try
            {
                bracket = context.BracketModels.Single(b => b.BracketID == id);
                foreach (var match in bracket.Matches)
                {
                    match.Challenger = context.TournamentUserModels.Find(match.ChallengerID);
                    match.Defender   = context.TournamentUserModels.Find(match.DefenderID);
                }
            }
            catch (Exception ex)
            {
                interfaceException = ex;
                WriteException(ex);
                bracket = null;
            }
            return(bracket);
        }
 public DbError DeleteBracket(int id)
 {
     try
     {
         BracketModel _bracket = context.BracketModels.Find(id);
         // TODO: implement delete for matches
         //foreach (var match in _bracket.Matches.ToList())
         //{
         //    DeleteMatch(match.MatchID);
         //}
         context.BracketModels.Remove(_bracket);
         context.SaveChanges();
     }
     catch (Exception ex)
     {
         interfaceException = ex;
         WriteException(ex);
         return(DbError.FAILED_TO_DELETE);
     }
     return(DbError.SUCCESS);
 }
        public DbError UpdateBracket(BracketModel bracket)
        {
            try
            {
                BracketModel _bracket = context.BracketModels.Find(bracket.BracketID);
                context.Entry(_bracket).CurrentValues.SetValues(bracket);
                foreach (var match in _bracket.Matches)
                {
                    match.Challenger = context.TournamentUserModels.Find(match.ChallengerID);
                    match.Defender   = context.TournamentUserModels.Find(match.DefenderID);
                }

                context.SaveChanges();
            }
            catch (Exception ex)
            {
                interfaceException = ex;
                WriteException(ex);
                return(DbError.FAILED_TO_UPDATE);
            }
            return(DbError.SUCCESS);
        }