public IHttpActionResult PostTinhThanhPho(TinhThanhPho tinhThanhPho) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } db.TinhThanhPho.Add(tinhThanhPho); try { db.SaveChanges(); } catch (DbUpdateException) { if (TinhThanhPhoExists(tinhThanhPho.TinhThanhPho_ID)) { return(Conflict()); } else { throw; } } return(CreatedAtRoute("DefaultApi", new { id = tinhThanhPho.TinhThanhPho_ID }, tinhThanhPho)); }
public IHttpActionResult PutTinhThanhPho(string id, TinhThanhPho tinhThanhPho) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } if (id != tinhThanhPho.TinhThanhPho_ID) { return(BadRequest()); } db.Entry(tinhThanhPho).State = EntityState.Modified; try { db.SaveChanges(); } catch (DbUpdateConcurrencyException) { if (!TinhThanhPhoExists(id)) { return(NotFound()); } else { throw; } } return(StatusCode(HttpStatusCode.NoContent)); }
public IHttpActionResult GetTinhThanhPho(string id) { TinhThanhPho tinhThanhPho = db.TinhThanhPho.Find(id); if (tinhThanhPho == null) { return(NotFound()); } return(Ok(tinhThanhPho)); }
public IHttpActionResult DeleteTinhThanhPho(string id) { TinhThanhPho tinhThanhPho = db.TinhThanhPho.Find(id); if (tinhThanhPho == null) { return(NotFound()); } db.TinhThanhPho.Remove(tinhThanhPho); db.SaveChanges(); return(Ok(tinhThanhPho)); }
public ViewResult Demo() { List <TinhThanhPho> listTTP = new List <TinhThanhPho>(); TinhThanhPho ttp; ttp = new TinhThanhPho(); ttp.MaTinhThanhPho = 1; ttp.TenTinhThanhPho = "TP Ho Chi Minh"; listTTP.Add(ttp); ttp = new TinhThanhPho(); ttp.MaTinhThanhPho = 2; ttp.TenTinhThanhPho = "TP Ha Noi"; listTTP.Add(ttp); ViewBag.TinhThanhPho = new SelectList(listTTP, "MaTinhThanhPho", "TenTinhThanhPho"); return(View()); }
// GET: GiaoVien/Them public ActionResult Them() { TinhThanhPho tp = new TinhThanhPho(); List <string> BoMon = new List <string>(); //get max id using (var connection = new SqlConnection(cn)) { connection.Open(); //var getMaxTeacherId = "select IDENT_CURRENT('GiaoVien');"; SqlCommand sqlCommand = new SqlCommand("SELECT IDENT_CURRENT ('GiaoVien')", connection); int maxId = Convert.ToInt32(sqlCommand.ExecuteScalar()); var newMaxId = maxId; if (maxId != 1) { newMaxId = maxId + 1; } ViewBag.newId = newMaxId; connection.Close(); } using (var connection = new SqlConnection(cn)) { connection.Open(); var TenKhoaQuery = "select TenBoMon from BoMon"; SqlCommand sqlCommand = new SqlCommand(TenKhoaQuery, connection); SqlDataReader reader = sqlCommand.ExecuteReader(); if (reader.HasRows) { while (reader.Read()) { BoMon.Add(reader.GetString(0)); } } reader.Close(); ViewBag.BoMon = BoMon; } ViewBag.TinhThanhPho = tp.tinhThanhPho; return(View()); }