Exemplo n.º 1
0
        /// <summary>
        /// Calls stored procedure which adds user.
        /// </summary>
        /// <param name="userData">User data object.</param>
        /// <param name="managerId">Id of manager adding.</param>
        /// <param name="userId">Out parameter created UserId.</param>
        /// <returns>True if added.</returns>
        public bool AddUser(User userData, int managerId, out int userId)
        {
            userData.Password = Cryptography.Encrypt(userData.Password);
            var isUserAdded = UserDataAccesor.AddUser(userData, out userId);

            var dbUser = GetUserByUserId(userId);

            var teamManagers = UnitOfWork.UserRepository
                               .Find(u => u.TeamId == dbUser.TeamId && u.IsManager == true)
                               .Select(lead => lead.UserId)
                               .ToList();

            if (isUserAdded)
            {
                teamManagers.ForEach(manager => UnitOfWork.EmailAlertSubscriptionRepository
                                     .AddOrUpdate(new EmailAlertSubscription
                {
                    SubscribedByUserId  = manager,
                    SubscribedForUserId = dbUser.UserId
                }));
                UnitOfWork.Commit();
            }

            if (isUserAdded && dbUser.IsTrainee)
            {
                new NotificationBl().UserNotification(dbUser, managerId);
            }

            return(isUserAdded);
        }
Exemplo n.º 2
0
        public async Task <List <User> > SyncGPSUsers(User currentUser)
        {
            List <User> gpsMembersUnderLead = await GetMembersUnderLead(currentUser.EmployeeId);

            List <User> ttMembersUnderLead = GetManageProfileVm(currentUser).AllUser;
            List <User> unsyncedMembers    = new List <User>();

            foreach (var gpsMember in gpsMembersUnderLead)
            {
                foreach (var ttMember in ttMembersUnderLead)
                {
                    if (ttMember.UserName == gpsMember.UserName)
                    {
                        ttMember.EmployeeId = gpsMember.EmployeeId;
                        if (!UserDataAccesor.UpdateUser(ttMember))
                        {
                            unsyncedMembers.Add(ttMember);
                        }
                    }
                    else
                    {
                        unsyncedMembers.Add(ttMember);
                    }
                }
            }
            return(unsyncedMembers);
        }
Exemplo n.º 3
0
 /// <summary>
 /// Get manage Profile View model
 /// </summary>
 /// <param name="currentUser">current user</param>
 public ManageProfileVm GetManageProfileVm(User currentUser)
 {
     return(new ManageProfileVm
     {
         AllTeams = TeamDataAccesor.GetAllTeam(),
         AllUser = GetAllUsersByTeam(currentUser)
     });
 }
Exemplo n.º 4
0
        /// <summary>
        /// Function for getting list of active user.
        /// </summary>
        /// <returns>Returns list of active user.</returns>
        public List <User> GetActiveUsers(User currentUser)
        {
            if (currentUser.IsAdministrator && !currentUser.TeamId.HasValue)
            {
                return(UserDataAccesor.GetActiveUsers());
            }

            return(currentUser.TeamId.HasValue
                              ? UserDataAccesor.GetActiveUsersByTeam(currentUser.TeamId.Value).Where(x => !currentUser.IsTrainee || !x.IsTrainee || x.UserId == currentUser.UserId).ToList()
                              : new List <User>());
        }
Exemplo n.º 5
0
        /// <summary>
        /// GEt all user
        /// </summary>
        /// <returns>List of User</returns>
        public List <User> GetAllUsersByTeam(User currentUser)
        {
            if (currentUser.IsAdministrator && !currentUser.TeamId.HasValue)
            {
                return(UserDataAccesor.GetAllUsers());
            }

            return(currentUser.TeamId.HasValue
                              ? UserDataAccesor.GetAllUsersForTeam(currentUser.TeamId.Value)
                              : new List <User>());
        }
Exemplo n.º 6
0
        /// <summary>
        /// Fetches all feedback Threads
        /// </summary>
        /// <param name="feedbackId">feedbackId</param>
        /// <param name="currentUser">current user</param>
        public List <Threads> GetFeedbackThreads(int feedbackId, User currentUser)
        {
            int feedbackForUserId = FeedbackDataAccesor.GetTraineebyFeedbackId(feedbackId);

            if (!(currentUser.IsAdministrator || currentUser.IsManager || currentUser.IsTrainer || currentUser.UserId == feedbackForUserId))
            {
                return(null);
            }

            return(FeedbackDataAccesor.GetFeedbackThreads(feedbackId));
        }
Exemplo n.º 7
0
        /// <summary>
        /// Public method GetUserId returns list of user id as per the condition,
        /// So specific notifications are added to specific user profile.
        /// </summary>
        /// <param name="notification">Contain notificationType as parameter.</param>
        /// <param name="addedFor">Contain notificationType as parameter.</param>
        /// <returns>Returns user Ids as a list.</returns>
        public List <int> GetUserId(Notification notification, int addedFor)
        {
            try
            {
                User currentUser = GetUserById(addedFor);

                using (TrainingTrackerEntities context = new TrainingTrackerEntities())
                {
                    switch (notification.TypeOfNotification)
                    {
                    case NotificationType.CodeReviewFeedbackNotification:
                    case NotificationType.AssignmentFeedbackNotification:
                    case NotificationType.SkillFeedbackNotification:
                    case NotificationType.CommentFeedbackNotification:
                    case NotificationType.WeeklyFeedbackNotification:
                    case NotificationType.NewNoteToFeedback:
                    case NotificationType.CourseFeedbackNotification:
                    case NotificationType.NewDiscussionPostNotification:
                    case NotificationType.NewDiscussionThreadNotification:
                    case NotificationType.RandomReviewFeedbackNotification:
                        return(context.Users
                               .Where(x => (x.UserId == addedFor || x.IsTrainer == true || x.IsManager == true) &&
                                      (x.IsActive == true && x.UserId != notification.AddedBy) &&
                                      (currentUser.TeamId.HasValue && x.TeamId == currentUser.TeamId))
                               .Select(x => x.UserId)
                               .ToList());

                    case NotificationType.NewReleaseNotification:
                    case NotificationType.NewFeatureRequestNotification:
                    case NotificationType.FeatureModifiedNotification:
                        return(context.Users.Where(x => x.UserId != notification.AddedBy && x.IsActive == true)
                               .Select(x => x.UserId)
                               .ToList());

                    case NotificationType.NewUserNotification:
                    case NotificationType.UserActivatedNotification:
                    case NotificationType.NewSessionNotification:
                    case NotificationType.SessionUpdatedNotification:
                        return(context.Users.Where(x => (x.IsManager == true || x.IsTrainer == true) &&
                                                   (x.IsActive == true && x.UserId != notification.AddedBy) &&
                                                   (currentUser.TeamId.HasValue && x.TeamId == currentUser.TeamId))
                               .Select(x => x.UserId)
                               .ToList());
                    }
                    return(null);
                }
            }
            catch (Exception ex)
            {
                LogUtility.ErrorRoutine(ex);
                return(null);
            }
        }
Exemplo n.º 8
0
 /// <summary>
 /// Calls stored procedure which validates user.
 /// </summary>
 /// <param name="userData">User data object.</param>
 /// <returns>True if valid customer.</returns>
 public bool ValidateUser(User userData)
 {
     try
     {
         using (TrainingTrackerEntities context = new TrainingTrackerEntities())
         {
             return(context.Users.Any(x => x.UserName == userData.UserName && x.Password == userData.Password && (x.IsAdministrator == true || x.TeamId.HasValue)));
         }
     }
     catch (Exception ex)
     {
         LogUtility.ErrorRoutine(ex);
         return(false);
     }
 }
Exemplo n.º 9
0
        /// <summary>
        /// Calls stored procedure which updates user.
        /// </summary>
        /// <param name="userData">User data object.</param>
        /// <returns>True if updated.</returns>
        public bool UpdateUser(User userData)
        {
            if (userData.UserId <= 0)
            {
                return(false);
            }

            try
            {
                using (TrainingTrackerEntities context = new TrainingTrackerEntities())
                {
                    var userContext = context.Users.FirstOrDefault(x => x.UserId == userData.UserId);

                    if (userContext == null)
                    {
                        return(false);
                    }

                    userContext.FirstName          = userData.FirstName;
                    userContext.LastName           = userData.LastName;
                    userContext.UserName           = userData.UserName;
                    userContext.Email              = userData.Email;
                    userContext.Designation        = userData.Designation;
                    userContext.ProfilePictureName = userData.ProfilePictureName;
                    userContext.IsFemale           = userData.IsFemale;
                    userContext.IsAdministrator    = userData.IsAdministrator;
                    userContext.IsTrainer          = userData.IsTrainer;
                    userContext.IsTrainee          = userData.IsTrainee;
                    userContext.IsManager          = userData.IsManager;
                    userContext.IsActive           = userData.IsActive;
                    userContext.EmployeeId         = userData.EmployeeId;
                    if (!string.IsNullOrEmpty(userData.Password))
                    {
                        userContext.Password = userData.Password;
                    }
                    userContext.TeamId = userData.TeamId;

                    context.SaveChanges();
                    return(true);
                }
            }
            catch (Exception ex)
            {
                LogUtility.ErrorRoutine(ex);
                return(false);
            }
        }
Exemplo n.º 10
0
        /// <summary>
        /// Calls stored procedure which updates user.
        /// </summary>
        /// <param name="userData">User data object.</param>
        /// <param name="addedById">manager id</param>
        /// <returns>True if updated.</returns>
        public bool UpdateUser(User userData, int addedById)
        {
            userData.Password = Cryptography.Encrypt(userData.Password);
            var isUserUpdated = UserDataAccesor.UpdateUser(userData);
            var dbUser        = GetUserByUserId(userData.UserId);
            var teamManagers  = UnitOfWork.UserRepository
                                .Find(u => u.TeamId == dbUser.TeamId && u.IsManager == true)
                                .Select(lead => lead.UserId)
                                .ToList();

            try
            {
                if (isUserUpdated && dbUser.IsTrainee)
                {
                    UnitOfWork.EmailAlertSubscriptionRepository
                    .GetAllSubscribedMentors(userData.UserId, includeDeleted: true)
                    .ForEach(s =>
                    {
                        s.IsDeleted = !(userData.IsActive && teamManagers.Contains(s.SubscribedByUserId));
                        teamManagers.Remove(s.SubscribedByUserId);                   //Remove from managers if record exists. Also avoids duplicate notifications.
                        UnitOfWork.EmailAlertSubscriptionRepository.AddOrUpdate(s);
                    });

                    teamManagers.ForEach(manager => UnitOfWork.EmailAlertSubscriptionRepository
                                         .AddOrUpdate(new EmailAlertSubscription
                    {
                        SubscribedByUserId  = manager,
                        SubscribedForUserId = dbUser.UserId
                    }));

                    UnitOfWork.Commit();

                    if (dbUser.IsActive)
                    {
                        new NotificationBl().UserNotification(dbUser, addedById, isNewUser: false);
                    }
                }
            }
            catch (Exception ex)
            {
                LogUtility.ErrorRoutine(ex);
                isUserUpdated = false;
            }

            return(isUserUpdated);
        }
Exemplo n.º 11
0
        public bool AddPostThread(ForumThread postThread, User currentUser)
        {
            var threadToAdd = ForumDiscussionThreadConverter.ConvertToCore(postThread);

            threadToAdd.CreatedOn = DateTime.Now;
            threadToAdd.AddedBy   = currentUser.UserId;
            UnitOfWork.ForumDiscussionThreadRepository.Add(threadToAdd);
            UnitOfWork.Commit();
            if (threadToAdd.Id > 0)
            {
                postThread.AddedBy     = currentUser.UserId;
                postThread.PostId      = threadToAdd.PostId;
                postThread.AddedByUser = currentUser;
                new NotificationBl().AddNewDiscussionThreadNotification(postThread);
            }

            return(threadToAdd.Id > 0);
        }
Exemplo n.º 12
0
        /// <summary>
        /// method to Add or edit session details
        /// </summary>
        /// <param name="objSession">instance of session Object</param>
        /// <returns>boolean resutt of event's success</returns>
        public bool UpdateSessionsDetails(Session objSession, User currentUser)
        {
            if (objSession.Id <= 0)
            {
                return(false);
            }
            try
            {
                DAL.EntityFramework.Session coreSession = UnitOfWork.SessionRepository
                                                          .GetSessionWithAttendeesTrackable(objSession.Id);

                coreSession.SessionDate   = objSession.Date;
                coreSession.Description   = objSession.Description;
                coreSession.Title         = objSession.Title;
                coreSession.SlideName     = objSession.SlideName;
                coreSession.VideoFileName = objSession.VideoFileName;

                coreSession.UserSessionMappings.Where(x => objSession.SessionAttendees.All(y => y.UserId != x.UserId))
                .ToList()
                .ForEach(trainee => coreSession.UserSessionMappings.Remove(trainee));


                objSession.SessionAttendees.Where(x => coreSession.UserSessionMappings.All(y => y.UserId != x.UserId))
                .ToList()
                .ForEach(trainee => coreSession.UserSessionMappings.Add(new UserSessionMapping
                {
                    AddedBy = currentUser.UserId,
                    AddedOn = DateTime.Now,
                    UserId  = trainee.UserId
                }));

                objSession.Presenter = currentUser;

                return(UnitOfWork.Commit() > 0 && (new NotificationBl().AddSessionNotification(objSession)));
            }
            catch (Exception ex)
            {
                LogUtility.ErrorRoutine(ex);
                return(false);
            }
        }
Exemplo n.º 13
0
        /// <summary>
        /// Get view model for user profile page
        /// </summary>
        /// <param name="userId">user id</param>
        /// <param name="loggedInUser"></param>
        /// <returns>instance of User vm</returns>
        public UserProfileVm GetUserProfileVm(int userId, User loggedInUser)
        {
            User requestedUser = userId == loggedInUser.UserId ? loggedInUser : UserDataAccesor.GetUserById(userId);

            CodeReview codeReview = loggedInUser.IsTrainer || loggedInUser.IsManager
                                        ? CodeReviewConverter.ConvertFromCore(UnitOfWork.CodeReviewRepository.GetSavedCodeReviewForTrainee(userId, loggedInUser.UserId))
                                        : null;
            var commonTags = UnitOfWork.CodeReviewRepository
                             .GetCommonlyUsedTags(userId, 5)
                             .Select(skill => new CodeReviewTag
            {
                CodeReviewTagId = 0,
                Skill           = new Skill
                {
                    Name    = skill.Name,
                    SkillId = skill.SkillId
                }
            }).ToList();

            if (codeReview != null)
            {
                codeReview.CodeReviewPreviewHtml = UtilityFunctions.GenerateCodeReviewPreview(codeReview, true);
                codeReview.SystemRating          = new FeedbackBl().CalculateCodeReviewRating(codeReview);
            }

            return(new UserProfileVm
            {
                User = userId == loggedInUser.UserId ? null : requestedUser,
                Skills = requestedUser.IsTrainee ? SkillDataAccesor.GetSkillsByUserId(userId) : null,
                TraineeSynopsis = requestedUser.IsTrainee ? FeedbackDataAccesor.GetTraineeFeedbackSynopsis(requestedUser.UserId) : null,
                Sessions = requestedUser.IsTrainee ? SessionConverter.ConvertListFromCore(UnitOfWork.SessionRepository.GetAllSessionForAttendee(userId)) : null,
                Projects = null,
                Feedbacks = requestedUser.IsTrainee ? FeedbackDataAccesor.GetUserFeedback(userId, 5) : FeedbackDataAccesor.GetFeedbackAddedByUser(userId),
                TrainorSynopsis = requestedUser.IsTrainer || requestedUser.IsManager ? FeedbackDataAccesor.GetTrainorFeedbackSynopsis(requestedUser.UserId) : null,
                AllAssignedCourses = requestedUser.IsTrainee ? LearningPathDataAccessor.GetAllCoursesForTrainee(requestedUser.UserId).OrderByDescending(x => x.PercentageCompleted).ToList() : new List <CourseTrackerDetails>(),
                SavedCodeReview = codeReview,
                CommonTags = commonTags
                             //  SavedCodeReviewData = logedInUser.IsTrainer && (codeReview != null && codeReview.Id > 0) ? UtilityFunctions.GenerateCodeReviewPreview(codeReview, true) : string.Empty
            });
        }
Exemplo n.º 14
0
        /// <summary>
        /// Function which add user notification
        /// Calls AddNotification() to save in the database.
        /// </summary>
        /// <param name="user">Release object</param>
        /// <param name="managerId">manager Id</param>
        /// <param name="isNewUser">true if user is new</param>
        /// <returns>Returns true if Notification is added successfully else false.</returns>
        internal bool UserNotification(User user, int managerId, bool isNewUser = true)
        {
            var notificationManagementLink = "/Setting/UserSetting?settingName=Notification&user="******"New user ""{0}"" added!", user.FullName)
                                   : string.Format(@"User ""{0}"" has been activated.", user.FullName));

            var notification = new Notification
            {
                Description        = description,
                Link               = notificationManagementLink,
                TypeOfNotification = isNewUser ? NotificationType.NewUserNotification
                                                            : NotificationType.UserActivatedNotification,
                AddedBy = managerId,
                Title   = description,
                AddedOn = DateTime.Now,
            };

            return(AddNotification(notification, UserDataAccesor.GetUserId(notification, managerId)));
        }
Exemplo n.º 15
0
        public bool AddPost(ForumPost post, User currentUser)
        {
            var postToAdd = ForumDiscussionPostConverter.ConvertToCore(post);

            postToAdd.CreatedOn  = DateTime.Now;
            postToAdd.AddedBy    = currentUser.UserId;
            postToAdd.CategoryId = 1;// Need to change HardCoded Value
            UnitOfWork.ForumDiscussionPostRepository.Add(postToAdd);
            UnitOfWork.Commit();

            if (postToAdd.Id <= 0)
            {
                return(false);
            }

            post.AddedBy     = currentUser.UserId;
            post.PostId      = postToAdd.Id;
            post.AddedByUser = currentUser;
            new NotificationBl().AddNewDiscussionPostNotification(post);

            return(true);
        }
Exemplo n.º 16
0
        /// <summary>
        /// Calls stored procedure which adds user.
        /// </summary>
        /// <param name="userData">User data object.</param>
        /// <param name="userId">Out parameter created UserId.</param>
        /// <returns>True if added.</returns>
        public bool AddUser(User userData, out int userId)
        {
            userId = 0;
            try
            {
                using (TrainingTrackerEntities context = new TrainingTrackerEntities())
                {
                    EntityFramework.User objUser = new EntityFramework.User
                    {
                        FirstName          = userData.FirstName,
                        LastName           = userData.LastName,
                        UserName           = userData.UserName,
                        Password           = userData.Password,
                        Email              = userData.Email,
                        Designation        = userData.Designation,
                        ProfilePictureName = userData.ProfilePictureName,
                        IsFemale           = userData.IsFemale,
                        IsAdministrator    = userData.IsAdministrator,
                        IsTrainer          = userData.IsTrainer,
                        IsTrainee          = userData.IsTrainee,
                        IsManager          = userData.IsManager,
                        DateAddedToSystem  = DateTime.Now,
                        IsActive           = userData.IsActive,
                        TeamId             = userData.TeamId,
                        EmployeeId         = userData.EmployeeId
                    };

                    context.Users.Add(objUser);
                    context.SaveChanges();
                    userId = objUser.UserId;
                    return(true);
                }
            }
            catch (Exception ex)
            {
                LogUtility.ErrorRoutine(ex);
                return(false);
            }
        }
Exemplo n.º 17
0
        /// <summary>
        /// method to Add or edit session details
        /// </summary>
        /// <param name="objSession">instance of session Object</param>
        /// <param name="currentUser">instance of Current User</param>
        /// <returns>boolean resutt of event's success</returns>
        public SessionVm AddNewSession(Session objSession, User currentUser)
        {
            objSession.IsNeW     = (objSession.Id == 0);
            objSession.Presenter = currentUser;

            DAL.EntityFramework.Session coreSession = SessionConverter.ConvertToCore(objSession);

            foreach (var trainee in objSession.SessionAttendees)
            {
                coreSession.UserSessionMappings.Add(new UserSessionMapping
                {
                    AddedBy = currentUser.UserId,
                    AddedOn = DateTime.Now,
                    UserId  = trainee.UserId
                });
            }
            UnitOfWork.SessionRepository.Add(coreSession);

            UnitOfWork.Commit();
            objSession.Id = coreSession.SessionId;

            new NotificationBl().AddSessionNotification(objSession);
            return(GetSessionOnFilter(1, (int)Common.Enumeration.SessionType.All, coreSession.SessionId, "", currentUser));
        }
Exemplo n.º 18
0
        public SessionVm GetSessionVm(int pageNumber, int sessionType, int sessionId, string searchKeyword, User currentUser)
        {
            SessionVm objSessionVm = GetSessions(pageNumber, sessionType, sessionId, searchKeyword, currentUser);

            objSessionVm.AllAttendees = UserConverter.ConvertListFromCore(UnitOfWork.UserRepository.GetAllTrainees(currentUser.TeamId ?? 0, true))
                                        .OrderBy(x => x.FirstName)
                                        .ToList();

            return(objSessionVm);
        }
Exemplo n.º 19
0
        public bool UpdatePostStatus(int postId, int statusId, string message, int addedFor, User currentUser)
        {
            var post = UnitOfWork.ForumDiscussionPostRepository.Get(postId);

            post.StatusId = statusId;
            post.ForumDiscussionThreads.Add(new ForumDiscussionThread
            {
                CreatedOn   = DateTime.Now,
                Description = message,
                AddedBy     = currentUser.UserId
            });


            if (UnitOfWork.Commit() <= 0)
            {
                return(false);
            }

            new NotificationBl().AddNewDiscussionThreadNotification(new ForumThread()
            {
                PostId      = postId,
                Description = message,
                AddedBy     = currentUser.UserId,
                AddedFor    = addedFor,
                AddedByUser = currentUser
            });

            return(true);
        }
Exemplo n.º 20
0
 /// <summary>
 /// authorize Current user for team's Feedback
 /// </summary>
 /// <param name="feedbackId">feedback Id</param>
 /// <param name="currentUser">Current User</param>
 /// <returns>Success flag</returns>
 public bool AuthorizeCurrentUserForFeedback(int feedbackId, User currentUser)
 {
     return((currentUser.IsAdministrator && !currentUser.TeamId.HasValue) ||
            FeedbackDataAccesor.GetFeedbackWithThreads(feedbackId).AddedBy.UserId == Constants.AppBotUserId ||
            FeedbackDataAccesor.GetFeedbackWithThreads(feedbackId).AddedBy.TeamId == currentUser.TeamId);
 }
Exemplo n.º 21
0
 /// <summary>
 /// Get session based on filter conditions
 /// </summary>
 /// <param name="pageNumber">Current page number</param>
 /// <param name="sessionType">type of session All/Presented/Scheduled</param>
 ///  <param name="sessionId">any session id</param>
 /// <param name="searchKeyword">any keyword term</param>
 /// <param name="currentUser">CurrentUser</param>
 /// <returns>instance of session method</returns>
 public SessionVm GetSessionOnFilter(int pageNumber, int sessionType, int sessionId, string searchKeyword, User currentUser)
 {
     return(GetSessions(pageNumber, sessionType, sessionId, searchKeyword, currentUser));
 }
Exemplo n.º 22
0
        public SessionVm GetSessions(int pageNumber, int sessionType, int sessionId, string searchKeyword, User currentUser)
        {
            SessionVm objSessionVm = new SessionVm
            {
                SessionList = GetPagedFilteredSessions(searchKeyword, sessionType, sessionId, currentUser.TeamId ?? 0, pageNumber, 5),
            };

            if (objSessionVm.SessionList.Results != null && objSessionVm.SessionList.Results.Count > 0)
            {
                objSessionVm.DefaultSession = GetSessionWithAttendees(objSessionVm.SessionList.Results[0].Id);
            }

            return(objSessionVm);
        }