示例#1
0
        public ActionResult ChitietbaitapSubmit(List <TraLoi> tralois, HttpPostedFileBase file, int idbt)
        {
            var      hv      = new HocVienDAO().FindByTDN(User.Identity.Name);
            DateTime now     = DateTime.Now;
            DateTime tsubmit = DateTime.Parse(Session[idbt.ToString()].ToString());
            double   phut    = tsubmit.Subtract(now).TotalMinutes;

            if (file != null && file.ContentLength > 0)
            {
                var    dao       = new fileTraLoiDAO();
                string _FileName = Path.GetFileName(file.FileName);
                string path      = "Content/Data/traloi/hv" + hv.id + "/bt" + idbt + "/";
                string _path     = Path.Combine(Server.MapPath("~/" + path), _FileName);
                Directory.CreateDirectory(Path.Combine(Server.MapPath("~/" + path)));
                file.SaveAs(_path);
                int fileSize = file.ContentLength;
                int Size     = fileSize / 1000000;
                var filetl   = new fileTraLoi();
                filetl.ten       = _FileName;
                filetl.FileSize  = Size;
                filetl.link      = "~/" + _FileName;
                filetl.idBT      = idbt;
                filetl.thoiGian  = DateTime.Now;
                filetl.idHV      = hv.id;
                filetl.trangThai = 1;           //0:dong 1:mo
                filetl.tgLamBai  = Convert.ToInt32(phut);
                dao.Insert(filetl);
            }
            //else
            //{
            //    var dao = new fileTraLoiDAO();

            //    var filetl = new fileTraLoi();
            //    filetl.idBT = idbt;
            //    filetl.thoiGian = DateTime.Now;
            //    filetl.idHV = hv.id;
            //    filetl.trangThai = 1;           //0:dong 1:mo
            //    dao.Insert(filetl);
            //}
            var daotl = new TraLoiDAO();

            foreach (var item in tralois)
            {
                var tl = new TraLoi();
                tl.idCauHoi = item.idCauHoi;
                tl.DapAn    = item.DapAn;
                tl.idHV     = hv.id;
                tl.thoiGian = DateTime.Now;
                tl.tgLamBai = Convert.ToInt32(phut);
                daotl.Insert(tl);
            }
            TempData["testmsg"] = "Nộp bài thành công.";
            Session.Clear();
            return(RedirectToAction("Chitietbaitap", "Learning", new { idbt = idbt }));
            //return RedirectToAction("Index", "Learning");
        }
        public ActionResult PostReply(TraLoi tl)
        {
            TraLoi info = (TraLoi)Session["NguoiDung"];

            tl.NguoiDung = info.NguoiDung;
            tl.NgayDang  = DateTime.Now;
            db.TraLois.Add(tl);
            db.SaveChanges();
            return(Redirect(Request.UrlReferrer.ToString()));
        }
示例#3
0
        public bool Update(TraLoi entity)
        {
            try
            {
                var tl = db.TraLois.Find(entity.ID);

                db.SaveChanges();
                return(true);
            }catch (Exception ex)
            {
                return(false);
            }
        }
        public ActionResult ThemTraLoi(TraLoi tl)
        {
            KhachHang info = (KhachHang)Session["kh"];

            if (info == null)
            {
                return(Redirect(Request.UrlReferrer.ToString()));
            }
            tl.MaNguoiDung = info.MaKhachHang;
            tl.NgayDang    = DateTime.Now;
            db.TraLois.Add(tl);
            db.SaveChanges();
            return(Redirect(Request.UrlReferrer.ToString()));
        }
示例#5
0
        public IActionResult ReplyComment(string userId, string maBl, string maSp, IFormCollection fc)
        {
            if (!string.IsNullOrEmpty(fc["ReplyComment"].ToString()))
            {
                TraLoi tl = new TraLoi()
                {
                    MaBinhLuan = maBl,
                    NoiDung    = fc["ReplyComment"],
                    MaKh       = userId,
                    NgayDang   = DateTime.Now
                };

                context.TraLoi.Add(tl);
                context.SaveChanges();
                return(RedirectToAction("SanPham", "SanPham", new { Id = maSp }));
            }
            else
            {
                return(RedirectToAction("SanPham", "SanPham", new { Id = maSp }));
            }
        }
示例#6
0
        public ActionResult Chitietbaitap(int idbt)
        {
            var dao   = new BaiTapDAO();
            var model = dao.GetByID(idbt);

            ViewBag.CountSubmit = dao.CountSubmit(idbt);
            var hv = new HocVienDAO().FindByTDN(User.Identity.Name);

            ViewBag.hv = hv;
            List <TraLoi> tralois = new List <TraLoi>();

            foreach (var i in model.CauHois)
            {
                var tl = new TraLoi();
                tl.CauHoi   = i;
                tl.idCauHoi = i.ID;
                tl.HocVien  = hv;
                tl.idHV     = hv.id;
                tralois.Add(tl);
            }
            ViewBag.tralois = tralois;
            string   d = null;
            DateTime timenop;
            int      timeLam = 0;

            if (hv.fileTraLois.Where(x => x.idBT == idbt).Count() > 0 || hv.TraLois.Where(x => x.CauHoi.idBT == idbt).Count() > 0)
            {
                d = new TraLoiDAO().Diem(idbt, hv.id);
                try
                {
                    timenop         = hv.fileTraLois.Where(x => x.idBT == idbt).FirstOrDefault().thoiGian;
                    ViewBag.timenop = timenop;
                    timeLam         = Convert.ToInt32(hv.fileTraLois.Where(x => x.idBT == idbt).FirstOrDefault().tgLamBai);
                    ViewBag.timeLam = timeLam;
                }
                catch
                {
                    timenop         = hv.TraLois.Where(x => x.CauHoi.idBT == idbt).FirstOrDefault().thoiGian;
                    ViewBag.timenop = timenop;
                    timeLam         = Convert.ToInt32(hv.TraLois.Where(x => x.CauHoi.idBT == idbt).FirstOrDefault().tgLamBai);
                    ViewBag.timeLam = timeLam;
                }
            }
            ViewBag.diem    = d;
            ViewBag.timeLam = timeLam;
            if (string.IsNullOrEmpty(Session[idbt.ToString()] as string))
            {
                try
                {
                    DateTime dt = DateTime.Now.AddMinutes(double.Parse(model.thoiGianLamBai.ToString()));
                    Session[idbt.ToString()] = dt.ToString();
                }
                catch
                {
                    Session[idbt.ToString()] = "";
                }
            }

            string ttt = Session[idbt.ToString()].ToString();

            return(View("Chitietbaitap", model));
        }
示例#7
0
 public int Insert(TraLoi entity)
 {
     db.TraLois.Add(entity);
     db.SaveChanges();
     return(entity.ID);
 }
示例#8
0
        public ActionResult ChoKiemTRa(Admin admin)
        {
            int?dotthi = db.CauHois.Where(x => x.ID == 1).FirstOrDefault().DotThi + 1;

            db.TraLois.RemoveRange(db.TraLois.ToList());
            db.CauHois.RemoveRange(db.CauHois.ToList());
            db.SaveChanges();
            FileInfo filecauhoi = new FileInfo("D:/DATN/Project_BDS/PBDS/PBDS/Cauhoi_Excel/test.xlsx");
            var      listcauhoi = new List <CauHoi>();
            var      listtraloi = new List <TraLoi>();

            if ((filecauhoi != null) && !string.IsNullOrEmpty(filecauhoi.FullName))
            {
                using (var package = new ExcelPackage(filecauhoi))
                {
                    ExcelPackage.LicenseContext = LicenseContext.Commercial;
                    var currentSheet = package.Workbook.Worksheets;
                    var workSheet    = currentSheet.First();
                    var noOfCol      = workSheet.Dimension.End.Column;
                    var noOfRow      = workSheet.Dimension.End.Row;

                    for (int rowquestion = 2; rowquestion < noOfRow; rowquestion += 2)
                    {
                        var cauhoi  = new CauHoi();
                        var traloia = new TraLoi();
                        var traloib = new TraLoi();
                        var traloic = new TraLoi();
                        var traloid = new TraLoi();

                        cauhoi.ID      = listcauhoi.Count() + 1;
                        cauhoi.NoiDung = workSheet.Cells[rowquestion, 2].Value.ToString();
                        listcauhoi.Add(cauhoi);

                        traloia.ID       = listtraloi.Count() + 1;
                        traloia.IDCauHoi = int.Parse(workSheet.Cells[rowquestion, 1].Value.ToString());
                        traloia.DungSai  = int.Parse(workSheet.Cells[rowquestion + 1, 3].Value.ToString());
                        traloia.DapAn    = workSheet.Cells[rowquestion, 3].Value.ToString();
                        listtraloi.Add(traloia);

                        traloib.ID       = listtraloi.Count() + 1;
                        traloib.IDCauHoi = int.Parse(workSheet.Cells[rowquestion, 1].Value.ToString());
                        traloib.DungSai  = int.Parse(workSheet.Cells[rowquestion + 1, 4].Value.ToString());
                        traloib.DapAn    = workSheet.Cells[rowquestion, 4].Value.ToString();
                        listtraloi.Add(traloib);

                        traloic.ID       = listtraloi.Count() + 1;
                        traloic.IDCauHoi = int.Parse(workSheet.Cells[rowquestion, 1].Value.ToString());
                        traloic.DungSai  = int.Parse(workSheet.Cells[rowquestion + 1, 5].Value.ToString());
                        traloic.DapAn    = workSheet.Cells[rowquestion, 5].Value.ToString();
                        listtraloi.Add(traloic);

                        traloid.ID       = listtraloi.Count() + 1;
                        traloid.IDCauHoi = int.Parse(workSheet.Cells[rowquestion, 1].Value.ToString());
                        traloid.DungSai  = int.Parse(workSheet.Cells[rowquestion + 1, 6].Value.ToString());
                        traloid.DapAn    = workSheet.Cells[rowquestion, 6].Value.ToString();
                        listtraloi.Add(traloid);
                    }
                }
            }
            int idtraloi = 1, idcauhoi = 1;

            foreach (var cauhoi in listcauhoi.OrderBy(a => Guid.NewGuid()))
            {
                CauHoi ch = new CauHoi
                {
                    ID      = idcauhoi++,
                    NoiDung = cauhoi.NoiDung,
                    DotThi  = dotthi,
                };
                db.Entry(ch).State = EntityState.Added;
                foreach (var traloi in listtraloi)
                {
                    if (cauhoi.ID == traloi.IDCauHoi)
                    {
                        TraLoi tl = new TraLoi()
                        {
                            ID       = idtraloi++,
                            IDCauHoi = ch.ID,
                            DapAn    = traloi.DapAn,
                            DungSai  = traloi.DungSai,
                        };
                        db.Entry(tl).State = EntityState.Added;
                    }
                }
                if (idcauhoi > 20)
                {
                    break;
                }
            }

            var listnhanvien = db.NhanViens.ToList();
            var listsales    = db.Sales.ToList();

            foreach (var nv in listnhanvien)
            {
                nv.ChoKiemTra      = 1;
                db.Entry(nv).State = EntityState.Modified;
                db.SaveChanges();
            }
            foreach (var sa in listsales)
            {
                sa.ChoKiemTra      = 1;
                db.Entry(sa).State = EntityState.Modified;
                db.SaveChanges();
            }
            return(Redirect("Uploads"));
        }