コード例 #1
0
        public ActionResult Create(Plant plant)
        {
            //TryUpdateModel(plant);
            if (ModelState.IsValid)
            {
                PlantContext plantContext = new PlantContext();
                plantContext.AddPlant(plant);

                return RedirectToAction("Index");
            }
            return View();
        }
コード例 #2
0
        public void AddPlant(Plant plant)
        {
            string connectionString = ConfigurationManager.ConnectionStrings["PlantContext"].ConnectionString;
            using (SqlConnection con = new SqlConnection(connectionString))
            {
                SqlCommand cmd = new SqlCommand("spAddPlant", con);
                cmd.CommandType = CommandType.StoredProcedure;

                cmd.Parameters.AddWithValue("@Name", plant.Name);
                cmd.Parameters.AddWithValue("@Category", plant.Category);
                cmd.Parameters.AddWithValue("@AttackIndex", plant.AttackIndex);
                cmd.Parameters.AddWithValue("@DefenceIndex", plant.DefenceIndex);
                cmd.Parameters.AddWithValue("@Price", plant.Price);
                cmd.Parameters.AddWithValue("@Attribute", plant.Attribute);
                cmd.Parameters.AddWithValue("@ImageUrl", plant.ImageUrl);

                con.Open();
                cmd.ExecuteNonQuery();
            }
        }