Пример #1
0
        public bool AddManufacturer(Manufacturer m)
        {
            bool error = false;

            string consulta = "INSERT INTO Manufacturer (ManufacturerName, ManufacturerCountry)" +
                              " VALUES (@ManufacturerName, @ManufacturerCountry);";

            using (SqlConnection conn = GetConnection())
            {
                SqlCommand cmd = new SqlCommand(consulta, conn);
                cmd.Parameters.AddWithValue("@ManufacturerName", m.ManufacturerName);
                cmd.Parameters.AddWithValue("@ManufacturerCountry", m.ManufacturerCountry);

                try
                {

                    conn.Open();
                    cmd.ExecuteNonQuery();

                }
                catch (Exception ex)
                {
                    error = true;
                }
            }

            return error;
        }
Пример #2
0
        public Manufacturer GetManufacturerByID(int id)
        {
            Manufacturer ma = null;

            string consulta = "SELECT ManufacturerID, ManufacturerName," +
                              " ManufacturerCountry, ManufacturerEmail, ManufacturerWebsite" +
                              " FROM Manufacturer WHERE ManufacturerID = @ManufacturerID";

            using (SqlConnection conn = GetConnection())
            {
                SqlCommand cmd = new SqlCommand(consulta, conn);
                cmd.Parameters.AddWithValue("@ManufacturerID", id);

                conn.Open();
                SqlDataReader reader = cmd.ExecuteReader();

                if (reader.HasRows)
                {
                    while (reader.Read())
                    {
                        ma = new Manufacturer
                        {
                            ManufacturerName = reader.GetString(reader.GetOrdinal("ManufacturerName")),
                            ManufacturerCountry = reader.GetString(reader.GetOrdinal("ManufacturerCountry")),
                            ManufacturerEmail = reader.GetString(reader.GetOrdinal("ManufacturerEmail")),
                            ManufacturerWebsite = reader.GetString(reader.GetOrdinal("ManufacturerWebsite")),
                        };
                    }
                }

                reader.Close();
            }

            return ma;
        }
 // GET: /Manufacturer/Guardar
 public ActionResult Guardar(Manufacturer m)
 {
     ViewData["Manufacturer"] = string.Format("Nombre: {0}, Country: {1}",
                                     m.ManufacturerName, m.ManufacturerCountry);
     return View();
 }