Exemplo n.º 1
0
        public void DeleteManager(string managerName, string team)
        {
            lock (_sycnRoot)
            {
                var deleteManager = from t in dc.Teams
                                    where t.TeamName == team && t.Managers.ManagerName == managerName
                                    select t.Managers;

                foreach (var manager in deleteManager)
                {
                    try
                    {
                        dc.Managers.DeleteOnSubmit(manager);
                        dc.SubmitChanges();
                        using (StreamWriter w = File.AppendText("NbaLog.txt"))
                        {
                            Log("Delete manager: " + manager.ManagerName, w);
                        }
                    }
                    catch (SqlException ex)
                    {
                        DataBaseException fault = new DataBaseException();
                        fault.Message = "Delete player exception: " + ex.Message;
                        throw new FaultException <DataBaseException>(fault, new FaultReason("Delete player exception: " + ex.Message));
                    }
                    catch (Exception ex)
                    {
                        DataBaseException fault = new DataBaseException();
                        fault.Message = "Delete player exception: " + ex.Message;
                        throw new FaultException <DataBaseException>(fault, new FaultReason("Delete player exception: " + ex.Message));
                    }
                }
                broadCast(managerName + " was deleted!", "Delete Manager");
            }
        }
Exemplo n.º 2
0
        //DATA BASE GLOBAL
        public void InsertUser(string userName, string password)
        {
            lock (_sycnRoot)
            {
                dc.GetTable <Users>().InsertOnSubmit(new Users
                {
                    UserName = userName,
                    Password = password
                });

                /* save the changes on the data base */
                try
                {
                    dc.SubmitChanges();
                    using (StreamWriter w = File.AppendText("NbaLog.txt"))
                    {
                        Log("New user insert: " + userName, w);
                    }
                }
                catch (SqlException ex)
                {
                    DataBaseException fault = new DataBaseException();
                    fault.Message = "Unable to insert user: "******"Unable to insert user: "******"Unable to insert user: "******"Unable to insert user: " + ex.Message));
                }
            }
        }
Exemplo n.º 3
0
 public void UpdateWinAndLose(string win, string lose)
 {
     lock (_sycnRoot)
     {
         try
         {
             var teamWin = from t in dc.Teams
                           where t.TeamName == win
                           select t;
             foreach (var team in teamWin)
             {
                 team.Wins++;
                 using (StreamWriter w = File.AppendText("NbaLog.txt"))
                 {
                     Log("Update team " + team.TeamName + " wins", w);
                 }
             }
             var teamLost = from t in dc.Teams
                            where t.TeamName == lose
                            select t;
             foreach (var team in teamLost)
             {
                 team.Losses++;
                 using (StreamWriter w = File.AppendText("NbaLog.txt"))
                 {
                     Log("Update team " + team.TeamName + " losses", w);
                 }
             }
             dc.SubmitChanges();
         }
         catch (SqlException ex)
         {
             DataBaseException fault = new DataBaseException();
             fault.Message = "Update win and losses exception: " + ex.Message;
             throw new FaultException <DataBaseException>(fault, new FaultReason("Update win and losses exception: " + ex.Message));
         }
         catch (Exception ex)
         {
             DataBaseException fault = new DataBaseException();
             fault.Message = "Update win and losses exception: " + ex.Message;
             throw new FaultException <DataBaseException>(fault, new FaultReason("Update win and losses exception: " + ex.Message));
         }
     }
 }
Exemplo n.º 4
0
 public void InsertPlayer(string playerName, string teamName, int age, double height, double weight, string position, int expYears, int titles, byte[] file_byte, string agent)
 {
     lock (_sycnRoot)
     {
         var playersTable = dc.GetTable <Players>();
         try
         {
             System.Data.Linq.Binary file_binary = new System.Data.Linq.Binary(file_byte);
             playersTable.InsertOnSubmit(new Players()
             {
                 PlayerName       = playerName,
                 TeamName         = teamName,
                 Age              = age,
                 Height           = height,
                 Weight           = weight,
                 Position         = position,
                 ExeperienceYears = expYears,
                 NumberOfTitles   = titles,
                 Picture          = file_binary,
                 AgentName        = agent,
                 MVP              = 0
             });
             dc.SubmitChanges();
             using (StreamWriter w = File.AppendText("NbaLog.txt"))
             {
                 Log("New player insert: " + playerName, w);
             }
         }
         catch (SqlException ex)
         {
             DataBaseException fault = new DataBaseException();
             fault.Message = "Unable to insert player: " + ex.Message;
             throw new FaultException <DataBaseException>(fault, new FaultReason("Unable to insert player: " + ex.Message));
         }
         catch (Exception ex)
         {
             DataBaseException fault = new DataBaseException();
             fault.Message = "Unable to insert player: " + ex.Message;
             throw new FaultException <DataBaseException>(fault, new FaultReason("Unable to insert player: " + ex.Message));
         }
         broadCast("player " + playerName + " was added to data base!", "Add Player");
     }
 }
Exemplo n.º 5
0
        public void InsertGame(string homeTeam, string awayTeam, string MVP, DateTime gameDate, int homeScore, int awayScore, int fixtures)
        {
            lock (_sycnRoot)
            {
                var gamesTable = dc.GetTable <Games>();
                try
                {
                    gamesTable.InsertOnSubmit(new Games()
                    {
                        HomeTeam      = homeTeam,
                        AwayTeam      = awayTeam,
                        MVP           = MVP,
                        GameDate      = gameDate,
                        AwayTeamScore = homeScore,
                        HomeTeamScore = awayScore,
                        Fixture       = fixtures
                    });

                    dc.SubmitChanges();
                    using (StreamWriter w = File.AppendText("NbaLog.txt"))
                    {
                        Log("New game insert: " + homeTeam + " - " + awayTeam + ", fixture: " + fixtures, w);
                    }
                }
                catch (SqlException ex)
                {
                    DataBaseException fault = new DataBaseException();
                    fault.Message = "Manager insertion exception: " + ex.Message;
                    throw new FaultException <DataBaseException>(fault, new FaultReason("Game insertion exception: " + ex.Message));
                }
                catch (Exception ex)
                {
                    DataBaseException fault = new DataBaseException();
                    fault.Message = "Manager insertion exception: " + ex.Message;
                    throw new FaultException <DataBaseException>(fault, new FaultReason("Game insertion exception: " + ex.Message));
                }
                broadCast("game " + homeTeam + " vs " + awayTeam + " was added to data base!", "Add Game");
            }
        }
Exemplo n.º 6
0
        public void UpdateMVP(string playerMVP)
        {
            lock (_sycnRoot)
            {
                try
                {
                    var players = from p in dc.Players
                                  where p.PlayerName == playerMVP.Substring(0, p.PlayerName.Length) &&
                                  p.TeamName == playerMVP.Substring(p.PlayerName.Length + 1, p.TeamName.Length)

                                  select p;

                    foreach (var player in players)
                    {
                        player.MVP++;
                        dc.SubmitChanges();
                        using (StreamWriter w = File.AppendText("NbaLog.txt"))
                        {
                            Log("Update player: " + player.PlayerName, w);
                        }
                    }
                }
                catch (SqlException ex)
                {
                    DataBaseException fault = new DataBaseException();
                    fault.Message = "Update MVP exception: " + ex.Message;
                    throw new FaultException <DataBaseException>(fault, new FaultReason("Update MVP exception: " + ex.Message));
                }
                catch (Exception ex)
                {
                    DataBaseException fault = new DataBaseException();
                    fault.Message = "Update MVP exception: " + ex.Message;
                    throw new FaultException <DataBaseException>(fault, new FaultReason("Update MVP exception: " + ex.Message));
                }
            }
        }
Exemplo n.º 7
0
        public void connectDB()
        {
            dc = new NBADataContext(connectionString);

            try
            {
                if (!dc.DatabaseExists())
                {
                    dc.CreateDatabase();
                }
            }
            catch (SqlException ex)
            {
                DataBaseException fault = new DataBaseException();
                fault.Message = "Unable to connect data base: " + ex.Message;
                throw new FaultException <DataBaseException>(fault, new FaultReason("Unable to connect data base: " + ex.Message));
            }
            catch (Exception ex)
            {
                DataBaseException fault = new DataBaseException();
                fault.Message = "Unable to connect data base: " + ex.Message;
                throw new FaultException <DataBaseException>(fault, new FaultReason("Unable to connect data base: " + ex.Message));
            }
        }
Exemplo n.º 8
0
 public void InsertManager(string managerName, string team, int age, int expYears, int titles)
 {
     lock (_sycnRoot)
     {
         var managersTable = dc.GetTable <Managers>();
         try
         {
             managersTable.InsertOnSubmit(new Managers()
             {
                 ManagerName     = managerName,
                 TeamName        = team,
                 Age             = age,
                 ExperienceYears = expYears,
                 NumberOfTitles  = titles
             });
             dc.SubmitChanges();
             using (StreamWriter w = File.AppendText("NbaLog.txt"))
             {
                 Log("New manager insert: " + managerName, w);
             }
         }
         catch (SqlException ex)
         {
             DataBaseException fault = new DataBaseException();
             fault.Message = "Manager insertion exception: " + ex.Message;
             throw new FaultException <DataBaseException>(fault, new FaultReason("Manager insertion exception: " + ex.Message));
         }
         catch (Exception ex)
         {
             DataBaseException fault = new DataBaseException();
             fault.Message = "Manager insertion exception: " + ex.Message;
             throw new FaultException <DataBaseException>(fault, new FaultReason("Manager insertion exception: " + ex.Message));
         }
         broadCast("manager " + managerName + " was added to data base!", "Add Manager");
     }
 }