コード例 #1
0
        public ActionResult Create(HocPhanModel hocphan)
        {
            try
            {
                hocphanCollection.InsertOne(hocphan);

                return(RedirectToAction("Index"));
            }
            catch
            {
                return(View());
            }
        }
コード例 #2
0
        public ActionResult Delete(string id, HocPhanModel hocphan)
        {
            try
            {
                hocphanCollection.DeleteOne(Builders <HocPhanModel> .Filter.Eq("_id", ObjectId.Parse(id)));

                return(RedirectToAction("Index"));
            }
            catch
            {
                return(View());
            }
        }
コード例 #3
0
        public HocPhanModel ChiTietHocPhanLog(int HocPhanLogID)
        {
            HocPhanModel model = null;

            try
            {
                model = HocPhanDA.ChiTietHocPhanLog(HocPhanLogID);
            }
            catch (Exception ex)
            {
                throw ex;
            }
            return(model);
        }
コード例 #4
0
        public ResponseResult SuaHocPhan(HocPhanModel model)
        {
            ResponseResult res = null;

            try
            {
                res = HocPhanDA.SuaHocPhan(model);
            }
            catch (Exception ex)
            {
                throw ex;
            }
            return(res);
        }
コード例 #5
0
        public ResponseResult ThemHocPhan(HocPhanModel model)
        {
            ResponseResult res = null;

            try
            {
                model.NguoiTao = AccountUtils.CurrentUsername();
                res            = HocPhanDA.ThemHocPhan(model);
            }
            catch (Exception ex)
            {
                throw ex;
            }
            return(res);
        }
コード例 #6
0
        public HocPhanModel ChiTietHocPhanLog(int HocPhanLogID)
        {
            HocPhanModel model = null;

            try
            {
                List <SqlParameter> listParameter = new List <SqlParameter>();
                listParameter.Add(new SqlParameter("@HocPhanLogID", HocPhanLogID));
                model = DBUtils.ExecuteSP <HocPhanModel>("SP_HocPhan_ChiTiet_Log", listParameter);
            }
            catch (Exception ex)
            {
                throw ex;
            }
            return(model);
        }
コード例 #7
0
        public ActionResult Edit(string id, HocPhanModel hocphan)
        {
            try
            {
                var filter = Builders <HocPhanModel> .Filter.Eq("_id", ObjectId.Parse(id));

                var update = Builders <HocPhanModel> .Update
                             .Set("TenHP", hocphan.TenHP)
                             .Set("TinChi", hocphan.TinChi)
                             .Set("MoTa", hocphan.MoTa);

                var result = hocphanCollection.UpdateOne(filter, update);
                return(RedirectToAction("Index"));
            }
            catch
            {
                return(View());
            }
        }
コード例 #8
0
        public ResponseResult ThemHocPhan(HocPhanModel model)
        {
            ResponseResult res = null;

            try
            {
                List <SqlParameter> listParameter = new List <SqlParameter>();
                listParameter.Add(new SqlParameter("@MaHP", model.MaHP));
                listParameter.Add(new SqlParameter("@TenHocPhan", model.TenHocPhan));
                listParameter.Add(new SqlParameter("@SoTC", model.SoTC));
                listParameter.Add(new SqlParameter("@SoTietLT", model.SoTietLT));
                listParameter.Add(new SqlParameter("@SoTietTH", model.SoTietTH));
                listParameter.Add(new SqlParameter("@BoMonID", model.BoMonID));
                listParameter.Add(new SqlParameter("@TuChon", model.TuChon));
                listParameter.Add(new SqlParameter("@NguoiTao", model.NguoiTao));
                res = DBUtils.ExecuteSP <ResponseResult>("SP_HocPhan_Them", listParameter);
            }
            catch (Exception ex)
            {
                throw ex;
            }
            return(res);
        }
コード例 #9
0
 public ActionResult SuaHocPhan(HocPhanModel model)
 {
     try
     {
         var result = HocPhanService.SuaHocPhan(model);
         if (result != null && result.ResponseCode == 1)
         {
             return(Json(JsonResponseViewModel.CreateSuccess("Cập nhật học phần 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 học phần thất bại.")));
         }
     }
     catch (Exception ex)
     {
         return(Json(JsonResponseViewModel.CreateFail(ex)));
     }
 }
コード例 #10
0
        public ActionResult DangKyHocPhan(List <string> DanhSachHocPhan, List <string> MonHoc)
        {
            if (!isUserNameExist())
            {
                return(RedirectToAction("Index"));
            }
            //Create client connection to our MongoDB database
            var client = new MongoClient(new configWEB().connectionstring);

            //Create a session object that is used when leveraging transactions


            MonHocModel  monHocModel  = new MonHocModel();
            HocPhanModel hocPhanModel = new HocPhanModel();
            AccountModel accountModel = new AccountModel();
            Account      account      = new AccountModel().find_username(Session[currentAccount].ToString());

            List <string> HocPhanDaDangKy_OLD = account.HocPhanDaDangKy;
            List <bool>   trungID             = new List <bool>();

            for (int i = 0; i < HocPhanDaDangKy_OLD.Count(); i++)
            {
                if (HocPhanDaDangKy_OLD[i] == DanhSachHocPhan[i])
                {
                    trungID.Add(true);
                }
                else
                {
                    trungID.Add(false);
                }
            }
            string monHoc_Success = "";
            string monHoc_ThatBai = "";
            bool   isThatBai      = false;

            if (account != null)
            {
                using (var session = client.StartSession())
                {
                    account.Status = true;
                    accountModel.update(account);
                    session.StartTransaction(new TransactionOptions(
                                                 readConcern: ReadConcern.Snapshot,
                                                 writeConcern: WriteConcern.WMajority));
                    try
                    {
                        account.Status          = false;
                        account.HocPhanDaDangKy = DanhSachHocPhan;
                        accountModel.updateHocPhanDaDangKy(account, session);
                        for (int i = 0; i < DanhSachHocPhan.Count(); i++)
                        {
                            if (DanhSachHocPhan[i] != "")
                            {
                                while (monHocModel.getHocphan(MonHoc[i], account.HocPhanDaDangKy[i]).Status == true)
                                {
                                    if (monHocModel.getHocphan(MonHoc[i], account.HocPhanDaDangKy[i]).Status == false)
                                    {
                                        break;
                                    }
                                }
                                monHocModel.lockHocPhan(DanhSachHocPhan[i]);

                                if (monHocModel.ConLai(account.HocPhanDaDangKy[i],
                                                       monHocModel.getHocphan(MonHoc[i],
                                                                              account.HocPhanDaDangKy[i]).SiSo) > 0 || trungID[i] == true)
                                {
                                    monHoc_Success = monHoc_Success + ", " + monHocModel.find(MonHoc[i]).TenMonHoc + " ";
                                }
                                else
                                {
                                    monHoc_ThatBai = monHoc_ThatBai + ", " + monHocModel.find(MonHoc[i]).TenMonHoc + " ";
                                    isThatBai      = true;
                                }
                            }
                        }



                        Thread.Sleep(3000);



                        for (int i = 0; i < DanhSachHocPhan.Count(); i++)
                        {
                            if (DanhSachHocPhan[i] != "")
                            {
                                monHocModel.unlockHocPhan(DanhSachHocPhan[i]);
                            }
                        }

                        if (isThatBai)
                        {
                            ThongBao_Error("học phần môn " + monHoc_ThatBai + " đã hết chỗ , vui lòng chọn học phần khác");
                            session.AbortTransactionAsync();
                            ViewBag.listMonHoc  = monHocModel.findAll();
                            ViewBag.accountInfo = accountModel.find_username(Session[currentAccount].ToString());

                            account.Status          = false;
                            account.HocPhanDaDangKy = HocPhanDaDangKy_OLD;
                            accountModel.update(account);
                            return(View(HocPhanDaDangKy_OLD));
                        }
                        else
                        {
                            ThongBao_Success("Đăng ký học phần " + monHoc_Success + "  thành công!");
                            session.CommitTransaction();
                            ViewBag.listMonHoc  = monHocModel.findAll();
                            ViewBag.accountInfo = accountModel.find_username(Session[currentAccount].ToString());
                            return(View(DanhSachHocPhan));
                        }
                    }
                    catch (Exception e)
                    {
                        account.Status          = false;
                        account.HocPhanDaDangKy = HocPhanDaDangKy_OLD;
                        accountModel.update(account);

                        ThongBao_Error("Error writing to MongoDB: " + e.Message);
                        session.AbortTransaction();
                        ViewBag.listMonHoc  = monHocModel.findAll();
                        ViewBag.accountInfo = accountModel.find_username(Session[currentAccount].ToString());
                        return(View(HocPhanDaDangKy_OLD));
                    }
                }
            }



            ViewBag.listMonHoc  = monHocModel.findAll();
            ViewBag.accountInfo = accountModel.find_username(Session[currentAccount].ToString());
            return(View(DanhSachHocPhan));
        }