Exemplo n.º 1
0
        public IHttpActionResult TaoGV(TaoGiaoVien model)
        {
            IHttpActionResult httpActionResult;
            ErrorModel        errors = new ErrorModel();

            if (string.IsNullOrEmpty(model.MaGv))
            {
                errors.Add("Mã giao vien là trường bắt buộc");
            }

            if (errors.Errors.Count == 0)
            {
                TTGV gv = new TTGV();
                gv.MaGv     = model.MaGv;
                gv.HoTen    = model.HoTen;
                gv.NgaySinh = model.NgaySinh;

                gv = db.TTGVs.Add(gv);

                this.db.SaveChanges();

                GiaoVien_model Lopm = new GiaoVien_model(gv);

                httpActionResult = Ok(Lopm);
            }
            else
            {
                httpActionResult = new ErrorActionResult(Request, System.Net.HttpStatusCode.BadRequest, errors);
            }

            return(httpActionResult);
        }
Exemplo n.º 2
0
        public IHttpActionResult CapNhatGV(CapNhatGiaoVien model)
        {
            IHttpActionResult httpActionResult;
            ErrorModel        errors = new ErrorModel();

            TTGV gv = this.db.TTGVs.FirstOrDefault(x => x.Id == model.Id);

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

                httpActionResult = new ErrorActionResult(Request, System.Net.HttpStatusCode.NotFound, errors);
            }
            else
            {
                gv.MaGv     = model.MaGv ?? model.MaGv;
                gv.NgaySinh = model.NgaySinh;
                gv.HoTen    = model.HoTen ?? model.HoTen;

                this.db.Entry(gv).State = System.Data.Entity.EntityState.Modified;

                this.db.SaveChanges();

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

            return(httpActionResult);
        }
Exemplo n.º 3
0
 public GiaoVien_model(TTGV ttgv)
 {
     this.Id       = ttgv.Id;
     this.MaGv     = ttgv.MaGv;
     this.HoTen    = ttgv.HoTen;
     this.NgaySinh = ttgv.NgaySinh;
 }