public IHttpActionResult CapNhatLop(CapNhatLop model) { IHttpActionResult httpActionResult; ErrorModel errors = new ErrorModel(); TTLOP lop = this.db.TTLOPs.FirstOrDefault(x => x.Id == model.Id); if (lop == null) { errors.Add("Không tìm thấy lớp"); httpActionResult = new ErrorActionResult(Request, System.Net.HttpStatusCode.NotFound, errors); } else { lop.MaLop = model.MaLop ?? model.MaLop; lop.TenLop = model.TenLop ?? model.TenLop; lop.gvcn = db.TTGVs.FirstOrDefault(x => x.Id == model.gvcnId); this.db.Entry(lop).State = System.Data.Entity.EntityState.Modified; this.db.SaveChanges(); httpActionResult = Ok(new Lop_model(lop)); } return(httpActionResult); }
public IHttpActionResult CapNhatLop(CapNhatLop update) { IHttpActionResult httpActionresult; ErrorModel error = new ErrorModel(); Class lop = this._db.Lop.FirstOrDefault(x => x.Id == update.Id); if (lop == null) { error.Add("Không tìm thấy lớp"); httpActionresult = Ok(error); } else { lop.MaLop = update.MaLop ?? update.MaLop; lop.TenLop = update.TenLop ?? update.TenLop; lop.LichDay = update.LichDay; lop.ChuNhiem = _db.GiaoVien.FirstOrDefault(x => x.Id == update.ChuNhiem); this._db.Entry(lop).State = System.Data.Entity.EntityState.Modified; this._db.SaveChanges(); httpActionresult = Ok(new ClassModel(lop)); } return(httpActionresult); }