Example #1
0
        public IndexCourseViewModel GetIndexCourseViewModel(List <Course> courses, ApplicationDbContext context, ApplicationUser user)
        {
            var categoryQuery     = Enum.GetNames(typeof(CourseCategory));
            var sortCriteriaQuery = Enum.GetNames(typeof(CourseSortCriteria));
            var courseIndexVM     = new IndexCourseViewModel();

            //  var currentUser = context.Users.Include(x=>x.Certificats).Include(x=>x.Stream).FirstOrDefault(x => x.Id == user.Id);

            courseIndexVM.categories        = new SelectList(categoryQuery);
            courseIndexVM.sortCrtiteriaList = new SelectList(sortCriteriaQuery);
            courseIndexVM.Courses           = courses;
            //courseIndexVM.User = currentUser;

            return(courseIndexVM);
        }
        public ActionResult Index()
        {
            List <IndexCourse> course = new List <IndexCourse>();

            foreach (var s in context.Courses.ToList())
            {
                course.Add(new IndexCourse()
                {
                    Id          = s.Id,
                    Name        = s.Name,
                    StartDate   = s.StartDate,
                    Description = s.Description,
                });
            }
            IndexCourseViewModel ic = new IndexCourseViewModel();

            ic.Courses = course.Where(x => x.StartDate > DateTime.Now).ToList();

            return(View(ic));
        }