Esempio n. 1
0
        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);
        }
Esempio n. 2
0
        public IHttpActionResult TaoLop(TaoLop tl)
        {
            IHttpActionResult httpActionResult;
            ErrorModel        errors = new ErrorModel();

            if (string.IsNullOrEmpty(tl.MaLop))
            {
                errors.Add("Mã lớp là trường bắt buộc");
            }

            if (errors.Errors.Count == 0)
            {
                TTLOP lop = new TTLOP();
                lop.MaLop  = tl.MaLop;
                lop.TenLop = tl.TenLop;
                lop.gvcn   = db.TTGVs.FirstOrDefault(x => x.Id == tl.gvcnId);

                lop = db.TTLOPs.Add(lop);

                this.db.SaveChanges();

                Lop_model Lopm = new Lop_model(lop);

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

            return(httpActionResult);
        }
Esempio n. 3
0
 public Lop_model(TTLOP ttlop)
 {
     this.Id     = ttlop.Id;
     this.MaLop  = ttlop.MaLop;
     this.TenLop = ttlop.TenLop;
     this.gvcnId = ttlop.gvcn.Id;
 }