コード例 #1
0
        public IHttpActionResult Update(UpdateTeacherModel model)
        {
            IHttpActionResult httpActionResult;
            ErrorModel        errors = new ErrorModel();

            Teacher gv = this._db.Teacher.FirstOrDefault(x => x.Id == model.Id);

            if (gv == null)
            {
                errors.Add("Không tìm thấy giáo viên này");
                httpActionResult = new ErrorActionResult(Request, System.Net.HttpStatusCode.NotFound, errors);
            }
            else
            {
                gv.MaGV  = model.MaGV ?? model.MaGV;
                gv.TenGV = model.TenGV ?? model.TenGV;
                this._db.Entry(gv).State = System.Data.Entity.EntityState.Modified;

                this._db.SaveChanges();

                httpActionResult = Ok(new TeacherModel(gv));
            }

            return(httpActionResult);
        }
コード例 #2
0
        public IHttpActionResult UpdateTeacher(UpdateTeacherModel model)
        {
            IHttpActionResult httpActionResult;
            ErrorModel        error = new ErrorModel();
            Teacher           tc    = this._db.Teacher.FirstOrDefault(x => x.Id == model.Id);

            if (tc == null)
            {
                error.Add("Không tìm thấy Giáo viên!");
                httpActionResult = new ErrorActionResult(Request, System.Net.HttpStatusCode.BadRequest, error);
            }
            else
            {
                tc.TeacherName           = model.TeacherName ?? model.TeacherName;
                tc.TeacherId             = model.TeacherId;
                tc.TeacherAddress        = model.TeacherAddress ?? model.TeacherAddress;
                this._db.Entry(tc).State = System.Data.Entity.EntityState.Modified;
                this._db.SaveChanges();
                httpActionResult = Ok(new TeacherModel(tc));
            }
            return(httpActionResult);
        }