コード例 #1
0
        public void CreateBMI(BMIDAO _BMICreate)
        {
            BMIDAO _CreateBMI = new BMIDAO();

            try
            {
                using (SqlConnection _connection = new SqlConnection(connectionstring))
                {
                    using (SqlCommand _command = new SqlCommand("sp_CreateBMI", _connection))
                    {
                        _command.CommandType = CommandType.StoredProcedure;
                        _command.Parameters.AddWithValue("@Height", _BMICreate.Height);
                        _command.Parameters.AddWithValue("@Weight", _BMICreate.Weight);
                        _command.Parameters.AddWithValue("@User_ID", _BMICreate.User_ID);

                        _command.Parameters.AddWithValue("@Result", _BMICreate.Result);

                        _connection.Open();
                        _command.ExecuteNonQuery();


                        _connection.Close();
                        _connection.Dispose();
                    }
                }
            }
            catch (Exception error)
            {
                Error_Logger log = new Error_Logger();
                log.LogError(error);
            }
        }
コード例 #2
0
        public List <BMIDAO> GetBMIByUser_ID(int User_ID)
        {
            List <BMIDAO> _BMIToGet = new List <BMIDAO>();

            try
            {  //esablishing the connection for the database
                using (SqlConnection _connection = new SqlConnection(connectionstring))

                {   //establishing the command to pass to the database and defining the command
                    using (SqlCommand _command = new SqlCommand("sp_GetBMIByUser_ID", _connection))
                    {
                        //this specifies what type of command is being used
                        _command.CommandType = CommandType.StoredProcedure;
                        //here is where values are going to be passed to the command
                        _command.Parameters.AddWithValue("@User_ID", User_ID);
                        //here is where the connection is open
                        _connection.Open();
                        //this executes the command
                        _command.ExecuteNonQuery();



                        using (SqlDataReader _reader = _command.ExecuteReader())
                        {
                            //loop through the dataset or command and write each element to the _playerToList using the player object class
                            //while (_reader.Read())
                            //{
                            //    List
                            //    _BMIToGet.Height = _reader.GetDecimal(0);
                            //    _BMIToGet.Weight = _reader.GetDecimal(1);
                            //    _BMIToGet.User_ID = _reader.GetInt32(2);
                            //    _BMIToGet.ID = _reader.GetInt32(3);


                            //}
                            while (_reader.Read())
                            {
                                BMIDAO _BMIToList = new BMIDAO()
                                {
                                    Height  = _reader.GetDecimal(0),
                                    Weight  = _reader.GetDecimal(1),
                                    User_ID = _reader.GetInt32(2),
                                    ID      = _reader.GetInt32(3),
                                    Result  = _reader.GetDecimal(4),
                                };
                                _BMIToGet.Add(_BMIToList);
                            }
                        }
                    }
                }
            }
            catch (Exception error)
            {
                Error_Logger log = new Error_Logger();
                log.LogError(error);
            }
            return(_BMIToGet);
        }
コード例 #3
0
ファイル: Mapper.cs プロジェクト: aravinda-kumar/HealthStats
        public BMI Map(BMIDAO _CreateListToMap)
        {
            BMI _BMIToCreate = new BMI()

            {
                Height  = _CreateListToMap.Height,
                Weight  = _CreateListToMap.Weight,
                User_ID = _CreateListToMap.User_ID,
                ID      = _CreateListToMap.ID,
                Result  = _CreateListToMap.Result,
            };

            return(_BMIToCreate);
        }
コード例 #4
0
ファイル: Mapper.cs プロジェクト: aravinda-kumar/HealthStats
        public List <BMIDAO> Map(List <BMI> _BMIListToMap)
        {
            List <BMIDAO> _BMIListToReturn = new List <BMIDAO>();

            foreach (BMI _BMIToMap in _BMIListToMap)
            {
                BMIDAO _BMIToView = new BMIDAO()
                {
                    Height  = _BMIToMap.Height,
                    Weight  = _BMIToMap.Weight,
                    User_ID = _BMIToMap.User_ID,
                    ID      = _BMIToMap.ID,
                    Result  = _BMIToMap.Result,
                };

                _BMIListToReturn.Add(_BMIToView);
            }
            return(_BMIListToReturn);
        }
コード例 #5
0
        public List <BMIDAO> ViewBMI()
        {
            List <BMIDAO> _BMIList = new List <BMIDAO>();

            try
            {  //esablishing the connection for the database
                using (SqlConnection _connection = new SqlConnection(connectionstring))

                {   //establishing the command to pass to the database and defining the command
                    using (SqlCommand _command = new SqlCommand("sp_ViewBMI", _connection))
                    {
                        _command.CommandType = CommandType.StoredProcedure;

                        //connect to the database
                        _connection.Open();
                        //open the SQL data reader
                        using (SqlDataReader _reader = _command.ExecuteReader())
                        {
                            //loop through the dataset or command and write each element to the _playerToList using the player object class
                            while (_reader.Read())
                            {
                                BMIDAO _BMIToList = new BMIDAO()
                                {
                                    Height  = _reader.GetDecimal(0),
                                    Weight  = _reader.GetDecimal(1),
                                    User_ID = _reader.GetInt32(2),
                                    ID      = _reader.GetInt32(3),
                                    Result  = _reader.GetDecimal(4),
                                };
                                _BMIList.Add(_BMIToList);
                            }
                        }
                    }
                }
            }
            catch (Exception error)
            {
                Error_Logger log = new Error_Logger();
                log.LogError(error);
            }
            return(_BMIList);
        }
コード例 #6
0
        public bool UpdateBMI(BMIDAO BMIToUpdate)
        {
            bool success = false;

            try
            {
                using (SqlConnection _connection = new SqlConnection(connectionstring))
                {
                    using (SqlCommand _command = new SqlCommand("sp_UpdateBMI", _connection))
                    {
                        //this specifies what type of command is being used
                        _command.CommandType = CommandType.StoredProcedure;
                        //here is where values are going to be passed to the command
                        _command.Parameters.AddWithValue("@Height", BMIToUpdate.Height);
                        _command.Parameters.AddWithValue("@Weight", BMIToUpdate.Weight);
                        _command.Parameters.AddWithValue("@User_ID", BMIToUpdate.User_ID);
                        _command.Parameters.AddWithValue("@ID", BMIToUpdate.ID);
                        _command.Parameters.AddWithValue("@Result", BMIToUpdate.Result);

                        //here is where the connection is open
                        _connection.Open();
                        //this executes the command
                        _command.ExecuteNonQuery();
                        success = true;
                        _connection.Close();
                    }
                }
            }
            catch (Exception error)
            {
                Error_Logger log = new Error_Logger();
                log.LogError(error);
            }

            return(success);
        }