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 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)); }