Exemple #1
0
 public JsonResult Insert(LopModel lop)
 {
     using (ELearningDB db = new ELearningDB())
     {
         var session = (TaiKhoanLogin)Session[CommonConstants.USER_SESSION];
         if (lop != null && db.Lops.Where(x => x.MaGiangVien == session.ID).Count() < 5)
         {
             Lop l = new Lop();
             l.TenLop      = lop.TenLop;
             l.TrangThai   = true;
             l.MaGiangVien = session.ID;
             l.MaMonHoc    = lop.MaMonHoc;
             l.NgayBatDau  = lop.StartDate;
             l.Image       = lop.Image;
             l.SiSo        = 0;
             l.MoTa        = lop.MoTa;
             db.Lops.Add(l);
             db.SaveChanges();
             return(Json(new { success = true }));
         }
         else
         {
             return(Json(new { success = false }));
         }
     }
 }
        public IHttpActionResult TaoLop(CreateClassModel model)
        {
            IHttpActionResult httpActionResult;
            ErrorModel        errors = new ErrorModel();

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

            if (errors.Errors.Count == 0)
            {
                Lop lop = new Lop();
                lop.MaLop  = model.MaLop;
                lop.TenLop = model.TenLop;
                //lop.GVCN_ID = model.GVCN_ID;
                lop = _db.Lops.Add(lop);

                this._db.SaveChanges();

                LopModel viewModel = new LopModel(lop);

                httpActionResult = Ok(viewModel);
            }
            else
            {
                httpActionResult = Ok(errors);
            }

            return(httpActionResult);
        }
Exemple #3
0
        public JsonResult GetLop()
        {
            var session = (TaiKhoanLogin)Session[CommonConstants.USER_SESSION];

            using (ELearningDB db = new ELearningDB())
            {
                List <LopModel> Lops   = new List <LopModel>();
                List <Lop>      lstLop = db.Lops.Where(x => x.MaGiangVien == session.ID).ToList();
                foreach (var item in lstLop)
                {
                    LopModel l = new LopModel();
                    l.MaLop       = item.MaLop;
                    l.TenLop      = item.TenLop;
                    l.TrangThai   = item.TrangThai;
                    l.MaMonHoc    = (int)item.MaMonHoc;
                    l.NgayBatDau  = item.NgayBatDau.ToString();
                    l.NgayKetThuc = item.NgayKetThuc.ToString();
                    l.Image       = item.Image;
                    l.SiSo        = item.SiSo;
                    l.MoTa        = item.MoTa;
                    Lops.Add(l);
                }
                return(Json(Lops, JsonRequestBehavior.AllowGet));
            }
        }
Exemple #4
0
 private void gridlop_SelectedItemChanged(object sender, DevExpress.Xpf.Grid.SelectedItemChangedEventArgs e)
 {
     try
     {
         LopModel select = gridlop.SelectedItem as LopModel;
         Lop      lop    = lopControll.GetById(select.MaLop);
         _txtmalop.Text  = lop.MaLop;
         _txttenlop.Text = lop.TenLop;
     }
     catch { }
 }
        public ResponseResult SuaLop(LopModel model)
        {
            ResponseResult res = null;

            try
            {
                res = LopDA.SuaLop(model);
            }
            catch (Exception ex)
            {
                throw ex;
            }
            return(res);
        }
        public LopModel ChiTietLop(int LopID)
        {
            LopModel model = null;

            try
            {
                model = LopDA.ChiTietLop(LopID);
            }
            catch (Exception ex)
            {
                throw ex;
            }
            return(model);
        }
        public ResponseResult ThemLop(LopModel model)
        {
            ResponseResult res = null;

            try
            {
                model.NguoiTao = AccountUtils.CurrentUsername();
                res            = LopDA.ThemLop(model);
            }
            catch (Exception ex)
            {
                throw ex;
            }
            return(res);
        }
        public LopModel ChiTietLop(int LopID)
        {
            LopModel model = null;

            try
            {
                List <SqlParameter> listParameter = new List <SqlParameter>();
                listParameter.Add(new SqlParameter("@LopID", LopID));
                model = DBUtils.ExecuteSP <LopModel>("SP_Lop_ChiTiet", listParameter);
            }
            catch (Exception ex)
            {
                throw ex;
            }
            return(model);
        }
Exemple #9
0
        public JsonResult Details(int id)
        {
            using (ELearningDB db = new ELearningDB())
            {
                Lop      l   = db.Lops.Find(id);
                LopModel Lop = new LopModel();
                Lop.MaLop      = l.MaLop;
                Lop.TenLop     = l.TenLop;
                Lop.TrangThai  = l.TrangThai;
                Lop.NgayBatDau = l.NgayBatDau.ToString();;
                Lop.HoTenGV    = l.GiangVien.HoVaTen;
                Lop.TenMonHoc  = l.MonHoc.TenMonHoc;
                Lop.MoTa       = l.MoTa;
                Lop.SiSo       = l.SiSo;

                return(Json(Lop, JsonRequestBehavior.AllowGet));
            }
        }
        public ResponseResult ThemLop(LopModel model)
        {
            ResponseResult res = null;

            try
            {
                List <SqlParameter> listParameter = new List <SqlParameter>();
                listParameter.Add(new SqlParameter("@MaLop", model.MaLop));
                listParameter.Add(new SqlParameter("@KhoaID", model.KhoaID));
                listParameter.Add(new SqlParameter("@GiangVienID", model.GiangVienID));
                listParameter.Add(new SqlParameter("@NguoiTao", model.NguoiTao));
                res = DBUtils.ExecuteSP <ResponseResult>("SP_Lop_Them", listParameter);
            }
            catch (Exception ex)
            {
                throw ex;
            }
            return(res);
        }
Exemple #11
0
 public JsonResult Update(LopModel UpdateLop)
 {
     using (ELearningDB db = new ELearningDB())
     {
         Lop lop = db.Lops.Find(UpdateLop.MaLop);
         if (lop == null)
         {
             return(Json(new { success = false }));
         }
         else
         {
             lop.MaLop      = UpdateLop.MaLop;
             lop.TenLop     = UpdateLop.TenLop;
             lop.MoTa       = UpdateLop.MoTa;
             lop.NgayBatDau = UpdateLop.StartDate;
             lop.Image      = UpdateLop.Image;
             lop.MaMonHoc   = UpdateLop.MaMonHoc;
             db.SaveChanges();
             return(Json(new { success = true }));
         }
     }
 }
Exemple #12
0
        public IHttpActionResult TaoMoi(TaoLopModel model)
        {
            IHttpActionResult httpActionResult;

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

            if (string.IsNullOrEmpty(model.TenLop))
            {
                err.Add("Tên lớp là trường bắt buộc");
            }
            var GVCN = db.GiaoViens.FirstOrDefault(x => x.Id == model.GVChuNhiem);

            if (GVCN == null)
            {
                err.Add("Không tìm thấy giáo viên");
            }
            if (err.errors.Count == 0)
            {
                Lop lop = new Lop();
                lop.MaLop      = model.MaLop;
                lop.TenLop     = model.TenLop;
                lop.SiSo       = model.SiSo;
                lop.GVChuNhiem = GVCN;
                lop            = db.Lops.Add(lop);
                db.SaveChanges();
                LopModel viewmodel = new LopModel(lop);
                httpActionResult = Ok(viewmodel);
            }
            else
            {
                httpActionResult = new ErrorActionResult(Request, System.Net.HttpStatusCode.BadRequest, err);
            }

            return(httpActionResult);
        }
 public ActionResult SuaLop(LopModel model)
 {
     try
     {
         var result = LopService.SuaLop(model);
         if (result != null && result.ResponseCode == 1)
         {
             return(Json(JsonResponseViewModel.CreateSuccess("Cập nhật lớp thành công.")));
         }
         else if (result != null && result.ResponseCode == -1)
         {
             return(Json(JsonResponseViewModel.CreateFail(result.ResponseMessage)));
         }
         else
         {
             return(Json(JsonResponseViewModel.CreateFail("Cập nhật lớp thất bại.")));
         }
     }
     catch (Exception ex)
     {
         return(Json(JsonResponseViewModel.CreateFail(ex)));
     }
 }
Exemple #14
0
        public IHttpActionResult Create(CreateLopModel model)
        {
            IHttpActionResult httpActionResult;

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

            if (string.IsNullOrEmpty(model.TenLop))
            {
                err.Add("Tên lớp là trường bắt buộc");
            }
            var GVCN = db.GiaoViens.FirstOrDefault(x => x.Id == model.GVChuNhiem);

            if (GVCN == null)
            {
                err.Add("Giáo viên không tồn tại");
            }
            if (err.errors.Count == 0)
            {
                Lop lop = new Lop();
                lop.MaLop    = model.MaLop;
                lop.TenLop   = model.TenLop;
                lop.GiaoVien = db.GiaoViens.FirstOrDefault(x => x.Id == model.GVChuNhiem);
                lop          = db.Lops.Add(lop);
                db.SaveChanges();
                LopModel viewmodel = new LopModel(lop);
                httpActionResult = Ok(viewmodel);
            }
            else
            {
                httpActionResult = Ok(err);
            }

            return(httpActionResult);
        }
Exemple #15
0
 public List <LopModel> GetListTableModelBySearch(string search)
 {
     return(LopModel.ToListByListLop(_LopControls.GetBySearch(search)));
 }