Example #1
0
        /// <summary>
        /// Place bet in administrator object and send it to sql table.
        /// </summary>
        /// <param name="betSort">Sort of bet which should be placed.</param>
        /// <param name="betValue">Value of the bet which should be placed.</param>
        /// <param name="dogToWin">Number of dog on which bet is placed.</param>
        public override void PlaceBet(BetFactory.BetSort betSort, decimal betValue, int dogToWin)
        {
            cash -= betValue;                                                     //substract amount bet.
            decimal standardBetValue = 0;                                         //variable used to get amount which was bet when placeing standard bet.

            if (betSort == BetFactory.BetSort.handicapBet)                        //check if admin has placed standard bet
            {
                try
                {
                    standardBetValue = (this.betSort as BetStandard).GetAmount;            //handicap uses the betValue from standardBet.
                }
                catch (System.NullReferenceException)
                {
                    standardBetValue = 0;
                }
            }

            this.betSort = betFactory.CreateBet(betSort, betValue + standardBetValue, dogToWin);   //place bet in admin object(add standardBet with current value of handicap).

            if (betSort == BetFactory.BetSort.dummyBet)                                            //prevents sending dummy bet to sql table.
            {
                return;
            }

            ClientServerConnectionsHub.PlaceAdminBet(name, betValue, dogToWin, betSort);             //send bet to database.
        }
        /// <summary>
        /// Handles the process of placing bet by administrator.
        /// Adds new bet which was created to database.
        /// </summary>
        /// <param name="adminName">Name of the administrator.</param>
        /// <param name="betValue">Value of the bet which should be placed.</param>
        /// <param name="dogToWin">Number of dog on which bet should be placed.</param>
        /// <param name="betSort">What sort of bet should be placed.</param>
        /// <remarks>
        /// Only database operations are stored here because admin object (<see cref="Parlor"/>) is already on server so whenever he places bet his object is instantly updated.
        /// </remarks>
        public void PlaceAdminBet(string adminName, decimal betValue, int dogToWin, BetFactory.BetSort betSort)
        {
            using (var dataBase = new DataClassesBettingParlorDataContext())
            {
                var searchAdminAccount = (from player in dataBase.Players
                                          where player.UserName == adminName
                                          select player).SingleOrDefault();

                searchAdminAccount.CurrentAccountBalance -= betValue;     //substract money from database.

                if (betSort == BetFactory.BetSort.standartBet)
                {
                    CurrentBet currentBet = new CurrentBet
                    {
                        Bettor_name = adminName,
                        Amount_bet  = betValue,
                        Dog_to_win  = dogToWin
                    };

                    dataBase.CurrentBets.InsertOnSubmit(currentBet);
                }
                else
                {
                    var searchCurrentBetRow = dataBase.CurrentBets.SingleOrDefault(p => p.Bettor_name == adminName); //Check if admin has placed standardBet.

                    if (searchCurrentBetRow != null)                                                                 //If admin has placed standard bet.
                    {
                        searchCurrentBetRow.Amount_bet += betValue;
                        searchCurrentBetRow.Dog_to_win  = dogToWin;
                    }
                    else                                       //If admin has not placed standard bet.
                    {
                        CurrentBet currentBet = new CurrentBet //create bet in dataBase to display it in dataGriedView.
                        {
                            Bettor_name = adminName,
                            Amount_bet  = betValue,
                            Dog_to_win  = dogToWin
                        };

                        dataBase.CurrentBets.InsertOnSubmit(currentBet);
                    }
                }
                dataBase.SubmitChanges();
            }
        }
Example #3
0
        /// <summary>
        /// Substracts money from bettor object.
        /// Checks whether standard bet has been placed, to aquire amount of the bet and use it when handicap is created.
        /// Uses betFactory, which returns new instance of <see cref="BetStandard"/> or <see cref="BetHandicap"/> and the previous instance
        /// stored of bet in class gets overriden because only one type of each bet is allowed.
        /// </summary>
        /// <exception cref="System.ArgumentNullException">Thrown when one of the parameters is null.</exception>
        /// <param name="sortOfBet">Enum type which specifies what sort of bet should be placed.</param>
        /// <param name="betValue">Amount of cash which is placed.</param>
        /// <param name="dogToWin">Dog number on which the bet should be placed.</param>
        /// <seealso cref="BetFactory"/>
        public override void PlaceBet(BetFactory.BetSort sortOfBet, decimal betValue, int dogToWin)
        {
            cash -= betValue;                                                   //substract money from Bettor object.
            decimal standardBetValue = 0;

            if (sortOfBet == BetFactory.BetSort.handicapBet)                  //check whetether user has placed standardBet.
            {
                try
                {
                    standardBetValue = (this.betSort as BetStandard).GetAmount;     //handicap uses previously placed standard bet.
                }
                catch (System.NullReferenceException)                               //exception is thrown when dummybet is stored in betSort object.
                {
                    standardBetValue = 0;
                }
            }

            this.betSort = betFactory.CreateBet(sortOfBet, betValue + standardBetValue, dogToWin);        //place bet in bettor object(add standardBet with current value of handicap).
        }
Example #4
0
 /// <summary>
 /// Sends administrator bet to database to display it in dataGriedView.
 /// </summary>
 /// <param name="adminName">Name of the administrator who places the bet.</param>
 /// <param name="betValue">Value of the bet which should be placed.</param>
 /// <param name="dogToWin">Number of dog on which bet should be placed.</param>
 /// <param name="betSort">Defines what kind of bet should be placed.</param>
 public static void PlaceAdminBet(string adminName, decimal betValue, int dogToWin, BetFactory.BetSort betSort)
 {
     manageUserData.PlaceAdminBet(adminName, betValue, dogToWin, betSort);   //place admin bet in database.
     UpdateClientsBetTable();                                                //send information to all clients that they should update their dataGriedViews.
 }
Example #5
0
 /// <summary>
 /// Creates new bet object by the use of <see cref="BetFactory"/>.
 /// </summary>
 /// <param name="betSort">Enum type which specifies what sort of bet should be placed.</param>
 /// <param name="betValue">Amount of cash which is placed.</param>
 /// <param name="dogToWin">Dog number on which the bet should be placed.</param>]
 /// <remarks>
 /// Function is implemented differently in <see cref="Bettor"/> and <see cref="Parlor"/> class to suit their needs.
 /// </remarks>
 public virtual void PlaceBet(BetFactory.BetSort betSort, decimal betValue, int dogToWin)
 {
 }