private void btnSave_Click(object sender, EventArgs e)
        {
            if (string.IsNullOrEmpty(txtGameName.Text))
            {
                MessageBox.Show("Game name is a required field.", "Input Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
            else
            {
                //Instantiate new Game and GameDescription objects
                GameBO gameToSaveOrUpdate = new GameBO();
                GameDescriptionBO gameDescriptionToSaveOrUpdate = new GameDescriptionBO();

                //Set Game object properties and call game manager to save
                gameToSaveOrUpdate.GameId = _GameId;
                gameToSaveOrUpdate.GameName = txtGameName.Text;
                int returnedGameId = GameManager.Save(gameToSaveOrUpdate);

                //Set GameDescription object properties and call game manager to save
                gameDescriptionToSaveOrUpdate.GameId = _GameId;
                gameDescriptionToSaveOrUpdate.GameCost = Convert.ToInt32(txtGameCost.Text);
                gameDescriptionToSaveOrUpdate.GameDescript = txtDescription.Text;
                gameDescriptionToSaveOrUpdate.HowToPlay = txtHowToPlay.Text;
                GameDescriptionManager.Save(returnedGameId, gameDescriptionToSaveOrUpdate);

                //Close the dialog window after serving
                base.Close();
            }
        }
        //INSERT
        public static int Save(int gameId, GameDescriptionBO gameDescriptionToSave)
        {
            ExecuteTypeEnum queryId = ExecuteTypeEnum.InsertItem;
            int result = 0;

            if (gameDescriptionToSave.GameId > 0)
            {
                queryId = ExecuteTypeEnum.UpdateItem;
            }

            using (SqlConnection myConnection = new SqlConnection(AppConfiguration.ConnectionString))
            {
                using (SqlCommand myCommand = new SqlCommand("usp_ExecuteGameDescription", myConnection))
                {
                    myCommand.CommandType = CommandType.StoredProcedure;

                    myCommand.Parameters.AddWithValue("@QueryId", queryId);
                    myCommand.Parameters.AddWithValue("@GameId", gameId);

                    if (gameDescriptionToSave.HowToPlay != null)
                    {
                        myCommand.Parameters.AddWithValue("@HowToPlay", gameDescriptionToSave.HowToPlay);
                    }
                    if (gameDescriptionToSave.GameDescript != null)
                    {
                        myCommand.Parameters.AddWithValue("@GameDescription", gameDescriptionToSave.GameDescript);
                    }
                    if (gameDescriptionToSave.GameCost != null)
                    {
                        myCommand.Parameters.AddWithValue("@GameCost", gameDescriptionToSave.GameCost);
                    }
                    if (gameDescriptionToSave.NumberOfBalls != null)
                    {
                        myCommand.Parameters.AddWithValue("@NumberOfBalls", gameDescriptionToSave.NumberOfBalls);
                    }
                    if (gameDescriptionToSave.SpecialBall != null)
                    {
                        myCommand.Parameters.AddWithValue("@SpecialBall", gameDescriptionToSave.SpecialBall);
                    }

                    //add return output parameter to command object
                    myCommand.Parameters.Add(HelperDAL.GetReturnParameterInt("ReturnValue"));

                    //Opens connection and executes query
                    myConnection.Open();
                    myCommand.ExecuteNonQuery();

                    //Get return value from stored procedure and return Id
                    result = Convert.ToInt32(myCommand.Parameters["@ReturnValue"].Value);
                }
                myConnection.Close();
            }
            return result;
        }
Пример #3
0
        public static GameDescriptionBO GetGameDescriptionRestfulConsume(int gameId)
        {
            GameDescriptionBO tempItem = new GameDescriptionBO();
            Base myBase = new Base();

            using (WebClient webClient = new WebClient())
            {
                //Call REST service and get JSON response
                string json = webClient.DownloadString("http://localhost:60706/LotteryService/GameDescription/Item/" + gameId.ToString());
                LotteryWindowsFormsApp.BO.GameDescriptionDTO item = myBase.GetGameItem<LotteryWindowsFormsApp.BO.GameDescriptionDTO>(json);

                if (!string.IsNullOrEmpty(item.GameDescript))
                {
                    tempItem.GameName = item.GameName;
                    tempItem.GameDescript = item.GameDescript;
                    tempItem.HowToPlay = item.HowToPlay;
                    tempItem.GameCost = item.GameCost;
                }
            }
            return tempItem;
        }
 public static int Save(int gameId, GameDescriptionBO gameDescriptionToSaveOrUpdate)
 {
     int returnValue = GameDescriptionDAL.Save(gameId, gameDescriptionToSaveOrUpdate);
     return returnValue;
 }