public ActionResult ShowArea() { //string userId1 = User.Identity.GetUserId(); //PersonalArea area1 = db.PersonalAreas.Where(a => a.AspNetUserId.CompareTo(userId1) == 0).First(); //db.PersonalAreas.Remove(area1); //db.SaveChanges(); //return RedirectToAction("Index"); if (User.Identity.IsAuthenticated) { ViewBag.teacher = false; if (User.IsInRole("teacher")) { PersonalArea areaTeacher = new PersonalArea() { AspNetUserId = User.Identity.GetUserId(), Person = User.Identity.Name }; ViewBag.teacher = true; return(View(areaTeacher)); } string userId = User.Identity.GetUserId(); PersonalArea area = db.PersonalAreas.Where(a => a.AspNetUserId.CompareTo(userId) == 0).First(); CoursesInAreaModel coursesModel = MakeCoursesModel(area); ViewBag.coursesModel = coursesModel; List <KeyValuePair <int, int> > redGreen = new List <KeyValuePair <int, int> >(); foreach (var course in area.Courses) { StudyViewModel studyModel = GetNextParagraph(area, course.Id); redGreen.Add(new KeyValuePair <int, int>(course.Id, studyModel.Paragraph.NumInCourse)); } ViewBag.RedGreen = redGreen; return(View(area)); } return(RedirectToAction("Index")); }
public ActionResult DeleteCourseFromPersonalArea(int courseId) { string userId = User.Identity.GetUserId(); PersonalArea area = db.PersonalAreas.Where(p => p.AspNetUserId.CompareTo(userId) == 0).First(); // area.Courses.Remove(db.Courses.Find(courseId)); // CourseStructure corStr = area.CourseStructures.Where(c => c.IdCourse == courseId).First(); area.CourseStructures.Remove(area.CourseStructures.Where(c => c.IdCourse == courseId).First()); db.CourseStructures.Remove(corStr); area.Courses.Remove(db.Courses.Find(courseId)); db.Entry(area).State = System.Data.Entity.EntityState.Modified; db.SaveChanges(); CoursesInAreaModel coursesModel = MakeCoursesModel(area); ViewBag.coursesModel = coursesModel; List <KeyValuePair <int, int> > redGreen = new List <KeyValuePair <int, int> >(); foreach (var course in area.Courses) { StudyViewModel studyModel = GetNextParagraph(area, course.Id); redGreen.Add(new KeyValuePair <int, int>(course.Id, studyModel.Paragraph.NumInCourse)); } ViewBag.RedGreen = redGreen; return(View(area)); }
public ActionResult AddCourseToArea(int courseId) { if (User.Identity.IsAuthenticated) { ViewBag.teacher = false; if (User.IsInRole("teacher")) { PersonalArea areaTeacher = new PersonalArea() { AspNetUserId = User.Identity.GetUserId(), Person = User.Identity.Name }; ViewBag.teacher = true; return(View(areaTeacher)); } string userId = User.Identity.GetUserId(); PersonalArea area = db.PersonalAreas.Where(a => a.AspNetUserId.CompareTo(userId) == 0).First(); bool alreadyStudy = false; foreach (var course in area.Courses) { if (course.Id == courseId) { alreadyStudy = true; } } if (alreadyStudy) { CoursesInAreaModel coursesModel1 = MakeCoursesModel(area); ViewBag.coursesModel = coursesModel1; List <KeyValuePair <int, int> > redGreen1 = new List <KeyValuePair <int, int> >(); foreach (var course in area.Courses) { StudyViewModel studyModel = GetNextParagraph(area, course.Id); redGreen1.Add(new KeyValuePair <int, int>(course.Id, studyModel.Paragraph.NumInCourse)); } ViewBag.RedGreen = redGreen1; return(View(area)); } CourseStructure courseStr = CreateCourseStructure(courseId); area.CourseStructures.Add(courseStr); area.Courses.Add(db.Courses.Find(courseId)); db.SaveChanges(); CoursesInAreaModel coursesModel = MakeCoursesModel(area); ViewBag.coursesModel = coursesModel; List <KeyValuePair <int, int> > redGreen = new List <KeyValuePair <int, int> >(); foreach (var course in area.Courses) { StudyViewModel studyModel = GetNextParagraph(area, course.Id); redGreen.Add(new KeyValuePair <int, int>(course.Id, studyModel.Paragraph.NumInCourse)); } ViewBag.RedGreen = redGreen; return(View(area)); } else { return(RedirectToAction("Login", "Account")); } }
public CoursesInAreaModel MakeCoursesModel(PersonalArea area) { CoursesInAreaModel coursesModel = new CoursesInAreaModel(); Dictionary <int, List <Triplet> > dictionary = new Dictionary <int, List <Triplet> >(); foreach (var course in area.Courses) { var paragraphs = db.Paragraphs.Where(p => p.CourseId == course.Id).ToList(); var sort = paragraphs.OrderBy(p => p.NumInCourse).ToList(); List <Triplet> pars = new List <Triplet>(); foreach (var paragraph in sort) { pars.Add(new Triplet() { Name = paragraph.Name, UrlImg = paragraph.ImgUrl, ParagraphId = paragraph.Id }); } dictionary.Add(course.Id, pars); } coursesModel.courses = dictionary; return(coursesModel); }