public bool AddSessionMail(Notification notification, Common.Entity.Session session) { User addedByUser = UserDataAccesor.GetUserById(notification.AddedBy); EmailContent emailContent = GetEmailContent(notification , addedByUser , notification.Title); foreach (var user in UnitOfWork.SessionRepository.GetSessionWithAttendees(session.Id).UserSessionMappings) { emailContent.EmailRecipients.Add(new EmailRecipient { EmailAddress = user.User1.Email, EmailRecipientType = (int)Common.Enumeration.EmailRecipientType.To }); } emailContent.EmailRecipients.Add(new EmailRecipient { EmailAddress = addedByUser.Email, EmailRecipientType = (int)Common.Enumeration.EmailRecipientType.CarbonCopy }); UnitOfWork.EmailRepository.Add(emailContent); //TODO:EmailRepository needs to be EmailContentRepository. return(UnitOfWork.Commit() > 0); }
public bool AddNewFeedbackMail(Notification notification, User addedFor, int feedbackId) { User addedByUser = UserDataAccesor.GetUserById(notification.AddedBy); EmailContent emailContent = GetEmailContent(notification , addedByUser , notification.Title); emailContent.EmailRecipients.Add(new EmailRecipient { EmailAddress = addedFor.Email, EmailRecipientType = (int)Common.Enumeration.EmailRecipientType.To }); foreach (var user in UnitOfWork.EmailAlertSubscriptionRepository.GetAllSubscribedMentors(addedFor.UserId) .Where(user => user.SubscribedByUserId != addedByUser.UserId)) { emailContent.EmailRecipients.Add(new EmailRecipient { EmailAddress = user.User.Email, EmailRecipientType = (int)Common.Enumeration.EmailRecipientType.CarbonCopy }); } UnitOfWork.EmailRepository.Add(emailContent); //TODO:EmailRepository needs to be EmailContentRepository. return(UnitOfWork.Commit() > 0); }
public bool AddNewDiscussionMail(Notification notification) { User addedByUser = UserDataAccesor.GetUserById(notification.AddedBy); List <EmailAlertSubscription> subscriptionList = UnitOfWork.EmailAlertSubscriptionRepository .GetAllSubscribedMentors(addedByUser.UserId) .Where(x => x.SubscribedByUserId != addedByUser.UserId) .Distinct() .ToList(); if (!subscriptionList.Any()) { return(true); // escape the routine if no one is subscribed to this trainee. } EmailContent emailContent = GetEmailContent(notification, addedByUser, notification.Title); foreach (var user in subscriptionList) { emailContent.EmailRecipients.Add(new EmailRecipient { EmailAddress = user.User.Email, EmailRecipientType = (int)Common.Enumeration.EmailRecipientType.To }); } UnitOfWork.EmailRepository.Add(emailContent); return(UnitOfWork.Commit() > 0); }
public Course GetCourseWithSubtopics(int courseId) { var courseDetails = LearningPathDataAccessor.GetCourseWithSubtopics(courseId); if (courseDetails != null) { courseDetails.AuthorName = UserDataAccesor.GetUserById(courseDetails.AddedBy).FirstName; } return(courseDetails); }
public bool AddNewDiscussionThreadMail(Notification notification, int discussionPostId) { User addedByUser = UserDataAccesor.GetUserById(notification.AddedBy); ForumDiscussionPost forumDiscussionPost = UnitOfWork.ForumDiscussionPostRepository.GetPostWithThreads(discussionPostId); List <EmailAlertSubscription> subscriptionList = UnitOfWork.EmailAlertSubscriptionRepository .GetAllSubscribedMentors(forumDiscussionPost.AddedBy) .Where(x => x.SubscribedByUserId != addedByUser.UserId) .ToList(); EmailContent emailContent = GetEmailContent(notification, addedByUser, notification.Title); List <DAL.EntityFramework.User> allUsers = forumDiscussionPost.ForumDiscussionThreads.Where(x => x.AddedBy != addedByUser.UserId) .Select(x => x.User) .Union(subscriptionList.Select(x => x.User)) .ToList(); if (addedByUser.UserId != forumDiscussionPost.AddedBy) { emailContent.EmailRecipients.Add(new EmailRecipient { EmailAddress = forumDiscussionPost.User.Email, EmailRecipientType = (int)Common.Enumeration.EmailRecipientType.To }); foreach (DAL.EntityFramework.User user in allUsers) { emailContent.EmailRecipients.Add(new EmailRecipient { EmailAddress = user.Email, EmailRecipientType = (int)Common.Enumeration.EmailRecipientType.CarbonCopy }); } } else { if (!allUsers.Any()) { return(true); // / escape the routine if no one is subscribed to this trainee. } foreach (DAL.EntityFramework.User user in allUsers) { emailContent.EmailRecipients.Add(new EmailRecipient { EmailAddress = user.Email, EmailRecipientType = (int)Common.Enumeration.EmailRecipientType.To }); } } UnitOfWork.EmailRepository.Add(emailContent); return(UnitOfWork.Commit() > 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 }); }
public Course GetCourseWithAllData(int courseId, User currentUser, int userId = 0) { Course courseDetails; if (!currentUser.IsTrainee) { if (userId > 0) { courseDetails = LearningPathDataAccessor.GetCourseWithAllData(courseId, userId); courseDetails.TrackerDetails = LearningPathDataAccessor.GetAllCoursesForTrainee(userId).FirstOrDefault(x => x.Id == courseId); } else { courseDetails = LearningPathDataAccessor.GetCourseWithAllData(courseId); } } else { courseDetails = LearningPathDataAccessor.GetCourseWithAllData(courseId, userId); } if (courseDetails != null) { User userData = UserDataAccesor.GetUserById(courseDetails.AddedBy); courseDetails.AuthorName = userData.FirstName; courseDetails.AuthorMailId = userData.Email; if (currentUser.IsTrainee && !courseDetails.IsStarted) { courseDetails.LoadAlert = true; foreach (CourseSubtopic subtopic in courseDetails.CourseSubtopics) { subtopic.Assignments = new Collection <Assignment>(); subtopic.SubtopicContents = new Collection <SubtopicContent>(); } } } return(courseDetails); }
public UserProfileVm GetUserProfileVm(int userId) { return(new UserProfileVm { User = UserDataAccesor.GetUserById(userId), Skills = SkillDataAccesor.GetSkillsByUserId(userId), AllSkills = SkillDataAccesor.GetAllSkillsForApp(), Sessions = SessionDataAccesor.GetSessionsByUserId(userId), Projects = ProjectDataAccesor.GetProjectsByUserId(userId), Feedbacks = FeedbackDataAccesor.GetUserFeedback(userId, 5), RecentCrFeedback = FeedbackDataAccesor.GetUserFeedback(userId, 100, 4), FeedbackTypes = new List <FeedbackType> { new FeedbackType { FeedbackTypeId = 1, Description = "Comment" }, new FeedbackType { FeedbackTypeId = 2, Description = "Skill" }, new FeedbackType { FeedbackTypeId = 3, Description = "Assignment" }, new FeedbackType { FeedbackTypeId = 4, Description = "Code Review" }, new FeedbackType { FeedbackTypeId = 5, Description = "Weekly Feedback" } } }); }
/// <summary> /// Function which takes feedback data and user list to whom notification is to be added, /// Calls AddNotification() to save in the database. /// </summary> /// <param name="feedback">Contain Feedback object as parameter.</param> /// <returns>Returns a boolean value as feedback notification is added successfully or not.</returns> internal bool AddFeedbackNotification(Feedback feedback) { NotificationType notificationType; string notificationText = string.Empty; switch ((FeedbackType)feedback.FeedbackType.FeedbackTypeId) { case FeedbackType.Weekly: { notificationType = NotificationType.WeeklyFeedbackNotification; notificationText = "New Weekly Feedback"; break; } case FeedbackType.Comment: { notificationType = NotificationType.CommentFeedbackNotification; notificationText = "New Comment"; break; } case FeedbackType.Skill: { notificationType = NotificationType.SkillFeedbackNotification; notificationText = "New Skill"; break; } case FeedbackType.Assignment: { notificationType = NotificationType.AssignmentFeedbackNotification; notificationText = "New Assignment Feedback"; break; } case FeedbackType.CodeReview: { notificationType = NotificationType.CodeReviewFeedbackNotification; notificationText = "New CR Feedback"; break; } case FeedbackType.Course: { notificationType = NotificationType.CourseFeedbackNotification; notificationText = "New Course Feedback"; break; } case FeedbackType.RandomReview: { notificationType = NotificationType.RandomReviewFeedbackNotification; notificationText = "New Random Review"; break; } default: { return(false); } } var user = UserDataAccesor.GetUserById(feedback.AddedFor.UserId); var notification = new Notification { Description = user.FirstName + " " + user.LastName, Link = string.Format(FeedbackLink, feedback.AddedFor.UserId, feedback.FeedbackId), TypeOfNotification = notificationType, AddedBy = feedback.AddedBy.UserId, Title = notificationText, AddedOn = DateTime.Now, }; new MailerBl().AddNewFeedbackMail(notification, user, feedback.FeedbackId); return(AddNotification(notification, UserDataAccesor.GetUserId(notification, feedback.AddedFor.UserId))); }
public bool AddNewFeedbackThreadMail(Notification notification, int feedbackId) { // This need to be changed... but How!! var addedByUser = UserDataAccesor.GetUserById(notification.AddedBy); Feedback feedback = UnitOfWork.FeedbackRepository.Get(feedbackId); EmailContent emailContent = GetEmailContent(notification , addedByUser , notification.Title); if (notification.AddedBy == feedback.User1.UserId) { emailContent.EmailRecipients.Add(new EmailRecipient { EmailAddress = feedback.User.Email, EmailRecipientType = (int)Common.Enumeration.EmailRecipientType.To }); } else { emailContent.EmailRecipients.Add(new EmailRecipient { EmailAddress = feedback.User1.Email, EmailRecipientType = (int)Common.Enumeration.EmailRecipientType.To }); if (notification.AddedBy != feedback.User.UserId) { emailContent.EmailRecipients.Add(new EmailRecipient { EmailAddress = feedback.User.Email, EmailRecipientType = (int)Common.Enumeration.EmailRecipientType.CarbonCopy }); } } foreach (var user in UnitOfWork.EmailAlertSubscriptionRepository.GetAllSubscribedMentors(feedback.User1.UserId) .Where(user => user.SubscribedByUserId != addedByUser.UserId)) { if (emailContent.EmailRecipients.All(x => x.EmailAddress != user.User.Email)) { emailContent.EmailRecipients.Add(new EmailRecipient { EmailAddress = user.User.Email, EmailRecipientType = (int)Common.Enumeration.EmailRecipientType.CarbonCopy }); } } foreach (var thread in feedback.FeedbackThreads.Where(user => user.AddedBy != addedByUser.UserId)) { if (emailContent.EmailRecipients.All(x => x.EmailAddress != thread.User.Email)) { emailContent.EmailRecipients.Add(new EmailRecipient { EmailAddress = thread.User.Email, EmailRecipientType = (int)Common.Enumeration.EmailRecipientType.CarbonCopy }); } } UnitOfWork.EmailRepository.Add(emailContent); return(UnitOfWork.Commit() > 0); }
/// <summary> /// Get User By user id /// </summary> /// <param name="userId">UserId</param> /// <returns>instance of User object</returns> public User GetUserByUserId(int userId) { return(UserDataAccesor.GetUserById(userId)); }