public LessonListPage() { InitializeComponent(); BindingContext = viewModel = new LessonListViewModel(); viewModel.Lessons.CollectionChanged += this.Lessons_CollectionChanged; }
public ViewViewComponentResult Invoke() { var model = new LessonListViewModel { Lessons = _lessonService.GetList() }; return(View(model)); }
// GET:Lesson List public async Task <IActionResult> List() { var result = await _schoolDataDbContext.Lessons.ToListAsync(); var LessonList = new LessonListViewModel() { Lessons = result }; if (LessonList == null) { ModelState.AddModelError("ListHata", "Model hatası"); return(RedirectToAction("Index")); } return(View(LessonList)); }
//Post : Search public async Task <IActionResult> Search(string Key) { if (string.IsNullOrEmpty(Key)) { ModelState.AddModelError(string.Empty, "Id is not unreachable"); return(View("List")); } var requireLessons = new LessonListViewModel() { //Bu kısımda bir açılır kutu görünümü sağlayıp kişilerin aramayı //farklı tercihlere göre gerçekleştirebilmesini sağlayabiliriz. Lessons = await(from m in _schoolDataDbContext.Lessons where m.Name == Key select m ).ToListAsync() }; return(View("List", requireLessons)); }
public async Task <IActionResult> List(string Key) { if (string.IsNullOrEmpty(Key)) { ModelState.AddModelError(string.Empty, "Doğru bir arama değeri girmediniz!!"); return(View()); } // Bu kısımda input değeri değiştikçe arama değerinin değişmesini sağlayan bir method tanımla var model = new LessonListViewModel() { Lessons = await _schoolDataDbContext.Lessons.Where(a => a.Name.Contains(Key)).ToListAsync <Lesson>() }; if (model == null) { ModelState.AddModelError(string.Empty, "Can't Find Any People"); return(View()); } return(View(model)); }
public ActionResult TeacherPage(int?teacher) { if (!isAuthenticate()) { return(Redirect("/Admin/LoginPage/?error")); } if (!IsAdmin()) { if (!IsTeacher()) { return(Redirect("/Admin/LoginPage/?noPermission")); } } IQueryable <Lesson> lessons = db.Lessons.Include(s => s.Teacher).Include(s => s.Group).Include(s => s.Course); if (teacher != null && teacher != 0) { if (IsAdmin()) { lessons = lessons.Where(s => s.TeacherId == teacher); } else { return(Redirect("/Admin/LoginPage/?noPermission")); } } else { IQueryable <Teacher> teachers0 = db.Teachers; Teacher teacher1 = null; string email = (string)Session["currentUser"]; foreach (Teacher t in teachers0) { if (t.Login == email) { teacher1 = t; break; } } if (teacher1 != null) { lessons = lessons.Where(s => s.TeacherId == teacher1.Id); } } List <Teacher> teachers = db.Teachers.ToList(); // устанавливаем начальный элемент, который позволит выбрать всех teachers.Insert(0, new Teacher { Name = "Все", Id = 0 }); LessonListViewModel plvm = new LessonListViewModel { Lessons = lessons.Include(s => s.Teacher).Include(s => s.Group).Include(s => s.Course).ToList(), Teachers = new SelectList(teachers, "Id", "Name") }; return(View(plvm)); }
/*========================================================================================================================== | METHOD: INVOKE (ASYNC) \-------------------------------------------------------------------------------------------------------------------------*/ /// <summary> /// Provides the pagel-level navigation menu for the current page, which exposes one tier of navigation from the nearest /// page group. /// </summary> public async Task<IViewComponentResult> InvokeAsync() { /*------------------------------------------------------------------------------------------------------------------------ | Retrieve root topic \-----------------------------------------------------------------------------------------------------------------------*/ var navigationRootTopic = GetNavigationRoot(); /*------------------------------------------------------------------------------------------------------------------------ | Construct view model \-----------------------------------------------------------------------------------------------------------------------*/ var navigationViewModel = new LessonListViewModel() { NavigationRoot = await MapNavigationTopicViewModels(navigationRootTopic).ConfigureAwait(true), CurrentWebPath = CurrentTopic?.GetWebPath()?? HttpContext.Request.Path }; /*------------------------------------------------------------------------------------------------------------------------ | Write lesson cookie \-----------------------------------------------------------------------------------------------------------------------*/ if (!IsVisited(CurrentTopic.Key)) { HttpContext.Response.Cookies.Append( $"Visited{CurrentTopic.Key}", "1", new Microsoft.AspNetCore.Http.CookieOptions() { Path = CurrentTopic.Parent.GetWebPath(), Expires = DateTime.Now.AddYears(20) } ); } /*------------------------------------------------------------------------------------------------------------------------ | Set visit status \-----------------------------------------------------------------------------------------------------------------------*/ foreach (var trackedNavigationViewModel in navigationViewModel.NavigationRoot.Children) { var isCurrent = CurrentTopic.Key.Equals(trackedNavigationViewModel.Key, StringComparison.OrdinalIgnoreCase); var isVisited = IsVisited(trackedNavigationViewModel.Key); trackedNavigationViewModel.IsVisited = isCurrent? true : isVisited? (bool?)true : null; } /*------------------------------------------------------------------------------------------------------------------------ | Write unit cookie \-----------------------------------------------------------------------------------------------------------------------*/ var isUnitNowComplete = navigationViewModel.NavigationRoot.Children.All(t => t.IsVisited is true); var wasUnitComplete = IsUnitComplete(); if (isUnitNowComplete != wasUnitComplete) { HttpContext.Response.Cookies.Append( $"Status{CurrentTopic.Parent.Key}", isUnitNowComplete.ToString(), new Microsoft.AspNetCore.Http.CookieOptions() { Path = CurrentTopic.Parent.Parent.GetWebPath(), Expires = DateTime.Now.AddYears(20) } ); navigationViewModel.TrackingEvents.Add( new TrackingEventViewModel( "Courses", isUnitNowComplete? "EndUnit" : "StartUnit", $"{CurrentTopic.Parent.Parent.Key}:{CurrentTopic.Parent.Key}" ) ); } /*------------------------------------------------------------------------------------------------------------------------ | Return the corresponding view \-----------------------------------------------------------------------------------------------------------------------*/ return View(navigationViewModel); }