/////////////////////////////////////////////////////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////////////////////////////////////////////////// public ActionResult Edit(int?id) { if (id == null) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } AspNetLessonPlan aspNetLessonPlan = db.AspNetLessonPlans.Find(id); if (aspNetLessonPlan == null) { return(HttpNotFound()); } var lessonplan = db.AspNetSubjects.FirstOrDefault(s => s.Id == aspNetLessonPlan.SubjectID); ViewBag.ClassID = new SelectList(db.AspNetClasses, "Id", "ClassName", lessonplan.ClassID); ViewBag.SubjectID = new SelectList(db.AspNetSubjects, "Id", "SubjectName", aspNetLessonPlan.SubjectID); ViewBag.LessonPlanId = aspNetLessonPlan.Id; //ViewBag.HeadingID = new SelectList(db.AspNetLessonPlanBreakdownHeadings, "Id", "BreakDownHeadingName"); int?no = aspNetLessonPlan.LessonPlanNo; ViewBag.LessonPlanNo = no; ViewBag.LessonPlanIDEdit = id; ViewBag.Date = aspNetLessonPlan.Date; var LessonTopicObj = db.AspNetLessonPlan_Topic.FirstOrDefault(s => s.LessonPlanID == id); var topicObj = db.AspNetTopics.FirstOrDefault(s => s.Id == LessonTopicObj.TopicID); ViewBag.ChapterID = new SelectList(db.AspNetChapters.Where(x => x.SubjectID == aspNetLessonPlan.SubjectID), "Id", "ChapterName", topicObj.ChapterID); return(View(aspNetLessonPlan)); }
public ActionResult DeleteConfirmed(int id) { AspNetLessonPlan aspNetLessonPlan = db.AspNetLessonPlans.Find(id); db.AspNetLessonPlans.Remove(aspNetLessonPlan); db.SaveChanges(); return(RedirectToAction("Index")); }
public ActionResult Create([Bind(Include = "Id,Date,Duration,SubjectID")] AspNetLessonPlan aspNetLessonPlan) { if (ModelState.IsValid) { db.AspNetLessonPlans.Add(aspNetLessonPlan); db.SaveChanges(); return(RedirectToAction("Index")); } ViewBag.HeadingID = new SelectList(db.AspNetLessonPlanBreakdownHeadings, "Id", "BreakDownHeadingName"); ViewBag.ClassID = new SelectList(db.AspNetSubjects.Where(x => x.TeacherID == TeacherID && x.AspNetClass.SessionID == SessionID).Select(x => x.AspNetClass).Distinct(), "Id", "ClassName"); ViewBag.SubjectID = new SelectList(db.AspNetSubjects.Where(x => x.AspNetClass.SessionID == SessionID), "Id", "SubjectName", aspNetLessonPlan.SubjectID); return(View(aspNetLessonPlan)); }
public ActionResult Edit([Bind(Include = "Id,Date,Duration,SubjectID")] AspNetLessonPlan aspNetLessonPlan) { if (ModelState.IsValid) { db.Entry(aspNetLessonPlan).State = EntityState.Modified; db.SaveChanges(); return(RedirectToAction("Index")); } ViewBag.ClassID = new SelectList(db.AspNetClasses, "Id", "ClassName"); ViewBag.SubjectID = new SelectList(db.AspNetSubjects, "Id", "SubjectName", aspNetLessonPlan.SubjectID); return(View(aspNetLessonPlan)); }
// GET: AspNetLessonPlan/Details/5 public ActionResult Details(int?id) { if (id == null) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } AspNetLessonPlan aspNetLessonPlan = db.AspNetLessonPlans.Find(id); if (aspNetLessonPlan == null) { return(HttpNotFound()); } return(View(aspNetLessonPlan)); }
public void EditLessonPlanobj(lessonPlan LessonPlan) { var lessonPlanToEdit = db.AspNetLessonPlans.FirstOrDefault(s => s.Date == LessonPlan.Date && s.SubjectID == LessonPlan.subjectID); AspNetLessonPlan aspNetLessonPlan = db.AspNetLessonPlans.FirstOrDefault(x => x.Id == lessonPlanToEdit.Id); aspNetLessonPlan.LessonPlanNo = LessonPlan.lessonPlanNo; aspNetLessonPlan.SubjectID = LessonPlan.subjectID; aspNetLessonPlan.Date = LessonPlan.Date; aspNetLessonPlan.Duration = LessonPlan.Duration; //db.AspNetLessonPlans.Add(aspNetLessonPlan); db.SaveChanges(); int LessonPlanID = db.AspNetLessonPlans.Max(x => x.Id); foreach (var topic in LessonPlan.Topics) { AspNetLessonPlan_Topic lessonPlanTopicExist = db.AspNetLessonPlan_Topic.FirstOrDefault(x => x.TopicID == topic && x.LessonPlanID == LessonPlanID); if (lessonPlanTopicExist == null) { AspNetLessonPlan_Topic lessonPlanTopic = new AspNetLessonPlan_Topic(); lessonPlanTopic.TopicID = topic; lessonPlanTopic.LessonPlanID = LessonPlanID; db.AspNetLessonPlan_Topic.Add(lessonPlanTopic); db.SaveChanges(); } } foreach (var breakdown in LessonPlan.BreakDown) { AspNetLessonPlanBreakdown BreakdownCheck = db.AspNetLessonPlanBreakdowns.FirstOrDefault(x => x.BreakDownHeadingID == breakdown.HeadingID && x.LessonPlanID == LessonPlanID); if (BreakdownCheck == null) { AspNetLessonPlanBreakdown aspNetLessonBreakdown = new AspNetLessonPlanBreakdown(); aspNetLessonBreakdown.LessonPlanID = LessonPlanID; aspNetLessonBreakdown.Minutes = breakdown.Minutes; aspNetLessonBreakdown.Resources = breakdown.Resources; aspNetLessonBreakdown.BreakDownHeadingID = breakdown.HeadingID; aspNetLessonBreakdown.Description = WebUtility.HtmlEncode(breakdown.Description).ToString(); db.AspNetLessonPlanBreakdowns.Add(aspNetLessonBreakdown); db.SaveChanges(); } else { BreakdownCheck.Minutes = breakdown.Minutes; BreakdownCheck.BreakDownHeadingID = breakdown.HeadingID; BreakdownCheck.Description = breakdown.Description; db.SaveChanges(); } } }
public ActionResult EditLessonPlan(int?id) { if (id == null) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } AspNetLessonPlan aspNetLessonPlan = db.AspNetLessonPlans.Find(id); if (aspNetLessonPlan == null) { return(HttpNotFound()); } ViewBag.HeadingID = new SelectList(db.AspNetLessonPlanBreakdownHeadings, "Id", "BreakDownHeadingName"); ViewBag.ClassID = new SelectList(db.AspNetClasses, "Id", "ClassName"); ViewBag.SubjectID = new SelectList(db.AspNetSubjects.Where(x => x.AspNetClass.Id == aspNetLessonPlan.AspNetSubject.AspNetClass.Id), "Id", "SubjectName", aspNetLessonPlan.SubjectID); ViewBag.LessonPlanNo = new SelectList(db.AspNetLessonPlans.Where(x => x.Id == id), "Id", "LessonPlanNo"); ViewBag.LessonPlanIDEdit = id; return(View(aspNetLessonPlan)); }
public void LessonPlanfromFile(AspNetLessonPlan aspNetLessonPlan) { HttpPostedFileBase file = Request.Files["LessonPlan"]; 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; List <int> TopicsID = new List <int>(); int LessonPlanID = -1; for (int rowIterator = 1; rowIterator <= noOfRow; rowIterator++) { string Heading = workSheet.Cells[rowIterator, 1].Value.ToString(); if (Heading == "Lesson No") { aspNetLessonPlan.LessonPlanNo = Convert.ToInt32(workSheet.Cells[rowIterator, 2].Value); } else if (Heading == "Chapter") { } else if (Heading == "Topic") { while (true) { rowIterator++; string check = workSheet.Cells[rowIterator, 1].Value.ToString(); if (check != "Duration") { string topicName = workSheet.Cells[rowIterator, 1].Value.ToString(); int topicID = db.AspNetTopics.Where(x => x.TopicName == topicName).Select(x => x.Id).FirstOrDefault(); TopicsID.Add(topicID); } else { rowIterator--; break; } } } else if (Heading == "Duration") { aspNetLessonPlan.Duration = Convert.ToInt32(workSheet.Cells[rowIterator, 2].Value); db.AspNetLessonPlans.Add(aspNetLessonPlan); db.SaveChanges(); LessonPlanID = db.AspNetLessonPlans.Max(x => x.Id); foreach (var topic in TopicsID) { AspNetLessonPlan_Topic lessonPlanTopic = new AspNetLessonPlan_Topic(); lessonPlanTopic.TopicID = topic; lessonPlanTopic.LessonPlanID = LessonPlanID; db.AspNetLessonPlan_Topic.Add(lessonPlanTopic); db.SaveChanges(); } } else if (Heading == "Breakdown") { AspNetLessonPlanBreakdown aspNetLessonBreakdown = new AspNetLessonPlanBreakdown(); while (true) { rowIterator++; string check = workSheet.Cells[rowIterator, 1].Value.ToString(); if (check != "End") { if (check == "Heading") { aspNetLessonBreakdown.LessonPlanID = LessonPlanID; string headingName = workSheet.Cells[rowIterator, 2].Value.ToString(); aspNetLessonBreakdown.BreakDownHeadingID = db.AspNetLessonPlanBreakdownHeadings.Where(x => x.BreakDownHeadingName == headingName).Select(x => x.Id).FirstOrDefault(); } else if (check == "Description") { aspNetLessonBreakdown.Description = workSheet.Cells[rowIterator, 2].Value.ToString(); } else if (check == "Time") { aspNetLessonBreakdown.Minutes = Convert.ToInt32(workSheet.Cells[rowIterator, 2].Value.ToString()); } else if (check == "Resources") { aspNetLessonBreakdown.Resources = workSheet.Cells[rowIterator, 2].Value.ToString(); db.AspNetLessonPlanBreakdowns.Add(aspNetLessonBreakdown); db.SaveChanges(); } } else { break; } } } else if (Heading == "End") { break; } } } }
// //////////////////////////////////////////////////////////////////////////////////////////////////////////////////// // //////////////////////////////////////////////////////////////////////////////////////////////////////////////////// // //////////////////////////////////////////////////////////////////////////////////////////////////////////////////// public JsonResult AddLessonPlan(lessonPlan LessonPlan) { var TransactionObj = db.Database.BeginTransaction(); try { AspNetLessonPlan aspNetLessonPlan = new AspNetLessonPlan(); aspNetLessonPlan.LessonPlanNo = LessonPlan.lessonPlanNo; aspNetLessonPlan.SubjectID = LessonPlan.subjectID; aspNetLessonPlan.Date = LessonPlan.Date; aspNetLessonPlan.Duration = LessonPlan.Duration; db.AspNetLessonPlans.Add(aspNetLessonPlan); db.SaveChanges(); int LessonPlanID = db.AspNetLessonPlans.Max(x => x.Id); foreach (var topic in LessonPlan.Topics) { AspNetLessonPlan_Topic lessonPlanTopic = new AspNetLessonPlan_Topic(); lessonPlanTopic.TopicID = topic; lessonPlanTopic.LessonPlanID = LessonPlanID; db.AspNetLessonPlan_Topic.Add(lessonPlanTopic); db.SaveChanges(); } if (LessonPlan.BreakDown != null) { foreach (var breakdown in LessonPlan.BreakDown) { AspNetLessonPlanBreakdown aspNetLessonBreakdown = new AspNetLessonPlanBreakdown(); aspNetLessonBreakdown.LessonPlanID = LessonPlanID; aspNetLessonBreakdown.Minutes = breakdown.Minutes; aspNetLessonBreakdown.Resources = breakdown.Resources; aspNetLessonBreakdown.BreakDownHeadingID = breakdown.HeadingID; aspNetLessonBreakdown.Description = WebUtility.HtmlEncode(breakdown.Description).ToString(); db.AspNetLessonPlanBreakdowns.Add(aspNetLessonBreakdown); db.SaveChanges(); } } ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// var UserNameLog = User.Identity.Name; AspNetUser a = db.AspNetUsers.First(x => x.UserName == UserNameLog); string UserIDLog = a.Id; var logMessage = "New LessonPlan Added, SubjectID: " + LessonPlan.subjectID + ", Date: " + LessonPlan.Date; var LogControllerObj = new AspNetLogsController(); LogControllerObj.CreateLogSave(logMessage, UserIDLog); ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// db.SaveChanges(); TransactionObj.Commit(); } catch (Exception) { TransactionObj.Dispose(); } return(Json("data", JsonRequestBehavior.AllowGet)); }
public void EditLessonPlan1234(EditLessonPlanType LessonPlan) { var TransactionObj = db.Database.BeginTransaction(); try { var lessonID = LessonPlan.LessonPlanID; AspNetLessonPlan aspNetLessonPlan = db.AspNetLessonPlans.FirstOrDefault(x => x.Id == lessonID); //aspNetLessonPlan.LessonPlanNo = LessonPlan.lessonPlanNo; aspNetLessonPlan.SubjectID = LessonPlan.subjectID; aspNetLessonPlan.Date = LessonPlan.Date; aspNetLessonPlan.Duration = LessonPlan.Duration; //db.AspNetLessonPlans.Add(aspNetLessonPlan); db.SaveChanges(); int LessonPlanID = aspNetLessonPlan.Id; var Lesson_TopicList = (from lesson_topic in db.AspNetLessonPlan_Topic where lesson_topic.LessonPlanID == LessonPlanID select lesson_topic).ToList(); int count = 1; do { var lessonObj = db.AspNetLessonPlan_Topic.FirstOrDefault(x => x.LessonPlanID == LessonPlanID); if (lessonObj == null) { count = 0; continue; } db.AspNetLessonPlan_Topic.Attach(lessonObj); db.AspNetLessonPlan_Topic.Remove(lessonObj); db.SaveChanges(); }while (count == 1); foreach (var topic in LessonPlan.Topics) { AspNetLessonPlan_Topic lessonPlanTopic = new AspNetLessonPlan_Topic(); lessonPlanTopic.TopicID = topic; lessonPlanTopic.LessonPlanID = LessonPlanID; db.AspNetLessonPlan_Topic.Add(lessonPlanTopic); db.SaveChanges(); } ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// var UserNameLog = User.Identity.Name; AspNetUser a = db.AspNetUsers.First(x => x.UserName == UserNameLog); string UserIDLog = a.Id; var logMessage = "LessonPlan Edited, LessonPlanID: " + lessonID + ", Date: " + LessonPlan.Date; var LogControllerObj = new AspNetLogsController(); LogControllerObj.CreateLogSave(logMessage, UserIDLog); ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// db.SaveChanges(); TransactionObj.Commit(); } catch (Exception) { TransactionObj.Dispose(); } }