/*
  * Returns courses to user
  * CourseSearchViewModel:
  * 1.PagesInfo:
  * currentPage - current coursees page - first = 0,
  * ItemsPerPage - count of courses on one page
  * TotalItems - total avaible courses in DB
  * 2.Courses - all
  */
 public async Task<ActionResult> Index(Int32 currentPage = 0)
 {
     appContext.Courses
         .Include(c => c.CourseTags)
         .Include(c => c.Topics);
         CourseSearchViewModel csVm = new CourseSearchViewModel
         {
             Courses = await CourseSearchHelper.GetCoursesOnPageAsync(appContext, currentPage),
             PInfo = new PagesInfo
             {
                 CurrentPage = currentPage,
                 ItemsPerPage = CourseSearchHelper.ItemsOnPageCount,
                 TotalItems = await appContext.Courses.CountAsync()
             }
         };
         return View(csVm);
 }
 /*
  * search view to search course by three categories : all, tags, names
  */
 public async Task<ActionResult> Search(String query = "all", String search = "all", Boolean showAll = true, Int32 currentPage = 0) // default: search by all
 {
     ViewBag.Query = query;
     ViewBag.ShowAll = showAll;
     ViewBag.Search = search;
     IEnumerable<Course> courses = showAll ? await coursesSearch.SearchCoursesAsync(search, query, appContext)
         : await coursesSearch.SearchCoursesAsync(search, query, appContext, currentPage);
     if (courses != null)
     {
         CourseSearchViewModel csVm = new CourseSearchViewModel
         {
             Courses = courses,
             PInfo = showAll ? null : new PagesInfo
             {
                 CurrentPage = currentPage,
                 ItemsPerPage = CourseSearchHelper.ItemsOnPageCount,
                 TotalItems = coursesSearch.ItemsCount
             }
         };
         return View(csVm);
     }
     return RedirectToAction("Index");
 }