예제 #1
0
        // POST: api/Home
        public bool Post([FromBody] OgrModel ogrenci)
        {
            if (ModelState.IsValid)
            {
                _Repostory.Insert(ogrenci);
                return(true);
            }
            else
            {
                return(false);

                throw new HttpResponseException(HttpStatusCode.BadRequest);    // how return status cood with booleans
            }

            /*
             * try
             * {
             *  _Repostory.Insert(ogrenci);
             *  return true;
             * }
             * catch (Exception)
             * {
             *  throw new HttpResponseException(HttpStatusCode.BadRequest);
             *
             *  return false;
             * }
             */
        }
예제 #2
0
        public ActionResult Insert(OgrModel ogrenci)
        {
            _Repostory.Insert(ogrenci);
            return(RedirectToAction("Index"));

            /*
             *          using (var con = new MySqlConnection("datasource=localhost;port=3306;Database=ogrdb;username=root;password=1234"))
             * {
             *  con.Open();
             *  var cmd = new MySqlCommand("INSERT INTO Ogrenciler (Ad , Soyad,Tc) VALUES (@Ad,  @Soyad, @Tc)", con);
             * // cmd.Parameters.AddWithValue("Id", ogrenci.Id);
             *  cmd.Parameters.AddWithValue("Ad", ogrenci.Ad);
             *  cmd.Parameters.AddWithValue("Soyad", ogrenci.Soyad);
             *  cmd.Parameters.AddWithValue("Tc", ogrenci.Tc);
             *
             *
             *  cmd.ExecuteNonQuery();
             *  con.Close();
             *  return RedirectToAction("Index");
             * }
             */
        }