// PUT: api/DenGiaoThong/5 public IHttpActionResult Put(int id, DenGiaoThong denGiaoThong) { if (!ModelState.IsValid) { return(BadRequest("Not a valid model")); } using (var ctx = new GTVTContext()) { var existingDenGiaoThong = ctx.DenGiaoThongs.Where(s => s.Id == id) .FirstOrDefault <DenGiaoThong>(); if (existingDenGiaoThong != null) { existingDenGiaoThong.Do = denGiaoThong.Do; existingDenGiaoThong.Vang = denGiaoThong.Vang; existingDenGiaoThong.Xanh = denGiaoThong.Xanh; existingDenGiaoThong.TrangThai = denGiaoThong.TrangThai; //existingDenGiaoThong.KhuVuc_Id = denGiaoThong.KhuVuc_Id; existingDenGiaoThong.TenDuong = denGiaoThong.TenDuong; ctx.SaveChanges(); } else { return(NotFound()); } } return(Ok()); }
public IHttpActionResult PutDenGiaoThong(int id, DenGiaoThong denGiaoThong) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } if (id != denGiaoThong.ma_den) { return(BadRequest()); } db.Entry(denGiaoThong).State = EntityState.Modified; try { db.SaveChanges(); } catch (DbUpdateConcurrencyException) { if (!DenGiaoThongExists(id)) { return(NotFound()); } else { throw; } } return(StatusCode(HttpStatusCode.NoContent)); }
public IHttpActionResult GetDenGiaoThong(int id) { DenGiaoThong denGiaoThong = db.DenGiaoThong.Find(id); if (denGiaoThong == null) { return(NotFound()); } return(Ok(denGiaoThong)); }
public IHttpActionResult PostDenGiaoThong(DenGiaoThong denGiaoThong) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } db.DenGiaoThong.Add(denGiaoThong); db.SaveChanges(); return(CreatedAtRoute("DefaultApi", new { id = denGiaoThong.ma_den }, denGiaoThong)); }
public IHttpActionResult DeleteDenGiaoThong(int id) { DenGiaoThong denGiaoThong = db.DenGiaoThong.Find(id); if (denGiaoThong == null) { return(NotFound()); } db.DenGiaoThong.Remove(denGiaoThong); db.SaveChanges(); return(Ok(denGiaoThong)); }
// POST: api/DenGiaoThong public IHttpActionResult Post(DenGiaoThong denGiaoThong) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } using (var ctx = new GTVTContext()) { ctx.DenGiaoThongs.Add(new DenGiaoThong() { Do = denGiaoThong.Do, Xanh = denGiaoThong.Xanh, Vang = denGiaoThong.Vang, TrangThai = denGiaoThong.TrangThai, KhuVuc_Id = denGiaoThong.KhuVuc_Id, TenDuong = denGiaoThong.TenDuong }); //ctx.DenGiaoThongs.Add(denGiaoThong); ctx.SaveChanges(); } return(Ok()); }