public IHttpActionResult PutCauTraLoi(int id, CauTraLoi cauTraLoi)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            if (id != cauTraLoi.IDCauTraLoi)
            {
                return(BadRequest());
            }

            db.Entry(cauTraLoi).State = EntityState.Modified;

            try
            {
                db.SaveChanges();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!CauTraLoiExists(id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(StatusCode(HttpStatusCode.NoContent));
        }
        public ActionResult DeleteConfirmed(int id)
        {
            CauTraLoi cauTraLoi = db.CauTraLois.Find(id);

            db.CauTraLois.Remove(cauTraLoi);

            db.SaveChanges();
            return(RedirectToAction("Index", new { stringId = TempData["IdTemplate"] }));
        }
Exemple #3
0
        //Nộp Bài
        private void btnSubmit_Click(object sender, EventArgs e)
        {
            Thoi_Gian.Stop();
            Luu_Cau_Tra_Loi();
            double So_cau_Dung = 0;
            double Tong_So_cau = De.De.Count;
            double Diem;

            for (int i = 0; i < DS_Cau_Tra_Loi.Count; i++)
            {
                if (DS_Cau_Tra_Loi[i].cau_tra_loi.Replace(" ", "") == DS_Cau_Tra_Loi[i].Dap_An.Replace(" ", ""))
                {
                    So_cau_Dung++;
                }
            }
            Diem = (So_cau_Dung / Tong_So_cau) * 10;
            Diem = Math.Round(Diem, 2);

            for (int i = 0; i < De.De.Count; i++)
            {
                if (i > DS_Cau_Tra_Loi.Count - 1)
                {
                    CauTraLoi cauTraLoi = new CauTraLoi();
                    cauTraLoi.new_Cau_Tra_Loi(i, "", De.De[i].Dap_An);
                    DS_Cau_Tra_Loi.Add(cauTraLoi);
                }
            }
            frmDap_An.DS_Cau_Tra_Loi = DS_Cau_Tra_Loi;
            KETQUATHI kqua = new KETQUATHI();

            kqua.MaKyThi         = _ma_ky_thi_;
            kqua.MaDeThi         = _ma_de_thi_;
            kqua.TaiKhoan        = hs.Tai_Khoan;
            kqua.Diem            = Diem;
            kqua.ThoiGianBatDau  = Start_time;
            kqua.ThoiGianKetThuc = End_time;

            if (BUS_Hoc_Sinh.Luu_Ket_Qua(kqua) == true)
            {
                MessageBox.Show("Đã Lưu ^_^", "Thông Báo", MessageBoxButtons.OK, MessageBoxIcon.Information);
                frmKetQua.Diem = Diem;
                frmKetQua frmKetQua1 = new frmKetQua();
                frmKetQua1.ShowDialog();
            }
            else
            {
                MessageBox.Show("Đã Có Kết Quả Đề Này ^_^", "Thông Báo", MessageBoxButtons.OK, MessageBoxIcon.Information);
            }

            btnSubmit.Enabled      = false;
            btnNext.Enabled        = false;
            btnPrev.Enabled        = false;
            btnStart_Pause.Enabled = false;
        }
        public IHttpActionResult GetCauTraLoi(int id)
        {
            CauTraLoi cauTraLoi = db.CauTraLois.Find(id);

            if (cauTraLoi == null)
            {
                return(NotFound());
            }

            return(Ok(cauTraLoi));
        }
 public ActionResult Edit([Bind(Include = "IDCauTraLoi,UserID,HoTen,MSNV,Email,IDChuDe,IDTemplate")] CauTraLoi cauTraLoi)
 {
     if (ModelState.IsValid)
     {
         db.Entry(cauTraLoi).State = EntityState.Modified;
         db.Entry(cauTraLoi).Property(x => x.UserID).IsModified = false;
         db.SaveChanges();
         return(RedirectToAction("Index", new { stringId = TempData["IdTemplate"] }));
     }
     ViewBag.IDChuDe    = new SelectList(db.ChuDes, "IDChuDe", "TenChuDe", cauTraLoi.IDChuDe);
     ViewBag.IDTemplate = new SelectList(db.Templates, "IDTemplate", "TenTemplate", cauTraLoi.IDTemplate);
     return(View(cauTraLoi));
 }
        // GET: CauTraLois/Details/5
        public ActionResult Details(int?id, string stringId)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            CauTraLoi cauTraLoi = db.CauTraLois.Find(id);

            if (cauTraLoi == null)
            {
                return(HttpNotFound());
            }
            return(View(cauTraLoi));
        }
        public IHttpActionResult DeleteCauTraLoi(int id)
        {
            CauTraLoi cauTraLoi = db.CauTraLois.Find(id);

            if (cauTraLoi == null)
            {
                return(NotFound());
            }

            db.CauTraLois.Remove(cauTraLoi);
            db.SaveChanges();

            return(Ok(cauTraLoi));
        }
        public ActionResult Create([Bind(Include = "IDCauTraLoi,UserID,HoTen,MSNV,Email,IDChuDe,IDTemplate")] CauTraLoi cauTraLoi)
        {
            if (ModelState.IsValid)
            {
                cauTraLoi.IDCauTraLoi = CreateCauTraLoiId();
                cauTraLoi.UserID      = CreateUserId(cauTraLoi);
                db.CauTraLois.Add(cauTraLoi);
                db.SaveChanges();
                return(RedirectToAction("Index", new { stringId = TempData["IdTemplate"] }));
            }

            ViewBag.IDChuDe    = new SelectList(db.ChuDes, "IDChuDe", "TenChuDe", cauTraLoi.IDChuDe);
            ViewBag.IDTemplate = new SelectList(db.Templates, "IDTemplate", "TenTemplate", cauTraLoi.IDTemplate);
            return(View(cauTraLoi));
        }
        // GET: CauTraLois/Edit/5
        public ActionResult Edit(int?id, string stringId)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            CauTraLoi cauTraLoi = db.CauTraLois.Find(id);

            if (cauTraLoi == null)
            {
                return(HttpNotFound());
            }
            ViewBag.IDChuDe    = new SelectList(db.ChuDes, "IDChuDe", "TenChuDe", cauTraLoi.IDChuDe);
            ViewBag.IDTemplate = new SelectList(db.Templates, "IDTemplate", "TenTemplate", cauTraLoi.IDTemplate);
            return(View(cauTraLoi));
        }
        public IHttpActionResult PostCauTraLoi(CauTraLoi cauTraLoi)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            cauTraLoi.UserID = CreateIDUser(cauTraLoi);
            foreach (var item in cauTraLoi.CauTraLoi_ChiTiet)
            {
                item.IDCauTraLoiChiTiet = cauTraLoi.IDCauTraLoi;
            }
            db.CauTraLois.Add(cauTraLoi);
            db.SaveChanges();

            return(CreatedAtRoute("DefaultApi", new { id = cauTraLoi.IDCauTraLoi }, cauTraLoi));
        }
        private int CreateUserId(CauTraLoi traLoi)
        {
            var user = db.CauTraLois.Where(x => x.HoTen == traLoi.HoTen && x.MSNV == traLoi.MSNV && x.Email == traLoi.Email);

            if (user.Count() == 0)
            {
                var userLastRow = db.CauTraLois.OrderByDescending(x => x.UserID).FirstOrDefault();
                if (userLastRow == null)
                {
                    return(1);
                }
                else
                {
                    return(userLastRow.UserID.Value + 1);
                }
            }
            else
            {
                return(user.FirstOrDefault().UserID.Value);
            }
        }
        private int CreateIDUser(CauTraLoi cauTraLoi)
        {
            var user = db.CauTraLois.Where(x => x.HoTen == cauTraLoi.HoTen && x.MSNV == cauTraLoi.MSNV && x.Email == cauTraLoi.Email);

            if (user.Count() == 0)
            {
                var newid = user.OrderByDescending(x => x.UserID).FirstOrDefault();
                if (newid == null)
                {
                    return(1);
                }
                else
                {
                    return(newid.UserID.Value + 1);
                }
            }
            else
            {
                return(user.OrderByDescending(x => x.UserID).Select(x => x.UserID).FirstOrDefault().Value + 1);
            }
        }
Exemple #13
0
        //Nộp Bài
        private void Luu_Cau_Tra_Loi()
        {
            End_time = DateTime.Now;
            CauTraLoi ctl = new CauTraLoi();

            if (rbtn_A.Checked)
            {
                ctl.new_Cau_Tra_Loi(_vi_tri_Cau_hoi_, rbtn_A.Text, De.De[_vi_tri_Cau_hoi_].Dap_An);
            }
            else if (rbtn_B.Checked)
            {
                ctl.new_Cau_Tra_Loi(_vi_tri_Cau_hoi_, rbtn_B.Text, De.De[_vi_tri_Cau_hoi_].Dap_An);
            }
            else if (rbtn_C.Checked)
            {
                ctl.new_Cau_Tra_Loi(_vi_tri_Cau_hoi_, rbtn_C.Text, De.De[_vi_tri_Cau_hoi_].Dap_An);
            }
            else if (rbtn_D.Checked)
            {
                ctl.new_Cau_Tra_Loi(_vi_tri_Cau_hoi_, rbtn_D.Text, De.De[_vi_tri_Cau_hoi_].Dap_An);
            }
            else
            {
                ctl.new_Cau_Tra_Loi(_vi_tri_Cau_hoi_, "", De.De[_vi_tri_Cau_hoi_].Dap_An);
            }

            for (int i = 0; i < DS_Cau_Tra_Loi.Count; i++)
            {
                if (DS_Cau_Tra_Loi[i].index == _vi_tri_Cau_hoi_)
                {
                    DS_Cau_Tra_Loi[i] = ctl;
                    return;
                }
            }


            DS_Cau_Tra_Loi.Add(ctl);
        }
Exemple #14
0
        public IHttpActionResult PostCauTraLoi(CauTraLoi traLoi)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }
            traLoi.IDCauTraLoi = CreateIdCauTraLoi();
            traLoi.UserID      = CreateUserId(traLoi);

            // insert vào bảng chi tiết ở db
            int i = 0;

            foreach (var item in traLoi.CauTraLoi_ChiTiet)
            {
                item.IDCauTraLoiChiTiet = CreateIdChiTiet() + i;
                item.IDCauTraLoi        = traLoi.IDCauTraLoi;
                i++;
            }

            db.CauTraLois.Add(traLoi);
            try
            {
                db.SaveChanges();
            }
            catch (DbUpdateException)
            {
                if (CauTraLoiExists(traLoi.IDCauTraLoi))
                {
                    return(Conflict());
                }
                else
                {
                    throw;
                }
            }
            return(CreatedAtRoute("DefaultApi", new { id = traLoi.IDCauTraLoi }, traLoi));
        }
Exemple #15
0
        public async Task <IActionResult> TraLoi(CauTraLoi model)
        {
            var ct = await _serviceCT.GetById(model.IdCT);

            ct.CauTraLoi = model.TraLoi;
            if (await UpLoadFile(model.File, ct))
            {
                await _serviceCT.Update(ct);

                return(Ok(new
                {
                    status = true,
                    mess = MessageResult.UpdateSuccess
                }));
            }
            else
            {
                return(Ok(new
                {
                    status = false,
                    mess = MessageResult.UpLoadFileFail
                }));
            }
        }