Ejemplo n.º 1
0
        public void updateModel(ModelModels model)
        {
            string cs = ConfigurationManager.ConnectionStrings["Con"].ConnectionString;

            using (SqlConnection con = new SqlConnection(cs))
            {
                SqlCommand cmd = new SqlCommand("updateModel", con);
                cmd.CommandType = CommandType.StoredProcedure;

                SqlParameter paramId = new SqlParameter();
                paramId.ParameterName = "@Id";
                paramId.Value         = model.Id;
                cmd.Parameters.Add(paramId);

                SqlParameter paramName = new SqlParameter();
                paramName.ParameterName = "@Name";
                paramName.Value         = model.Name;
                cmd.Parameters.Add(paramName);

                SqlParameter paramBrandId = new SqlParameter();
                paramBrandId.ParameterName = "@BrandId";
                paramBrandId.Value         = model.BrandId;
                cmd.Parameters.Add(paramBrandId);

                SqlParameter paramCategoryId = new SqlParameter();
                paramCategoryId.ParameterName = "@CategoryId";
                paramCategoryId.Value         = model.CategoryId;
                cmd.Parameters.Add(paramCategoryId);

                con.Open();
                cmd.ExecuteNonQuery();
            }
        }
Ejemplo n.º 2
0
        public IEnumerable <ModelModels> getModelBrands(int id)
        {
            string             cs     = ConfigurationManager.ConnectionStrings["Con"].ConnectionString;
            List <ModelModels> models = new List <ModelModels>();

            using (SqlConnection con = new SqlConnection(cs))
            {
                SqlCommand cmd = new SqlCommand("getModelBrands", con);
                cmd.CommandType = CommandType.StoredProcedure;

                SqlParameter paramBrandId = new SqlParameter();
                paramBrandId.ParameterName = "@BrandId";
                paramBrandId.Value         = id;
                cmd.Parameters.Add(paramBrandId);

                con.Open();
                SqlDataReader reader = cmd.ExecuteReader();
                while (reader.Read())
                {
                    ModelModels model = new ModelModels();
                    model.Id          = Convert.ToInt32(reader["Id"]);
                    model.Name        = reader["Name"].ToString();
                    model.BrandId     = Convert.ToInt32(reader["BrandID"]);
                    model.CategoryId  = Convert.ToInt32(reader["CategoryId"]);
                    model.CreatedBy   = reader["CreatedBy"].ToString();
                    model.CreatedDate = Convert.ToDateTime(reader["CreatedDate"]);

                    models.Add(model);
                }
            }
            return(models);
        }