Пример #1
0
        public IHttpActionResult Update(UpdateClassModel model)
        {
            IHttpActionResult httpActionResult;
            ErrorModel        errors = new ErrorModel();

            Classes lop = this._db.Class.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.GiaoVienChuNhiem      = _db.Teacher.FirstOrDefault(m => m.Id == model.GVCN_Id);
                this._db.Entry(lop).State = System.Data.Entity.EntityState.Modified;

                this._db.SaveChanges();

                httpActionResult = Ok(new ClassModel(lop));
            }

            return(httpActionResult);
        }
Пример #2
0
        public IHttpActionResult CapNhatLop(UpdateClassModel model)
        {
            IHttpActionResult httpActionResult;
            ErrorModel        errors = new ErrorModel();

            Lop lop = this._db.Lops.FirstOrDefault(x => x.Id == model.Id);

            if (lop == null)
            {
                errors.Add("Không tìm thấy lớp");

                httpActionResult = Ok(errors);
            }
            else
            {
                lop.MaLop  = model.MaLop ?? model.MaLop;
                lop.TenLop = model.TenLop ?? model.TenLop;

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

                this._db.SaveChanges();

                httpActionResult = Ok(new ClassModel(lop));
            }

            return(httpActionResult);
        }
Пример #3
0
        public IHttpActionResult UpdateClass(UpdateClassModel model)
        {
            IHttpActionResult httpActionResult;
            ErrorModel        error = new ErrorModel();
            Class             lop   = this._db.Class.FirstOrDefault(x => x.Id == model.Id);

            if (lop == null)
            {
                error.Add("Không tìm thấy lớp!");
                httpActionResult = new ErrorActionResult(Request, System.Net.HttpStatusCode.BadRequest, error);
            }
            else
            {
                lop.ClassId               = model.ClassId ?? model.ClassId;
                lop.ClassName             = model.ClassName ?? model.ClassName;
                lop.LearningTime          = model.LearningTime;
                lop.Homeroom              = _db.Teacher.FirstOrDefault(x => x.Id == model.Homeroom_Teacher);
                this._db.Entry(lop).State = System.Data.Entity.EntityState.Modified;
                this._db.SaveChanges();
                httpActionResult = Ok(new ClassModel(lop));
            }
            return(httpActionResult);
        }