Esempio n. 1
0
        public List <UserCourses> GetPassedCourses(FilterCourses filter)
        {
            var courses = db.UserCourses.Where(i => i.HasPassed.HasValue && i.HasPassed == true &&
                                               i.CompletedDate.HasValue &&
                                               i.CompletedDate >= filter.StartDate && i.CompletedDate <= filter.EndDate).ToList();

            if (filter.CourseID != 0)
            {
                courses = courses.Where(i => i.MasterCourseId == filter.CourseID).ToList();
            }
            if (filter.AssignedToCompanyIds.Count > 0)
            {
                courses = courses.Where(i => filter.AssignedToCompanyIds.Contains(i.UserProfiles.CompanyId)).ToList();
            }
            if (filter.AssignedToDepartmentIds.Count > 0)
            {
                courses = courses.Where(i => filter.AssignedToDepartmentIds.Contains(i.UserProfiles.DepartmentId)).ToList();
            }
            if (filter.AssignedToUserIds.Count > 0)
            {
                courses = courses.Where(i => filter.AssignedToUserIds.Contains(i.UserId.Value)).ToList();
            }

            return(courses);
        }
Esempio n. 2
0
        /// <summary>
        /// Get the list of mastercourses, assigned to company, department or user. If filter is null - returns all entries
        /// </summary>
        /// <param name="filter"></param>
        /// <returns></returns>
        public List <MasterCourses> MasterCourses(FilterCourses filter = null, bool showDeactivated = true)
        {
            var list = db.MasterCourses.ToList();

            if (filter == null)
            {
                return(list);
            }
            //filter rezulting list step by step.
            if (filter.AssignedToCompanyIds.Count > 0)
            {
                list = list.Where(i => i.CompanyCourses.Where(c => filter.AssignedToCompanyIds.Contains(c.CompanyId) && (showDeactivated == true || c.CourseStatus == true)).Any()).ToList();
            }
            if (filter.AssignedToDepartmentIds.Count > 0)
            {
                list = list.Where(i => i.DepartmentCourses.Where(c => filter.AssignedToDepartmentIds.Contains(c.DepartmentId) && (showDeactivated == true || c.CourseStatus == true)).Any()).ToList();
            }
            if (filter.AssignedToUserIds.Count > 0)
            {
                list = list.Where(i => i.UserCourses.Where(c => c.UserId.HasValue == true && filter.AssignedToUserIds.Contains(c.UserId.Value) && (showDeactivated == true || c.CourseStatus == true)).Any()).ToList();
            }
            if (filter.CourseID != null)
            {
                list = list.Where(i => i.Id == filter.CourseID).ToList();
            }
            return(list);
        }
Esempio n. 3
0
        public List <MasterCourses> GetAvaliableCourses(FilterCourses filter)
        {
            var rez = db.MasterCourses.ToList();

            if (filter == null)
            {
                return(rez);
            }
            else if (filter.AssignedToCompanyIds.Count > 0)
            {
                var assigned = db.CompanyCourses.Where(i => filter.AssignedToCompanyIds.Contains(i.CompanyId)).Select(s => s.MasterCourses);
                return(rez.Except(assigned).ToList());
            }
            else if (filter.AssignedToDepartmentIds.Count > 0)
            {
                var assigned = db.DepartmentCourses.Where(i => filter.AssignedToDepartmentIds.Contains(i.DepartmentId)).Select(s => s.MasterCourses);
                return(rez.Except(assigned).ToList());
            }
            else if (filter.AssignedToUserIds.Count > 0)
            {
                var assigned = db.UserCourses.Where(i => filter.AssignedToUserIds.Contains(i.UserId.Value)).Select(s => s.MasterCourses);
                return(rez.Except(assigned).ToList());
            }
            return(rez);
        }
Esempio n. 4
0
        public static List <CoursesStatDto> GetCoursesForTableStat(int Id, FilterIdType type)
        {
            var           list   = new List <CoursesStatDto>();
            FilterCourses filter = null;

            switch (type)
            {
            case FilterIdType.CompanyId:
                filter = new FilterCourses {
                    AssignedToCompanyIds = new List <int> {
                        Id
                    }
                };
                break;

            case FilterIdType.DepartmentId:
                filter = new FilterCourses {
                    AssignedToDepartmentIds = new List <int> {
                        Id
                    }
                };
                break;

            case FilterIdType.UserId:
                filter = new FilterCourses {
                    AssignedToUserIds = new List <int> {
                        Id
                    }
                };
                break;

            case FilterIdType.All:
                filter = null;
                break;
            }
            list = courseRepo.GetAssignedCoursesForStatistic(filter);

            var userCourses = courseRepo.UserCourses(filter);
            var userIds     = userCourses.Select(u => u.UserId.Value).ToList();

            foreach (var entry in list)
            {
                //users
                entry.Users = userCourses.Where(i => i.MasterCourseId == entry.MasterCourseId).Count();
                //avg score
                var maxScores = userCourses.Where(i => i.MasterCourseId == entry.MasterCourseId && i.CompletedDate.HasValue).Select(c => c.MaxUserScore);
                entry.Avg = maxScores.Any() ? maxScores.Average() : 0;
                //status of completion
                var watchedcourse = userCourses.Where(i => i.MasterCourseId == entry.MasterCourseId).FirstOrDefault();
                var watched       = watchedcourse != null?watchedcourse.MasterCourses.UserModulesWatched.Where(i => userIds.Contains(i.UserProfiles.Id)).Count() : 0;

                entry.Status = entry.Users == 0 || entry.Modules == 0 ? 0 : watched * 100 / (entry.Users * entry.Modules);
            }
            return(list);
        }
Esempio n. 5
0
 public List <UserCourses> UserCourses(FilterCourses filter)
 {
     //if we don't need to filter, filter is null, so return all entries
     if (filter == null)
     {
         return(db.UserCourses.Where(i => i.UserId.HasValue).ToList());
     }
     else if (filter.AssignedToCompanyIds.Count > 0)
     {
         return(db.UserCourses.Where(i => filter.AssignedToCompanyIds.Contains(i.UserProfiles.CompanyId)).ToList());
     }
     else if (filter.AssignedToDepartmentIds.Count > 0)
     {
         return(db.UserCourses.Where(i => filter.AssignedToDepartmentIds.Contains(i.UserProfiles.DepartmentId)).ToList());
     }
     else if (filter.AssignedToUserIds.Count > 0)
     {
         return(db.UserCourses.Where(i => filter.AssignedToUserIds.Contains(i.UserId.Value)).ToList());
     }
     else
     {
         throw new KeyNotFoundException("No such filter configuration found :(");
     }
 }
Esempio n. 6
0
 public static List <UserCourses> GetPassedExams(FilterCourses filter)
 {
     return(courseRepo.GetPassedCourses(filter));
 }
Esempio n. 7
0
 public List <CoursesStatDto> GetAssignedCoursesForStatistic(FilterCourses filter)
 {
     if (filter == null)
     {
         var courses = db.MasterCourses.ToList();
         return(courses.Select(i => new CoursesStatDto
         {
             CourseName = i.Name,
             Cover = i.CoverUrl,
             Deadline = !i.EndTime.HasValue ? "" : i.EndTime.Value.ToString(),
             MasterCourseId = i.Id,
             Modules = i.MasterCourseModules.Where(c => c.MasterCourseId == i.Id).Count(),
             Start = !i.StartTime.HasValue ? "" : i.StartTime.Value.ToString()
         }).ToList());
     }
     else if (filter.AssignedToCompanyIds.Count > 0)
     {
         var courses = db.CompanyCourses.Where(c => filter.AssignedToCompanyIds.Contains(c.CompanyId)).ToList();
         return(courses.Select(i => new CoursesStatDto
         {
             CourseName = i.MasterCourses.Name,
             Cover = i.MasterCourses.CoverUrl,
             Deadline = !i.EndDate.HasValue ? "" : i.EndDate.Value.ToString(),
             MasterCourseId = i.CourseId,
             Modules = i.MasterCourses.MasterCourseModules.Where(c => c.MasterCourseId == i.Id).Count(),
             Start = !i.StartDate.HasValue ? "" : i.StartDate.Value.ToString()
         })
                .ToList());
     }
     else if (filter.AssignedToDepartmentIds.Count > 0)
     {
         var courses = db.DepartmentCourses.Where(c => filter.AssignedToDepartmentIds.Contains(c.DepartmentId)).ToList();
         return(courses.Select(i => new CoursesStatDto
         {
             CourseName = i.MasterCourses.Name,
             Cover = i.MasterCourses.CoverUrl,
             Deadline = !i.EndDate.HasValue ? "" : i.EndDate.Value.ToString(),
             MasterCourseId = i.CourseId,
             Modules = i.MasterCourses.MasterCourseModules.Where(c => c.MasterCourseId == i.Id).Count(),
             Start = !i.StartDate.HasValue ? "" : i.StartDate.Value.ToString()
         })
                .ToList());
     }
     else if (filter.AssignedToUserIds.Count > 0)
     {
         var courses = db.UserCourses.Where(c => c.UserId.HasValue && filter.AssignedToUserIds.Contains(c.UserId.Value)).ToList();
         return(courses.Select(i => new CoursesStatDto
         {
             CourseName = i.MasterCourses.Name,
             Cover = i.MasterCourses.CoverUrl,
             Deadline = !i.EndDate.HasValue ? "" : i.EndDate.Value.ToString(),
             MasterCourseId = i.MasterCourseId,
             Modules = i.MasterCourses.MasterCourseModules.Where(c => c.MasterCourseId == i.Id).Count(),
             Start = !i.StartDate.HasValue ? "" : i.StartDate.Value.ToString()
         })
                .ToList());
     }
     else
     {
         return(new List <CoursesStatDto>());
     }
 }