public ActionResult DeleteConfirmed(int id) { AspNetLessonPlanBreakdown aspNetLessonPlanBreakdown = db.AspNetLessonPlanBreakdowns.Find(id); db.AspNetLessonPlanBreakdowns.Remove(aspNetLessonPlanBreakdown); db.SaveChanges(); return(RedirectToAction("Index")); }
public ActionResult Create([Bind(Include = "Id,LessonPlanID,BreakDownHeadingID,Description,Minutes,Resources,Priority")] AspNetLessonPlanBreakdown aspNetLessonPlanBreakdown) { if (ModelState.IsValid) { db.AspNetLessonPlanBreakdowns.Add(aspNetLessonPlanBreakdown); db.SaveChanges(); return(RedirectToAction("Index")); } ViewBag.LessonPlanID = new SelectList(db.AspNetLessonPlans, "Id", "Id", aspNetLessonPlanBreakdown.LessonPlanID); ViewBag.BreakDownHeadingID = new SelectList(db.AspNetLessonPlanBreakdownHeadings, "Id", "BreakDownHeadingName", aspNetLessonPlanBreakdown.BreakDownHeadingID); return(View(aspNetLessonPlanBreakdown)); }
// GET: AspNetLessonPlanBreakdown/Details/5 public ActionResult Details(int?id) { if (id == null) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } AspNetLessonPlanBreakdown aspNetLessonPlanBreakdown = db.AspNetLessonPlanBreakdowns.Find(id); if (aspNetLessonPlanBreakdown == null) { return(HttpNotFound()); } return(View(aspNetLessonPlanBreakdown)); }
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 Edit(AspNetLessonPlanBreakdown aspNetLessonPlanBreakdown) { if (ModelState.IsValid) { aspNetLessonPlanBreakdown.Description = WebUtility.HtmlEncode(aspNetLessonPlanBreakdown.Description); db.Entry(aspNetLessonPlanBreakdown).State = EntityState.Modified; db.SaveChanges(); return(RedirectToAction("View_LessonPlan", "AspNetLessonPlan")); } ViewBag.LessonPlanID = new SelectList(db.AspNetLessonPlans, "Id", "Id", aspNetLessonPlanBreakdown.LessonPlanID); ViewBag.BreakDownHeadingID = new SelectList(db.AspNetLessonPlanBreakdownHeadings, "Id", "BreakDownHeadingName", aspNetLessonPlanBreakdown.BreakDownHeadingID); aspNetLessonPlanBreakdown.Description = WebUtility.HtmlDecode(aspNetLessonPlanBreakdown.Description); return(View(aspNetLessonPlanBreakdown)); }
// GET: AspNetLessonPlanBreakdown/Edit/5 public ActionResult Edit(int?id) { if (id == null) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } AspNetLessonPlanBreakdown aspNetLessonPlanBreakdown = db.AspNetLessonPlanBreakdowns.Find(id); if (aspNetLessonPlanBreakdown == null) { return(HttpNotFound()); } ViewBag.LessonPlanID = new SelectList(db.AspNetLessonPlans, "Id", "Id", aspNetLessonPlanBreakdown.LessonPlanID); ViewBag.BreakDownHeadingID = new SelectList(db.AspNetLessonPlanBreakdownHeadings, "Id", "BreakDownHeadingName", aspNetLessonPlanBreakdown.BreakDownHeadingID); aspNetLessonPlanBreakdown.Description = WebUtility.HtmlDecode(aspNetLessonPlanBreakdown.Description); return(View(aspNetLessonPlanBreakdown)); }
public ActionResult BreakdownEdit(BreakDownStructure LessonPlan) { AspNetLessonPlanBreakdown breakdownobj = db.AspNetLessonPlanBreakdowns.FirstOrDefault(x => x.Id == LessonPlan.Id); if (ModelState.IsValid) { breakdownobj.LessonPlanID = LessonPlan.LessonPlanID; breakdownobj.BreakDownHeadingID = LessonPlan.HeadingID; breakdownobj.Minutes = LessonPlan.Minutes; breakdownobj.Resources = LessonPlan.Resources; breakdownobj.Description = WebUtility.HtmlEncode(LessonPlan.Description).ToString(); db.SaveChanges(); return(RedirectToAction("View_LessonPlan", "AspNetLessonPlan")); } ViewBag.LessonPlanID = new SelectList(db.AspNetLessonPlans, "Id", "Id", LessonPlan.LessonPlanID); ViewBag.BreakDownHeadingID = new SelectList(db.AspNetLessonPlanBreakdownHeadings, "Id", "BreakDownHeadingName", LessonPlan.HeadingID); return(View(LessonPlan)); }
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)); }