Example #1
0
        public void Update(BodyTypeModel model)
        {
            String sql = "Update [BodyType] set Description=@Description where Id=@Id";

            using (SqlConnection connection = new SqlConnection(connectionString))
                using (SqlCommand command = new SqlCommand(sql, connection))
                {
                    command.Connection.Open();
                    command.Parameters.AddWithValue("@Description", model.Description);
                    command.Parameters.AddWithValue("@Id", model.Id);
                    command.ExecuteNonQuery();
                }
        }
Example #2
0
        public bool Create(BodyTypeModel model)
        {
            String sql = "insert into [BodyType] (Description) values (@Description)";

            using (SqlConnection connection = new SqlConnection(connectionString))
                using (SqlCommand command = new SqlCommand(sql, connection))
                {
                    command.Parameters.AddWithValue("@Description", model.Description);
                    command.Connection.Open();
                    command.ExecuteNonQuery();
                    return(true);
                }
        }
Example #3
0
        public List <BodyTypeModel> List()
        {
            List <BodyTypeModel> BodyTypeList = new List <BodyTypeModel>();

            String sql = "select Id, Description from [BodyType]";

            using (SqlConnection connection = new SqlConnection(connectionString))
                using (SqlCommand command = new SqlCommand(sql, connection))
                {
                    command.Connection.Open();
                    SqlDataReader reader = command.ExecuteReader();

                    while (reader.Read())
                    {
                        BodyTypeModel model = new BodyTypeModel();
                        model.Id          = Convert.ToInt32(reader["Id"]);
                        model.Description = reader["Description"].ToString();

                        BodyTypeList.Add(model);
                    }

                    return(BodyTypeList);
                }
        }
Example #4
0
        public BodyTypeModel Read(int id)
        {
            BodyTypeModel model = null;

            String sql = "select Description from [BodyType] where Id=@Id";


            using (SqlConnection connection = new SqlConnection(connectionString))
                using (SqlCommand command = new SqlCommand(sql, connection))
                {
                    command.Parameters.AddWithValue("@Id", id);
                    command.Connection.Open();
                    SqlDataReader reader = command.ExecuteReader();

                    if (reader.Read())
                    {
                        model             = new BodyTypeModel();
                        model.Id          = id;
                        model.Description = reader["Description"].ToString();
                    }
                }

            return(model);
        }