public ActionResult Edit([Bind(Include = "Id,TopicNo,TopicName,StartDate,EndDate,ChapterID,Status")] AspNetTopic aspNetTopic)
 {
     if (ModelState.IsValid)
     {
         db.Entry(aspNetTopic).State = EntityState.Modified;
         db.SaveChanges();
         var  status    = db.AspNetTopics.Where(x => x.ChapterID == aspNetTopic.ChapterID).Select(x => x.Status).ToList();
         bool completed = true;
         foreach (var item in status)
         {
             if (item == false)
             {
                 completed = false;
                 break;
             }
         }
         AspNetChapter aspNetChapter = db.AspNetChapters.Where(x => x.Id == aspNetTopic.ChapterID).FirstOrDefault();
         if (completed)
         {
             aspNetChapter.Status = true;
             db.SaveChanges();
         }
         else
         {
             aspNetChapter.Status = false;
             db.SaveChanges();
         }
         return(RedirectToAction("Dashboard", "Account"));
     }
     ViewBag.ChapterID = new SelectList(db.AspNetChapters, "Id", "ChapterName", aspNetTopic.ChapterID);
     return(View(aspNetTopic));
 }
        public ActionResult DeleteConfirmed(int id)
        {
            AspNetChapter aspNetChapter = db.AspNetChapters.Find(id);

            db.AspNetChapters.Remove(aspNetChapter);
            db.SaveChanges();
            return(RedirectToAction("Dashboard", "Account"));
        }
Beispiel #3
0
        public JsonResult ChapterByLessonPlan(int id)
        {
            db.Configuration.ProxyCreationEnabled = false;
            var LessonTopicObj = db.AspNetLessonPlan_Topic.FirstOrDefault(s => s.LessonPlanID == id);
            var topicObj       = db.AspNetTopics.FirstOrDefault(s => s.Id == LessonTopicObj.TopicID);

            AspNetChapter chapterobj = db.AspNetChapters.FirstOrDefault(x => x.Id == topicObj.ChapterID);
            int?          chapter    = chapterobj.Id;

            return(Json(chapter, JsonRequestBehavior.AllowGet));
        }
 public ActionResult Edit([Bind(Include = "Id,ChapterNo,ChapterName,StartDate,EndDate,SubjectID,Status")] AspNetChapter aspNetChapter)
 {
     if (ModelState.IsValid)
     {
         db.Entry(aspNetChapter).State = EntityState.Modified;
         db.SaveChanges();
         return(RedirectToAction("Dashboard", "Account"));
     }
     ViewBag.SubjectID = new SelectList(db.AspNetSubjects, "Id", "SubjectName", aspNetChapter.SubjectID);
     return(View(aspNetChapter));
 }
        // GET: AspNetChapter/Details/5
        public ActionResult Details(int?id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            AspNetChapter aspNetChapter = db.AspNetChapters.Find(id);

            if (aspNetChapter == null)
            {
                return(HttpNotFound());
            }
            return(View(aspNetChapter));
        }
        // GET: AspNetChapter/Edit/5
        public ActionResult Edit(int?id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            AspNetChapter aspNetChapter = db.AspNetChapters.Find(id);

            if (aspNetChapter == null)
            {
                return(HttpNotFound());
            }
            ViewBag.SubjectID = new SelectList(db.AspNetSubjects, "Id", "SubjectName", aspNetChapter.SubjectID);
            return(View(aspNetChapter));
        }
        public ActionResult Create([Bind(Include = "Id,ChapterNo,ChapterName,StartDate,EndDate,SubjectID,Status")] AspNetChapter aspNetChapter)
        {
            if (ModelState.IsValid)
            {
                db.AspNetChapters.Add(aspNetChapter);
                db.SaveChanges();
                ViewBag.ClassID       = new SelectList(db.AspNetSubjects.Where(x => x.TeacherID == TeacherID).Select(x => x.AspNetClass).Distinct(), "Id", "ClassName");
                ViewBag.CreateChapter = "Chapter created and updated successfully";
                return(View("../Teacher_Dashboard/_Topics"));
            }

            ViewBag.SubjectID = new SelectList(db.AspNetSubjects.Where(x => x.AspNetClass.SessionID == SessionID), "Id", "SubjectName", aspNetChapter.SubjectID);

            return(View(aspNetChapter));
        }
        public ActionResult CurriculumFromFile()
        {
            HttpPostedFileBase file = Request.Files["curriculum"];
            int SubjectID           = Convert.ToInt32(Request.Form["SubjectID"]);

            if ((file != null) && (file.ContentLength > 0) && !string.IsNullOrEmpty(file.FileName))
            {
                string fileName        = file.FileName;
                string fileContentType = file.ContentType;
                byte[] fileBytes       = new byte[file.ContentLength];
                var    data            = file.InputStream.Read(fileBytes, 0, Convert.ToInt32(file.ContentLength));
            }
            using (var package = new ExcelPackage(file.InputStream))
            {
                var currentSheet = package.Workbook.Worksheets;
                var workSheet    = currentSheet.First();
                var noOfCol      = workSheet.Dimension.End.Column;
                var noOfRow      = workSheet.Dimension.End.Row;

                for (int rowIterator = 1; rowIterator <= noOfRow; rowIterator++)
                {
                    var heading = workSheet.Cells[rowIterator, 1].Value.ToString();
                    if (heading == "Chapter")
                    {
                        rowIterator++;
                        AspNetChapter aspNetChapter = new AspNetChapter();
                        aspNetChapter.SubjectID   = SubjectID;
                        aspNetChapter.ChapterNo   = Convert.ToInt32(workSheet.Cells[rowIterator, 1].Value.ToString());
                        aspNetChapter.ChapterName = workSheet.Cells[rowIterator, 2].Value.ToString();
                        aspNetChapter.StartDate   = Convert.ToDateTime(workSheet.Cells[rowIterator, 3].Value.ToString());
                        aspNetChapter.EndDate     = Convert.ToDateTime(workSheet.Cells[rowIterator, 4].Value.ToString());
                        aspNetChapter.Status      = Convert.ToBoolean(Convert.ToInt32(workSheet.Cells[rowIterator, 5].Value.ToString()));
                        db.AspNetChapters.Add(aspNetChapter);
                        db.SaveChanges();
                    }
                    else if (heading == "Topic")
                    {
                        int ChapterID = db.AspNetChapters.Max(item => item.Id);
                        rowIterator++;
                        AspNetTopic aspNetTopic = new AspNetTopic();
                        aspNetTopic.ChapterID = ChapterID;
                        aspNetTopic.TopicNo   = Convert.ToDouble(workSheet.Cells[rowIterator, 1].Value.ToString());
                        aspNetTopic.TopicName = workSheet.Cells[rowIterator, 2].Value.ToString();
                        aspNetTopic.StartDate = Convert.ToDateTime(workSheet.Cells[rowIterator, 3].Value.ToString());
                        aspNetTopic.EndDate   = Convert.ToDateTime(workSheet.Cells[rowIterator, 4].Value.ToString());
                        aspNetTopic.Status    = Convert.ToBoolean(Convert.ToInt32(workSheet.Cells[rowIterator, 5].Value.ToString()));
                        db.AspNetTopics.Add(aspNetTopic);
                        db.SaveChanges();
                    }
                    else
                    {
                        int         ChapterID   = db.AspNetChapters.Max(item => item.Id);
                        AspNetTopic aspNetTopic = new AspNetTopic();
                        aspNetTopic.ChapterID = ChapterID;
                        aspNetTopic.TopicNo   = Convert.ToDouble(workSheet.Cells[rowIterator, 1].Value.ToString());
                        aspNetTopic.TopicName = workSheet.Cells[rowIterator, 2].Value.ToString();
                        aspNetTopic.StartDate = Convert.ToDateTime(workSheet.Cells[rowIterator, 3].Value.ToString());
                        aspNetTopic.EndDate   = Convert.ToDateTime(workSheet.Cells[rowIterator, 4].Value.ToString());
                        aspNetTopic.Status    = Convert.ToBoolean(Convert.ToInt32(workSheet.Cells[rowIterator, 5].Value.ToString()));
                        db.AspNetTopics.Add(aspNetTopic);
                        db.SaveChanges();
                    }
                }
            }
            return(RedirectToAction("Dashboard", "Teacher_Dashboard"));
        }