Beispiel #1
0
 /// <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);
     }
 }
Beispiel #2
0
 /// <summary>
 /// Signature for method validates whether is allowed to access the course or not
 /// </summary>
 /// <param name="requestedCourseId">course id to validated to allow access</param>
 /// <param name="currentUser">requested user instance</param>
 /// <returns>success flag for user permission to acces the page</returns>
 public bool AuthorizeUserForCourse(int requestedCourseId, Common.Entity.User currentUser)
 {
     try
     {
         using (TrainingTrackerEntities context = new TrainingTrackerEntities())
         {
             return(context.LearningMapCourseMappings
                    .Any(x => x.CourseId == requestedCourseId &&
                         x.LearningMap.LearningMapUserMappings.Any(y => y.UserId == currentUser.UserId)));
         }
     }
     catch (Exception ex)
     {
         LogUtility.ErrorRoutine(ex);
         return(false);
     }
 }