Beispiel #1
0
        public IHttpActionResult CapNhatGiangVien(UpdateGVModel model)
        {
            IHttpActionResult httpActionResult;
            ErrorModel        errors = new ErrorModel();

            GiangVien GV = this._db.GiangViens.FirstOrDefault(x => x.Id == model.Id);

            if (GV == null)
            {
                errors.Add("Không tìm thấy giảng viên có ID này");

                httpActionResult = Ok(errors);
            }
            else
            {
                GV.Ma  = model.Ma ?? model.Ma;
                GV.Ten = model.Ten ?? model.Ten;

                this._db.Entry(GV).State = System.Data.Entity.EntityState.Modified;

                this._db.SaveChanges();

                httpActionResult = Ok(new GiangVienModel(GV));
            }

            return(httpActionResult);
        }
        public IHttpActionResult Update(UpdateGVModel model)
        {
            IHttpActionResult httpActionResult;
            GiaoVien          giaoVien = db.GiaoViens.FirstOrDefault(x => x.Id == model.Id);

            if (giaoVien == null)
            {
                err.Add("Không tìm thấy giáo viên");
                httpActionResult = Ok(err);
            }
            else
            {
                giaoVien.MAGV    = model.MaGV ?? model.MaGV;
                giaoVien.HoTen   = model.HoTen ?? model.HoTen;
                giaoVien.NTNS    = model.NTNS ?? model.NTNS;
                giaoVien.TrinhDo = model.TrinhDo ?? model.TrinhDo;

                db.Entry(giaoVien).State = System.Data.Entity.EntityState.Modified;
                db.SaveChanges();
                httpActionResult = Ok(new GiaoVienModel(giaoVien));
            }
            return(httpActionResult);
        }