Example #1
0
        // GET: api/Time/5
        public TimeBindingModel Get(int id)
        {
            SqlConnection();
            TimeBindingModel Time = new TimeBindingModel();

            using (SqlCommand sqlCommand = new SqlCommand("GetTimeById", sqlConnection))
            {
                sqlCommand.CommandType = System.Data.CommandType.StoredProcedure;
                sqlCommand.Parameters.AddWithValue("@Id", id);
                sqlConnection.Open();
                SqlDataReader sqlDataReader = sqlCommand.ExecuteReader();

                while (sqlDataReader.Read())
                {
                    Time = new TimeBindingModel()
                    {
                        Id   = Convert.ToInt32(sqlDataReader["Id"]),
                        Nome = Convert.ToString(sqlDataReader["Name"])
                    };
                }
                sqlConnection.Close();
            }

            return(Time);
        }
Example #2
0
        // GET: api/Time
        public IEnumerable <TimeBindingModel> Get()
        {
            SqlConnection();
            List <TimeBindingModel> times = new List <TimeBindingModel>();

            using (SqlCommand sqlCommand = new SqlCommand("GetAllTimes", sqlConnection))
            {
                sqlCommand.CommandType = System.Data.CommandType.StoredProcedure;
                sqlConnection.Open();
                SqlDataReader sqlDataReader = sqlCommand.ExecuteReader();

                while (sqlDataReader.Read())
                {
                    if (sqlDataReader.HasRows)
                    {
                        TimeBindingModel time = new TimeBindingModel()
                        {
                            Id   = Convert.ToInt32(sqlDataReader["Id"]),
                            Nome = Convert.ToString(sqlDataReader["Name"])
                        };
                        times.Add(time);
                    }
                }
                sqlConnection.Close();
            }

            return(times);
        }
Example #3
0
        // POST: api/Time
        public IHttpActionResult Post(TimeBindingModel Time)
        {
            SqlConnection();

            using (SqlCommand sqlCommand = new SqlCommand("InsertTime", sqlConnection))
            {
                sqlCommand.CommandType = System.Data.CommandType.StoredProcedure;
                sqlCommand.Parameters.AddWithValue("@Name", Time.Nome);

                sqlConnection.Open();
                int execute = sqlCommand.ExecuteNonQuery();
            }
            sqlConnection.Close();

            return(Ok(Time));
        }