Exemplo n.º 1
0
        public IHttpActionResult TaoLop(TaoLop lop)
        {
            IHttpActionResult httpActionResult;
            ErrorModel        error = new ErrorModel();

            if (string.IsNullOrEmpty(lop.MaLop))
            {
                error.Add("Mã lớp bắt buộc");
            }
            if (string.IsNullOrEmpty(lop.TenLop))
            {
                error.Add("Tên lớp bắt buộc");
            }
            if (_db.GiaoVien.FirstOrDefault(m => m.Id == lop.ChuNhiem) == null)
            {
                error.Add("Giáo viên không tồn tại");
            }
            if (error.Errors.Count == 0)
            {
                Class oneClass = new Class();
                oneClass.TenLop   = lop.TenLop;
                oneClass.MaLop    = lop.MaLop;
                oneClass.LichDay  = lop.LichDay;
                oneClass.ChuNhiem = _db.GiaoVien.FirstOrDefault(m => m.Id == lop.ChuNhiem);
                oneClass          = this._db.Lop.Add(oneClass);
                this._db.SaveChanges();
                ClassModel viewModel = new ClassModel(oneClass);
                httpActionResult = Ok(viewModel);
            }
            else
            {
                httpActionResult = Ok(error);
            }
            return(httpActionResult);
        }
Exemplo 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);
        }
Exemplo n.º 3
0
 private void tsTaoLop_Click(object sender, EventArgs e)
 {
     if (!CheckExistFrom("TaoLop"))
     {
         TaoLop frm = new TaoLop();
         frm.MdiParent = this;
         frm.Show();
     }
     else
     {
         ActiveChildForm("TaoLop");
     }
 }