public ActionResult DeleteConfirmed(int id) { courseCategory courseCategory = db.courseCategories.Find(id); db.courseCategories.Remove(courseCategory); db.SaveChanges(); return(RedirectToAction("Index")); }
public ActionResult Edit([Bind(Include = "courseCategoryId,courseCategory1")] courseCategory courseCategory) { if (ModelState.IsValid) { db.Entry(courseCategory).State = EntityState.Modified; db.SaveChanges(); return(RedirectToAction("Index")); } return(View(courseCategory)); }
public ActionResult Create([Bind(Include = "courseCategoryId,courseCategory1")] courseCategory courseCategory) { if (ModelState.IsValid) { db.courseCategories.Add(courseCategory); db.SaveChanges(); return(RedirectToAction("Index")); } return(View(courseCategory)); }
private static void GetCourseCategory() { Debug.WriteLine("Starting WebScrape"); var htmldocument = DocumentURLReturn(baseURL); var courseCategoryHtml = htmldocument.DocumentNode.Descendants("div") .Where(node => node.GetAttributeValue("class", "") .Equals("toc")).ToList(); var courseCategoryList = courseCategoryHtml[0].Descendants("a").ToList(); using (MyDbContext context = new MyDbContext()) { //Remove All subjectMapping var mall = from c in context.majors select c; context.majors.RemoveRange(mall); var dall = from c in context.majorSubjects select c; context.majorSubjects.RemoveRange(dall); context.SaveChanges(); //Remove All courses var all = from c in context.CourseLists select c; context.CourseLists.RemoveRange(all); context.SaveChanges(); //Remove All Course Categories var ball = from c in context.courseCategories select c; context.courseCategories.RemoveRange(ball); context.SaveChanges(); foreach (var courseCategory in courseCategoryList) { //Course Category string categoryName = courseCategory.InnerText; //link to undergraduate course information string categoryUndergradURL = baseURL + courseCategory.GetAttributeValue("href", "").Replace("index.html", "ug/index.html"); //Write to debug fullCouseCategoryList.Add(new string[2] { categoryName, categoryUndergradURL }); //Debug.WriteLine(categoryName); //Debug.WriteLine(categoryUndergradURL); //write to database courseCategory category = new courseCategory { courseCategory1 = categoryName }; context.courseCategories.Add(category); } context.SaveChanges(); } }
// GET: Category/Delete/5 public ActionResult Delete(int?id) { if (id == null) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } courseCategory courseCategory = db.courseCategories.Find(id); if (courseCategory == null) { return(HttpNotFound()); } return(View(courseCategory)); }
private static void WebScrapeCourses(string categoryname, string categoryURL) { //Debug.WriteLine("Function 2 " + categoryname + " " + categoryURL); var htmldocument = DocumentURLReturn(categoryURL); var courseListHTML = htmldocument.DocumentNode.SelectNodes("/ html / body / div[4] / div[1] / div[2] / div / div / div / div[1]"); var courseList = courseListHTML[0].Descendants("tr").ToList(); //if (categoryname == "UTS: Communication") { // Debug.WriteLine(""); //} using (MyDbContext context = new MyDbContext()) { foreach (var course in courseList) { //Course Number string courseNumbers = course.FirstChild.InnerText; //Course Name string coursesName = course.LastChild.InnerText; //Course URL string courseURL = course.FirstChild.FirstChild.GetAttributeValue("href", ""); //Write to debug Debug.WriteLine("Category: " + categoryname + " Course Number: " + courseNumbers + " Course Name: " + coursesName + " Course URL: " + courseURL); fullCourseList.Add(new string[4] { categoryname, courseNumbers, coursesName, courseURL }); //write to database courseCategory category = context.courseCategories.FirstOrDefault(c => c.courseCategory1 == categoryname); //context.CourseLists.Add(new CourseList { courseName = coursesName, courseCategory = category, courseNumber = courseNumbers }); category.CourseLists.Add(new CourseList { courseName = coursesName, courseNumber = courseNumbers }); Debug.WriteLine(""); } context.SaveChanges(); } }