public List <Skill> GetSkillsByUserId(int userId) { var skills = new List <Skill>(); try { using (var context = new TrainingTrackerEntities()) { skills = context.Feedbacks.Where(x => x.AddedFor == userId).Join(context.Skills, f => f.SkillId, s => s.SkillId, (f, s) => new { f, s }) //.Where(x => x.f.AddedFor == userId) .GroupBy(a => a.f.SkillId).Select(g => new { g.Key, Item = g.FirstOrDefault(), AverageRating = g.Average(x => x.f.Rating) }) .Select(x => new Skill { Name = x.Item.s.Name, SkillId = x.Item.f.SkillId ?? 0, Rating = (int)x.AverageRating } ).ToList(); } } catch (Exception ex) { LogUtility.ErrorRoutine(ex); } return(skills); }
public bool AddAssignment(Assignment dataToAdd, out int id) { try { using (var context = new TrainingTrackerEntities()) { EntityFramework.Assignment newEntity = new EntityFramework.Assignment { Name = dataToAdd.Name, Description = dataToAdd.Description, AddedBy = dataToAdd.AddedBy, IsActive = dataToAdd.IsActive, CreatedOn = dataToAdd.CreatedOn, AssignmentAsset = dataToAdd.AssignmentAsset }; context.Assignments.Add(newEntity); context.SaveChanges(); id = newEntity.Id; AddAssignmentSubtopicMapping(id, dataToAdd.CourseSubtopicId); return(true); } } catch (Exception ex) { LogUtility.ErrorRoutine(ex); id = 0; return(false); } }
/// <summary> /// Delete Learning Map data by making its IsDeleted attribute to true. /// </summary> /// <param name="id">Learning Map Id whose data is to be deleted</param> /// <returns>true if Learning Map data is deleted successfully and false if data to be deleted is not found or some other exception occurs.</returns> public bool DeleteLearningMap(int id) { try { using (var context = new TrainingTrackerEntities()) { var learningMapEntity = context.LearningMaps.First(x => x.Id == id); if (learningMapEntity == null) { return(false); } learningMapEntity.IsDeleted = true; context.SaveChanges(); return(true); } } catch (Exception ex) { LogUtility.ErrorRoutine(ex); return(false); } }
/// <summary> /// Fetch feedback's threads /// </summary> /// <param name="feedbackId">feedback Id</param> /// <returns>List Of Threads</returns> public List <Threads> GetFeedbackThreads(int feedbackId) { try { using (TrainingTrackerEntities context = new TrainingTrackerEntities()) { return(context.FeedbackThreads .Where(x => x.FeedbackId == feedbackId) .Select(x => new Threads { ThreadId = x.ThreadId, Comments = x.Comments, AddedBy = new User { UserId = x.User.UserId, FullName = x.User.FirstName + " " + x.User.LastName, ProfilePictureName = x.User.ProfilePictureName }, DateInserted = x.DateTimeInserted }) .ToList()); } } catch (Exception ex) { LogUtility.ErrorRoutine(ex); return(null); } }
public bool UpdateSubtopicContent(SubtopicContent dataToUpdate) { try { using (var context = new TrainingTrackerEntities()) { var entityToUpdate = context.SubtopicContents.Find(dataToUpdate.Id); if (entityToUpdate == null) { return(false); } entityToUpdate.Name = dataToUpdate.Name; entityToUpdate.Description = dataToUpdate.Description; entityToUpdate.Url = dataToUpdate.Url; entityToUpdate.CourseSubtopicId = dataToUpdate.CourseSubtopicId; context.SaveChanges(); return(true); } } catch (Exception ex) { LogUtility.ErrorRoutine(ex); return(false); } }
public List <Question> GetQuestionsBySkillAndExperience(int skillId, int startExperience, int endExperience) { try { using (var context = new TrainingTrackerEntities()) { return(context.Questions.Join(context.QuestionLevelMappings, x => x.Id, m => m.QuestionId, (x, m) => new { q = x, mp = m }). Where(a => a.q.SkillId == skillId && a.mp.ExperienceStartRange >= startExperience && a.mp.ExperienceEndRange <= endExperience). Select(x => new Question { Id = x.q.Id, QuestionText = x.q.QuestionText, Description = x.q.Description, SkillId = x.q.SkillId, Level = x.mp.Level }).ToList()); } } catch (Exception ex) { LogUtility.ErrorRoutine(ex); return(null); } }
/// <summary> /// Get all the Trainees List belong to a specified team. /// </summary> /// <param name="teamId">teamId which is used to fetch the Trainees data of that team only.</param> /// <returns>List of User object if successfully fetches some data and returns null if no data is present or some exception occurs. </returns> public List <User> GetAllTrainees(int teamId) { try { using (var context = new TrainingTrackerEntities()) { return(context.Users.Where(l => l.IsActive == true && l.TeamId == teamId && l.IsTrainee == true) .Select(x => new User { UserId = x.UserId, FirstName = x.FirstName, LastName = x.LastName, FullName = x.FirstName + " " + x.LastName, UserName = x.UserName, Email = x.Email, Designation = x.Designation, ProfilePictureName = x.ProfilePictureName, IsFemale = x.IsFemale ?? false, IsAdministrator = x.IsAdministrator ?? false, IsTrainer = x.IsTrainer ?? false, IsTrainee = x.IsTrainee ?? false, IsManager = x.IsManager ?? false, IsActive = x.IsActive ?? false, DateAddedToSystem = x.DateAddedToSystem, TeamId = x.TeamId }) .ToList()); } } catch (Exception ex) { LogUtility.ErrorRoutine(ex); return(null); } }
/// <summary> /// Signature for method to update the Current User's and course Mapping /// </summary> /// <param name="currentUser">Session instance of current user</param> /// <param name="courseId">course id to be mapped</param> /// <returns>Status if mapping added or not.</returns> /// <exception >on exception return false</exception> public bool StartCourseForTrainee(Common.Entity.User currentUser, int courseId) { try { using (TrainingTrackerEntities context = new TrainingTrackerEntities()) { if (!context.CourseUserMappings.Any(x => x.CourseId == courseId && x.UserId == currentUser.UserId)) { context.CourseUserMappings.Add(new CourseUserMapping { CourseId = courseId, UserId = currentUser.UserId, StartedOn = DateTime.Now }); return(context.SaveChanges() == 1); } return(true); } } catch (Exception ex) { LogUtility.ErrorRoutine(ex); return(false); } }
public bool UpdateCourse(Course courseToUpdate) { try { using (var context = new TrainingTrackerEntities()) { var courseEntity = context.Courses.FirstOrDefault(x => x.Id == courseToUpdate.Id); if (courseEntity == null) { return(false); } courseEntity.Name = courseToUpdate.Name; courseEntity.Description = courseToUpdate.Description; courseEntity.Icon = courseToUpdate.Icon; courseEntity.Duration = courseToUpdate.Duration; context.SaveChanges(); return(true); } } catch (Exception ex) { LogUtility.ErrorRoutine(ex); return(false); } }
public bool SaveSubtopicContentProgress(int subtopicContentId, int userId) { try { using (var context = new TrainingTrackerEntities()) { var newEntity = new EntityFramework.SubtopicContentUserMap { SubtopicContentId = subtopicContentId, UserId = userId, Seen = true, CreatedOn = DateTime.Now }; context.SubtopicContentUserMaps.Add(newEntity); context.SaveChanges(); return(true); } } catch (Exception ex) { LogUtility.ErrorRoutine(ex); return(false); } }
/// <summary> /// fetches Trainor synopsis /// </summary> /// <param name="trainerId">trainer Id</param> /// <returns>instances of Trainor synopsis</returns> public TrainerFeedbackSynopsis GetTrainorFeedbackSynopsis(int trainerId) { try { using (TrainingTrackerEntities context = new TrainingTrackerEntities()) { IEnumerable <EntityFramework.Feedback> feedbacks = context.Feedbacks.Where(x => x.AddedBy == trainerId); return(new TrainerFeedbackSynopsis { AssignmentFeedbackCount = feedbacks.Count(x => x.FeedbackType == (int)Common.Enumeration.FeedbackType.Assignment), CodeReviewFeedbackCount = feedbacks.Count(x => x.FeedbackType == (int)Common.Enumeration.FeedbackType.CodeReview), WeeklyFeedbackCount = feedbacks.Count(x => x.FeedbackType == (int)Common.Enumeration.FeedbackType.Weekly), SessionFeedbackCount = context.Sessions.Count(x => x.Presenter == trainerId), SlowFeedbackCount = feedbacks.Count(x => x.Rating == (int)Common.Enumeration.FeedbackRating.Slow), AverageFeedbackCount = feedbacks.Count(x => x.Rating == (int)Common.Enumeration.FeedbackRating.Average), FastFeedbackCount = feedbacks.Count(x => x.Rating == (int)Common.Enumeration.FeedbackRating.Fast), ExceptionalFeedbackCount = feedbacks.Count(x => x.Rating == (int)Common.Enumeration.FeedbackRating.Exceptional), }); } } catch (Exception ex) { LogUtility.ErrorRoutine(ex); return(null); } }
public PagedResult <Course> GetCourses(int pageNumber, int pageSize) { using (var context = new TrainingTrackerEntities()) { return(context.Courses.OrderBy(x => x.Name).Page(pageNumber, pageSize)); } }
public bool AddSubtopicContent(SubtopicContent dataToAdd, out int id) { try { using (var context = new TrainingTrackerEntities()) { EntityFramework.SubtopicContent entityToAdd = new EntityFramework.SubtopicContent { Name = dataToAdd.Name, Description = dataToAdd.Description, CourseSubtopicId = dataToAdd.CourseSubtopicId, Url = dataToAdd.Url, SortOrder = context.SubtopicContents.Where(s => s.CourseSubtopicId == dataToAdd.CourseSubtopicId).Count() + 1, AddedBy = dataToAdd.AddedBy, CreatedOn = dataToAdd.CreatedOn, IsActive = dataToAdd.IsActive }; context.SubtopicContents.Add(entityToAdd); context.SaveChanges(); id = entityToAdd.Id; return(true); } } catch (Exception ex) { LogUtility.ErrorRoutine(ex); id = 0; return(false); } }
public bool AddQuestionMapping(List <QuestionLevelMapping> mappings, int questionId) { try { using (var context = new TrainingTrackerEntities()) { foreach (var questionLevelMapping in mappings) { context.QuestionLevelMappings.Add(new EntityFramework.QuestionLevelMapping { QuestionId = questionId, Level = questionLevelMapping.Level, ExperienceStartRange = questionLevelMapping.ExperienceStartRange, ExperienceEndRange = questionLevelMapping.ExperienceEndRange }); } context.SaveChanges(); return(true); } } catch (Exception ex) { LogUtility.ErrorRoutine(ex); return(false); } }
public bool UpdateCourseSubtopic(CourseSubtopic subtopicToUpdate) { try { using (var context = new TrainingTrackerEntities()) { var subtopicEntityToUpdate = context.CourseSubtopics.Find(subtopicToUpdate.Id); if (subtopicEntityToUpdate == null) { return(false); } subtopicEntityToUpdate.Name = subtopicToUpdate.Name; subtopicEntityToUpdate.Description = subtopicToUpdate.Description; subtopicEntityToUpdate.CourseId = subtopicToUpdate.CourseId; context.SaveChanges(); return(true); } } catch (Exception ex) { LogUtility.ErrorRoutine(ex); return(false); } }
public List <SubtopicContent> GetSubtopicContents(int subtopicId) { try { using (var context = new TrainingTrackerEntities()) { return(context.SubtopicContents .Where(s => s.CourseSubtopicId == subtopicId && s.IsActive) .Select(s => new SubtopicContent { Id = s.Id, CourseSubtopicId = s.CourseSubtopicId, Name = s.Name, Description = s.Description, Url = s.Url, CreatedOn = s.CreatedOn, IsActive = s.IsActive, AddedBy = s.AddedBy, SortOrder = s.SortOrder }).OrderBy(x => x.SortOrder) .ToList()); } } catch (Exception ex) { LogUtility.ErrorRoutine(ex); return(null); } }
public int AddCourseSubtopic(CourseSubtopic subtopicToAdd) { try { using (var context = new TrainingTrackerEntities()) { EntityFramework.CourseSubtopic newSubtopicEntity = new EntityFramework.CourseSubtopic { Name = subtopicToAdd.Name, CourseId = subtopicToAdd.CourseId, Description = subtopicToAdd.Description, SortOrder = context.CourseSubtopics.Where(c => c.CourseId == subtopicToAdd.CourseId).Count() + 1, AddedBy = subtopicToAdd.AddedBy, IsActive = subtopicToAdd.IsActive, CreatedOn = subtopicToAdd.CreatedOn }; context.CourseSubtopics.Add(newSubtopicEntity); context.SaveChanges(); return(newSubtopicEntity.Id); } } catch (Exception ex) { LogUtility.ErrorRoutine(ex); return(0); } }
//ToDo: This function can be refactored and reused public List <Course> GetAllCourses(int traineeId = 0) { try { using (var context = new TrainingTrackerEntities()) { var userDal = new UserDal(); var course = context.Courses.Where(c => c.IsActive && (traineeId == 0 || c.CourseUserMappings.Any(x => x.CourseId == c.Id && x.UserId == traineeId))) .AsEnumerable() .Select(c => { var courseModel = ModelMapper.MapFromCourseModel(c); courseModel.AuthorName = userDal.GetUserById(c.AddedBy).FirstName; courseModel.AuthorMailId = userDal.GetUserById(c.AddedBy).Email; return(courseModel); } ).ToList(); return(course); } } catch (Exception ex) { LogUtility.ErrorRoutine(ex); return(null); } }
public Course GetCourseWithSubtopics(int courseId) { try { using (var context = new TrainingTrackerEntities()) { var courseWithSubtopics = context.Courses .Where(c => c.IsActive && c.Id == courseId) .AsEnumerable() .Select(c => { var course = ModelMapper.MapFromCourseModel(c); course.CourseSubtopics = c.CourseSubtopics .Where(s => s.IsActive) .Select(s => ModelMapper.MapFromCourseSubtopic(s)) .OrderBy(x => x.SortOrder) .ToList(); return(course); }) .FirstOrDefault(); return(courseWithSubtopics); } } catch (Exception ex) { LogUtility.ErrorRoutine(ex); return(null); } }
public bool AddQuestion(Question question) { try { var newQuestion = new EntityFramework.Question { QuestionText = question.QuestionText, Description = question.Description, SkillId = question.SkillId, AddedBy = question.AddedBy, AddedDate = question.AddedDate }; using (var context = new TrainingTrackerEntities()) { context.Questions.Add(newQuestion); context.SaveChanges(); } return(AddQuestionMapping(question.LevelMapping, newQuestion.Id)); } catch (Exception ex) { LogUtility.ErrorRoutine(ex); return(false); } }
public List <Question> GetQuestionsByUserId(int userId) { try { using (var context = new TrainingTrackerEntities()) { return(context.Questions. Where(x => x.AddedBy == userId). Select(x => new Question { Id = x.Id, QuestionText = x.QuestionText, Description = x.Description, SkillId = x.SkillId, AddedBy = x.AddedBy, AddedDate = x.AddedDate }).ToList()); } } catch (Exception ex) { LogUtility.ErrorRoutine(ex); return(null); } }
/// <summary> /// Data access method for filtering courses on search keyword /// </summary> /// <param name="traineeId">Filter Trainee assigned Course</param> /// <param name="searchKeyword">search keyword for free text search</param> /// <returns>List of courses matching search keyword</returns> public List <Course> FilterCourses(string searchKeyword, int traineeId = 0) { try { // To search on multiple words string[] splittedKeywords = !string.IsNullOrEmpty(searchKeyword) ? searchKeyword.Split(new char[] { ' ', ',', '+' }, StringSplitOptions.RemoveEmptyEntries) : new string[] {}; int length = splittedKeywords.Length; using (TrainingTrackerEntities context = new TrainingTrackerEntities()) { return(context.Courses .Where(x => (length == 0 || splittedKeywords.Any(y => x.Name.Contains(y) || x.Description.Contains(y))) && x.IsActive && (traineeId == 0 || x.CourseUserMappings.Any(y => y.UserId == traineeId && x.Id == y.CourseId))) .Select(x => new Course { Id = x.Id, Name = x.Name, Description = x.Description, Icon = x.Icon }).ToList()); } } catch (Exception ex) { LogUtility.ErrorRoutine(ex); return(new List <Course>()); } }
public void AddUserSkillMapping(int skillId, int userId, int addedByUser) { try { using (var context = new TrainingTrackerEntities()) { var skillMapping = context.UserSkillMappings.SingleOrDefault(x => x.SkillId == skillId && x.UserId == userId); if (skillMapping == null) { return; } context.UserSkillMappings.Add(new UserSkillMapping { SkillId = skillId, AddedBy = addedByUser, UserId = userId, AddedOn = DateTime.Now }); context.SaveChanges(); } } catch (Exception ex) { LogUtility.ErrorRoutine(ex); } }
/// <summary> /// Function GetNotification Return list of notification. /// </summary> /// <param name="userId">UserId</param> /// <returns>Return list of notification for a user</returns> public List <Common.Entity.Notification> GetNotification(int userId) { try { using (TrainingTrackerEntities context = new TrainingTrackerEntities()) { return(context.UserNotificationMappings .Where(x => x.UserId == userId && !x.Seen) .Select(x => new Common.Entity.Notification { NotificationId = x.NotificationId, Title = x.Notification.NotificationTitle, Description = x.Notification.Description, Link = x.Notification.Link, TypeOfNotification = (Common.Enumeration.NotificationType)x.Notification.NotificationType, AddedBy = x.Notification.AddedBy, AddedOn = x.Notification.AddedOn, UserDetails = new Common.Entity.User { FirstName = x.Notification.User.FirstName, LastName = x.Notification.User.LastName, ProfilePictureName = x.Notification.User.ProfilePictureName } }).ToList()); } } catch (Exception ex) { LogUtility.ErrorRoutine(ex); return(null); } }
/// <summary> /// Fetch feedback with threads /// </summary> /// <param name="feedbackId">feedback Id</param> /// <returns>Instance of Feedback</returns> public Feedback GetFeedbackWithThreads(int feedbackId) { try { using (TrainingTrackerEntities context = new TrainingTrackerEntities()) { var feedback = context.Feedbacks .Where(x => x.FeedbackId == feedbackId) .Select(x => new Feedback { FeedbackId = x.FeedbackId, FeedbackText = x.FeedbackText, Title = x.Title, FeedbackType = new FeedbackType { FeedbackTypeId = x.FeedbackType1.FeedbackTypeId, Description = x.FeedbackType1.Description, }, Rating = x.Rating ?? 0, AddedOn = x.AddedOn ?? new DateTime(), AddedBy = new User { UserId = x.User.UserId, FullName = x.User.FirstName + " " + x.User.LastName, ProfilePictureName = x.User.ProfilePictureName, TeamId = x.User.TeamId }, StartDate = x.StartDate ?? new DateTime(), EndDate = x.EndDate ?? new DateTime(), }).FirstOrDefault(); if (feedback == null) { return(null); } feedback.Threads = context.FeedbackThreads.Where(x => x.FeedbackId == feedbackId) .Select(x => new Threads { ThreadId = x.ThreadId, Comments = x.Comments, AddedBy = new User { UserId = x.User.UserId, FullName = x.User.FirstName + " " + x.User.LastName, ProfilePictureName = x.User.ProfilePictureName }, DateInserted = x.DateTimeInserted }).ToList(); return(feedback); } } catch (Exception ex) { LogUtility.ErrorRoutine(ex); return(null); } }
/// <summary> /// Data Access method to get Survey Questions /// </summary> /// <param name="teamId">team id</param> /// <returns>Survey instance</returns> public Common.Entity.Survey GetWeeklySurveySetForTeam(int teamId) { try { using (TrainingTrackerEntities context = new TrainingTrackerEntities()) { Common.Entity.Survey survey = context.Teams.Where(x => x.TeamId == teamId) .Include(x => x.Survey) .Include(x => x.Survey.SurveySections) .Include(x => x.Survey.SurveySections .Select(y => y.SurveyQuestions .Select(z => z.SurveyAnswers))) .AsEnumerable() .Select(x => new Common.Entity.Survey { SurveyId = x.Survey.SurveyId, Description = x.Survey.Description, SurveySubSections = x.Survey.SurveySections .Where(yS => yS.IsDeleted == false) .Select(y => new SurveySection { Id = y.SurveySectionId, Header = y.SectionHeader, SortOrder = y.SortOrder, Questions = y.SurveyQuestions .Where(yQ => yQ.IsDeleted == false) .Select(q => new Common.Entity.SurveyQuestion { SurveyQuestionId = q.SurveyQuestionId, HelpText = q.HelpText, AdditionalNoteRequired = q.AdditionalNoteRequired, IsMandatory = q.IsMandatory, QuestionText = q.QuestionText, ResponseTypeId = q.ResponseTypeId, SortOrder = q.SortOrder, Answers = q.SurveyAnswers .Where(yA => yA.IsDeleted == false) .Select(a => new Common.Entity.SurveyAnswer { Id = a.SurveyAnswerId, OptionText = a.OptionText, SortOrder = a.SortOrder }).OrderBy(so => so.SortOrder) .ToList() }).OrderBy(so => so.SortOrder) .ToList() }).OrderBy(so => so.SortOrder) .ToList(), }).FirstOrDefault(); return(survey); } } catch (Exception ex) { LogUtility.ErrorRoutine(ex); return(null); } }
public List <Assignment> GetAssignments(int subtopicId, int traineeId = 0) { try { using (var context = new TrainingTrackerEntities()) { var assignments = context.AssignmentSubtopicMaps .Where(s => s.SubtopicId == subtopicId) .Select(a => new { assignmentData = a.Assignment, traineeData = a.Assignment.AssignmentUserMaps.Where(s => s.TraineeId == traineeId && s.AssignmentId == a.Assignment.Id) }) .Where(a => a.assignmentData.IsActive) .Select(a => new Assignment { Name = a.assignmentData.Name, Description = a.assignmentData.Description, Id = a.assignmentData.Id, AddedBy = a.assignmentData.AddedBy, CreatedOn = a.assignmentData.CreatedOn, IsActive = a.assignmentData.IsActive, CourseSubtopicId = subtopicId, AssignmentAsset = a.assignmentData.AssignmentAsset, TraineeId = (int)traineeId, IsCompleted = a.traineeData.Select(b => b.IsCompleted).FirstOrDefault(), IsApproved = a.traineeData.Select(b => b.IsApproved).FirstOrDefault(), ApprovedBy = (int)a.traineeData.Select(b => b.ApprovedBy).FirstOrDefault(), Feedback = a.assignmentData.AssignmentFeedbackMappings .Where(x => x.AssignmentId == a.assignmentData.Id) .Select(x => x.Feedback).Where(x => x.AddedFor == traineeId) .Select(f => new Common.Entity.Feedback { FeedbackId = f.FeedbackId, Title = f.Title, FeedbackType = new Common.Entity.FeedbackType { FeedbackTypeId = f.FeedbackType1.FeedbackTypeId, Description = f.FeedbackType1.Description, }, Rating = f.Rating == null ? 0 : (int)f.Rating, AddedOn = (DateTime)f.AddedOn, AddedBy = new Common.Entity.User { UserId = f.User.UserId, FullName = f.User.FirstName + " " + f.User.LastName, ProfilePictureName = f.User.ProfilePictureName, } }).OrderByDescending(f => f.AddedOn).ToList() }) .ToList(); assignments.ForEach(x => x.Feedback.OrderByDescending(y => y.AddedOn)); return(assignments); } } catch (Exception ex) { LogUtility.ErrorRoutine(ex); return(null); } }
/// <summary> /// DataAccess method to fetch the list of Curces assigned to the User /// ** should be modified to fetch the cource details like percentage completed,status etc.. /// </summary> /// <param name="traineeId">user id of the trainee</param> /// <exception>All exceptions are handled to return empty List</exception> /// <returns>The implementing method should return the List of Courses for the trainee,or empty list.</returns> public List <CourseTrackerDetails> GetAllCoursesForTrainee(int traineeId) { try { using (TrainingTrackerEntities context = new TrainingTrackerEntities()) { return(context.Courses .Join(context.LearningMapCourseMappings, c => c.Id, lmcm => lmcm.CourseId, (c, lmcm) => new { c, lmcm }) .Join(context.LearningMaps, p => p.lmcm.LearningMapId, lm => lm.Id, (p, lm) => new { p, lm }) .Join(context.LearningMapUserMappings, q => q.lm.Id, lmum => lmum.LearningMapId, (q, lmum) => new { q, lmum }) .Join(context.Users, r => r.lmum.UserId, u => u.UserId, (r, u) => new { r, u }) .GroupJoin(context.CourseSubtopics, s => s.r.q.p.c.Id, cs => cs.CourseId, (s, cs) => new { s, cs = cs.FirstOrDefault() }) .GroupJoin(context.SubtopicContents, t => t.cs.Id, sc => sc.CourseSubtopicId, (t, sc) => new { t, sc = sc.FirstOrDefault() }) .GroupJoin(context.SubtopicContentUserMaps, u => u.sc.Id, scum => scum.SubtopicContentId, (u, scum) => new { u, scum = scum.FirstOrDefault() }) .Where(x => x.u.t.s.r.lmum.UserId == traineeId) .Select(x => new CourseTrackerDetails { Id = x.u.t.s.r.q.p.c.Id, Name = x.u.t.s.r.q.p.c.Name, TotalSubTopicCount = context.SubtopicContents.Count(y => y.CourseSubtopic.CourseId == x.u.t.s.r.q.p.c.Id && y.IsActive), CoveredSubTopicCount = context.SubtopicContentUserMaps.Count(y => y.Seen && y.SubtopicContent.CourseSubtopic.Course.Id == x.u.t.s.r.q.p.c.Id && y.UserId == traineeId && y.SubtopicContent.IsActive), TotalAssignmentCount = context.Assignments .GroupJoin(context.AssignmentSubtopicMaps, a => a.Id, asm => asm.AssignmentId, (a, asm) => new { a, asm = asm.FirstOrDefault() }) .Count(y => y.asm.CourseSubtopic.CourseId == x.u.t.s.r.q.p.c.Id && y.a.IsActive), CompletedAssignmentCount = context.AssignmentUserMaps .Join(context.Assignments, aum => aum.AssignmentId, a => a.Id, (aum, a) => new { a, aum }) .Where(y => y.aum.TraineeId == traineeId && y.a.IsActive) .GroupJoin(context.AssignmentSubtopicMaps, p => p.a.Id, asm => asm.AssignmentId, (p, asm) => new { p, asm = asm.FirstOrDefault() }) .Count(y => y.p.aum.IsApproved && y.p.aum.TraineeId == traineeId && y.asm.CourseSubtopic.CourseId == x.u.t.s.r.q.p.c.Id), PendingAssignmentCount = context.AssignmentUserMaps .Join(context.Assignments, aum => aum.AssignmentId, a => a.Id, (aum, a) => new { a, aum }) .Where(y => y.aum.TraineeId == traineeId && y.a.IsActive) .GroupJoin(context.AssignmentSubtopicMaps, p => p.a.Id, asm => asm.AssignmentId, (p, asm) => new { p, asm = asm.FirstOrDefault() }) .Count(y => y.p.aum.IsCompleted && !y.p.aum.IsApproved && y.p.aum.TraineeId == traineeId && y.asm.CourseSubtopic.CourseId == x.u.t.s.r.q.p.c.Id), UserDetails = new Common.Entity.User { UserId = x.u.t.s.r.lmum.UserId, FullName = x.u.t.s.r.lmum.User.FirstName + " " + x.u.t.s.r.lmum.User.LastName, Email = x.u.t.s.r.lmum.User.Email, Designation = x.u.t.s.r.lmum.User.Designation, ProfilePictureName = x.u.t.s.r.lmum.User.ProfilePictureName } }) .ToList() .GroupBy(x => x.Id) .Select(x => x.First()) .ToList()); } } catch (Exception ex) { LogUtility.ErrorRoutine(ex); return(new List <CourseTrackerDetails>()); } }
/// <summary> /// Data Access method to Save response for the survey /// </summary> /// <param name="response">instance of response</param> /// <param name="survey">instance of survey</param> /// <returns>id of saved feedback</returns> public int SaveWeeklySurveyResponseForTrainee(Common.Entity.SurveyResponse response, Common.Entity.Survey survey) { try { using (TrainingTrackerEntities context = new TrainingTrackerEntities()) { SurveyCompletedMetaData instanceMetaData = new SurveyCompletedMetaData { SurveyId = survey.SurveyId, SurveyTakenBy = response.AddedBy.UserId, DateCompleted = DateTime.Now }; Feedback feedback = new Feedback { AddedBy = response.Feedback.AddedBy.UserId, AddedFor = response.Feedback.AddedFor.UserId, AddedOn = DateTime.Now, SkillId = 0, FeedbackText = response.Feedback.FeedbackText, FeedbackType = response.Feedback.FeedbackType.FeedbackTypeId, Title = response.Feedback.FeedbackType.Description, StartDate = response.Feedback.StartDate, EndDate = response.Feedback.EndDate, ProjectId = 0, Rating = (short?)response.Feedback.Rating }; foreach (var ans in response.Response) { instanceMetaData.SurveyResponses.Add(new SurveyResponse { SurveyQuestionId = ans.QuestionId, SurveyAnswerId = ans.AnswerId, AdditionalNote = ans.AdditionalNotes, DateCreated = DateTime.Now }); } context.SurveyCompletedMetaDatas.Add(instanceMetaData); context.Feedbacks.Add(feedback); context.WeeklyFeedbackSurveyMappings.Add(new WeeklyFeedbackSurveyMapping { FeedbackId = feedback.FeedbackId, SurveyCompletedMetaDataId = instanceMetaData.SurveyCompletedMetaDataId }); context.SaveChanges(); return(feedback.FeedbackId); } } catch (Exception ex) { LogUtility.ErrorRoutine(ex); return(-1); } }
/// <summary> /// Interface signature for fetching course Detail /// </summary> /// <param name="userId">user id</param> /// <param name="assignmentId">assignment id</param> /// <param name="subtopicContentId">subtopic id</param> /// <returns>courseid</returns> public CourseTrackerDetails GetCourseDetailBasedOnParameters(int userId, int assignmentId = 0, int subtopicContentId = 0) { try { using (TrainingTrackerEntities context = new TrainingTrackerEntities()) { int courseId = 0; if (assignmentId > 0 && subtopicContentId == 0) { var assignment = context.Assignments.FirstOrDefault(x => x.Id == assignmentId); if (assignment != null) { var assignmentSubtopicMap = assignment.AssignmentSubtopicMaps.FirstOrDefault(); if (assignmentSubtopicMap != null) { courseId = assignmentSubtopicMap.CourseSubtopic.CourseId; } } } else if (assignmentId == 0 && subtopicContentId > 0) { var subTopic = context.SubtopicContents.FirstOrDefault(x => x.Id == subtopicContentId); if (subTopic != null) { courseId = subTopic.CourseSubtopic.CourseId; } } else { throw new NotImplementedException(); } // fetch user and course return(context.Courses.Where(x => x.Id == courseId) .Select(x => new CourseTrackerDetails { Id = x.Id, Name = x.Name, TotalAssignmentCount = x.CourseSubtopics.SelectMany(y => y.AssignmentSubtopicMaps.Select(z => z.Assignment).Where(a => a.IsActive)).Count(), CompletedAssignmentCount = x.CourseSubtopics.SelectMany(y => y.AssignmentSubtopicMaps.Select(yz => yz.Assignment).Where(a => a.IsActive).SelectMany(z => z.AssignmentUserMaps.Where(za => za.IsApproved && za.TraineeId == userId))).Count(), TotalSubTopicCount = x.CourseSubtopics.SelectMany(y => y.SubtopicContents.Where(ya => ya.IsActive)).Count(), CoveredSubTopicCount = x.CourseSubtopics.SelectMany(y => y.SubtopicContents.Where(ya => ya.IsActive).SelectMany(z => z.SubtopicContentUserMaps.Where(za => za.Seen && za.UserId == userId))).Count(), }).FirstOrDefault()); throw new Exception("Course details cannot be null,there have to be course assigned"); } } catch (Exception ex) { LogUtility.ErrorRoutine(ex); return(null); } }