Esempio n. 1
0
        public HttpResponseMessage InsertBreed(BreedRequestModel model)
        {
            if (ModelState.IsValid)
            {
                _breedService.InsertBreed(model);

                return Request.CreateResponse(HttpStatusCode.OK, model);
            }
            else
                return Request.CreateResponse(HttpStatusCode.BadRequest, ModelState);
        }
Esempio n. 2
0
        public void InsertBreed(BreedRequestModel model)
        {
            Configuration rootConfig = WebConfigurationManager.OpenWebConfiguration("/DogVDog");
            ConnectionStringSettings connString = rootConfig.ConnectionStrings.ConnectionStrings["DefaultConnection"];

            SqlConnection conn = new SqlConnection(connString.ConnectionString);
            conn.Open();

            SqlCommand cmd = conn.CreateCommand();
            cmd.CommandText = "Breeds_Insert";
            cmd.CommandType = CommandType.StoredProcedure;

            cmd.Parameters.AddWithValue("@Breed", model.Breed);
            if(model.Region != null)
                cmd.Parameters.AddWithValue("@Region", model.Region);
            else
                cmd.Parameters.AddWithValue("@Region", DBNull.Value);
            cmd.Parameters.AddWithValue("@IsCute", model.IsCute);
            cmd.Parameters.AddWithValue("@MedicalIssues", model.MedicalIssues);

            cmd.ExecuteNonQuery();

            conn.Close();
        }