public ActionResult Edit([Bind(Include = "ID,Contents,Description,TrackingTime,ID_Student,ID_Subject,FileUpload")] TrackingPaper trackingPaper)
 {
     if (ModelState.IsValid)
     {
         db.Entry(trackingPaper).State = EntityState.Modified;
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     ViewBag.ID_Student = new SelectList(db.Students, "ID", "FullName", trackingPaper.ID_Student);
     ViewBag.ID_Subject = new SelectList(db.Subjects, "ID", "ID_Subject", trackingPaper.ID_Subject);
     return(View(trackingPaper));
 }
        public ActionResult Edit(int?id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            TrackingPaper trackingPaper = db.TrackingPapers.Find(id);

            if (trackingPaper == null)
            {
                return(HttpNotFound());
            }
            ViewBag.ID_Student = new SelectList(db.Students, "ID", "FullName", trackingPaper.ID_Student);
            ViewBag.ID_Subject = new SelectList(db.Subjects, "ID", "ID_Subject", trackingPaper.ID_Subject);
            return(View(trackingPaper));
        }
        public ActionResult Create(TrackingPaper trackingPaper, HttpPostedFileBase file)
        {
            trackingPaper.ID_Student = db.Students.SingleOrDefault(student => student.ID_Account == CurrentUser.ID).ID;
            trackingPaper.ID_Subject = db.SubjectDetails.FirstOrDefault(subject => subject.ID_Student == trackingPaper.ID_Student).ID_Subject;
            var pro = db.TrackingPapers.SingleOrDefault(c => c.ID.Equals(trackingPaper.ID));

            if (file != null)
            {
                if (file.ContentLength > 0)
                {
                    try
                    {
                        string nameFile = Path.GetFileName(file.FileName);
                        file.SaveAs(Path.Combine(Server.MapPath("/FileUpload"), nameFile));
                        trackingPaper.FileUpload = nameFile;
                    }
                    catch (Exception)
                    {
                        ViewBag.CreateProError = "Không thể chọn file.";
                    }
                }
                trackingPaper.TrackingTime = GetCurrentDay();
                try
                {
                    if (pro != null)
                    {
                        ViewBag.CreateProError = "Mã đề tài ko tồn tại.";
                    }
                    else
                    {
                        db.TrackingPapers.Add(trackingPaper);
                        db.SaveChanges();
                        TempData["SuccessMessage"] = " Nộp báo cáo thành công";
                        return(RedirectToAction("Index"));
                    }
                }
                catch (Exception)
                {
                    return(View(trackingPaper));
                }
            }
            else
            {
                ViewBag.FileUpload = "Chọn file đính kèm";
            }
            return(View(trackingPaper));
        }