예제 #1
0
        /// <summary>
        /// Add New feedback for user
        /// </summary>
        /// <param name="feedback">instance of feedback object</param>
        /// <returns>success flag wether feedback was added or not</returns>
        public bool AddFeedback(Feedback feedback)
        {
            feedback.Project = feedback.Project ?? new Project();

            if (feedback.FeedbackType.FeedbackTypeId == (int)FeedbackType.Skill)
            {
                if (!string.IsNullOrEmpty(feedback.Title))
                {
                    Skill newSkill = new Skill
                    {
                        Name    = feedback.Title,
                        AddedBy = feedback.AddedBy.UserId,
                        AddedOn = DateTime.Now
                    };

                    newSkill.SkillId = SkillDataAccesor.AddNewSkillForId(newSkill);

                    //Since new skill update the skill data
                    feedback.Skill.SkillId = newSkill.SkillId;
                    feedback.Skill.Name    = feedback.Title;
                }

                feedback.Title = feedback.Skill.Name;
                feedback.Skill = new Skill
                {
                    SkillId = feedback.Skill.SkillId
                };
            }
            else
            {
                feedback.Skill = new Skill();
            }

            // no way comment can have feedback rating
            if (feedback.FeedbackType.FeedbackTypeId == (int)FeedbackType.Comment || feedback.FeedbackType.FeedbackTypeId == (int)FeedbackType.Course)
            {
                feedback.Rating = 0;
            }

            feedback.Title = string.IsNullOrEmpty(feedback.Title) ? feedback.FeedbackType.Description : feedback.Title;

            int feedbackId = FeedbackDataAccesor.AddFeedback(feedback);

            if (!(feedbackId > 0))
            {
                return(false);
            }

            feedback.FeedbackId = feedbackId;

            return(new NotificationBl().AddFeedbackNotification(feedback));
        }
예제 #2
0
        /// <summary>
        ///  Private to class method to generate course
        /// </summary>
        /// <param name="courseId">Course Id</param>
        /// <param name="userId">User Id</param>
        /// <returns>success flag for the event</returns>
        internal bool GenerateCourseFeedback(int courseId, int userId)
        {
            Course course = LearningPathDataAccessor.GetCourseWithAllData(courseId, userId);

            Feedback feedback = new Feedback
            {
                AddedBy = new User {
                    UserId = Constants.AppBotUserId
                },
                AddedFor = new User {
                    UserId = userId
                },
                FeedbackType = new Common.Entity.FeedbackType {
                    FeedbackTypeId = (int)FeedbackType.Course
                },
                FeedbackText = UtilityFunctions.GenerateHtmlForCourseFeedback(course),
                Title        = course.Name
            };

            return(AddFeedback(feedback));
        }
예제 #3
0
        public bool SubmitCodeReviewFeedback(CodeReview codeReview)
        {
            CodeReviewMetaData codeReviewMetaData        = UnitOfWork.CodeReviewRepository.GetCodeReviewWithAllData(codeReview.Id);
            CodeReview         codeReviewDetailsFromCore = CodeReviewConverter.ConvertFromCore(codeReviewMetaData);

            Feedback feedback = new Feedback
            {
                AddedBy = new User {
                    UserId = codeReview.AddedBy.UserId
                },
                AddedFor = new User {
                    UserId = codeReview.AddedFor.UserId
                },
                FeedbackType = new Common.Entity.FeedbackType {
                    FeedbackTypeId = (int)FeedbackType.CodeReview
                },
                FeedbackText = UtilityFunctions.GenerateCodeReviewPreview(codeReviewDetailsFromCore, true),
                Skill        = new Skill(),
                Project      = new Project(),
                Title        = codeReviewDetailsFromCore.Title,
                Rating       = codeReview.Rating
            };

            int feedbackId = FeedbackDataAccesor.AddFeedback(feedback);

            if (!(feedbackId > 0))
            {
                return(false);
            }

            codeReviewMetaData.FeedbackId   = feedback.FeedbackId = feedbackId;
            codeReviewMetaData.SystemRating = CalculateCodeReviewRating(codeReviewDetailsFromCore);

            UnitOfWork.Commit();

            return(new NotificationBl().AddFeedbackNotification(feedback));

            //  return AddFeedback(feedback);
        }
예제 #4
0
        /// <summary>
        /// Dal method to Add feedback
        /// </summary>
        /// <param name="feedbackData">feedback instance</param>
        /// <returns>int of feedback</returns>
        public int AddFeedback(Feedback feedbackData)
        {
            try
            {
                var feedback = new EntityFramework.Feedback
                {
                    FeedbackText = feedbackData.FeedbackText.Trim(),
                    Title        = feedbackData.Title,
                    FeedbackType = feedbackData.FeedbackType.FeedbackTypeId,
                    ProjectId    = feedbackData.Project.ProjectId,
                    SkillId      = feedbackData.Skill.SkillId,
                    Rating       = (short?)feedbackData.Rating,
                    AddedBy      = feedbackData.AddedBy.UserId,
                    AddedFor     = feedbackData.AddedFor.UserId,
                    StartDate    = feedbackData.StartDate,
                    EndDate      = feedbackData.EndDate,
                    AddedOn      = feedbackData.AddedOn == DateTime.MinValue ? DateTime.Now : feedbackData.AddedOn
                };

                using (var context = new TrainingTrackerEntities())
                {
                    context.Feedbacks.Add(feedback);
                    context.SaveChanges();

                    // Add new mapping for user and skill
                    if (feedbackData.FeedbackType.FeedbackTypeId == (int)Common.Enumeration.FeedbackType.Skill)
                    {
                        SkillDal.AddUserSkillMapping(feedbackData.Skill.SkillId, feedbackData.AddedFor.UserId, feedbackData.AddedBy.UserId);
                    }

                    return(feedback.FeedbackId);
                }
            }
            catch (Exception ex)
            {
                LogUtility.ErrorRoutine(ex);
                return(0);
            }
        }
예제 #5
0
        /// <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)));
        }