示例#1
0
        public IEnumerable <VmSurvey> GetSurveyList(string userId, QuestionType type)
        {
            var blPerson = new BLPerson();
            var person   = blPerson.GetPersonByUserId(userId);

            var blTeamMember = new BLTeamMember();

            VmTeamMember teamMember = null;

            var teamId = 0;

            if (person.RoleName.ToLower().Contains("judge") == false)
            {
                teamMember = blTeamMember.GetTeamMemberByUserId(userId);
                teamId     = teamMember.TeamId;
                blTeamMember.UpdateTeamMemberSurvey(userId, true);
            }

            var viewViewSurveyRepository = UnitOfWork.GetRepository <ViewSurveyRepository>();

            var questionList = viewViewSurveyRepository.GetViewSurveys(type);

            var vmSurveyList = (from q in questionList
                                group new
            {
                q.AnswerId,
                q.QuestionAnswerId,
                q.AnswerType,
                q.Weight,
                q.AnswerPriority,
                q.Answer,
                q.TitleVisible,
                q.Comment,
                q.ShowComment,
            }
                                by new
            {
                q.Id,
                q.Question,
                q.QuestionPriority,
                q.QuestionType,
                q.QuestionComment,
            }
                                into g
                                select new VmSurvey
            {
                Id = g.Key.Id,
                Question = g.Key.Question,
                QuestionPriority = g.Key.QuestionPriority,
                QuestionComment = g.Key.QuestionComment,
                QuestionType = g.Key.QuestionType,

                SurveyDetailList = (from gd in g.ToList()
                                    select new VmSurveyDetail
                {
                    AnswerId = gd.AnswerId,
                    QuestionAnswerId = gd.QuestionAnswerId,
                    AnswerType = gd.AnswerType,
                    Weight = gd.Weight,
                    AnswerPriority = gd.AnswerPriority,
                    Answer = gd.Answer,
                    TitleVisible = gd.TitleVisible,
                    Value = "",
                    Comment = gd.Comment,
                    ShowComment = gd.ShowComment,
                }).ToList()
            }).ToList();


            IEnumerable <ViewSurveyResult> surveyResultList = null;

            if (person.RoleName.ToLower().Contains("judge") == false)
            {
                surveyResultList = viewViewSurveyRepository.GetViewSurveyResults(userId, teamId);
            }
            else
            {
                surveyResultList = viewViewSurveyRepository.GetViewSurveyResults(userId);
            }
            if (surveyResultList.Count() > 0)
            {
                foreach (var question in vmSurveyList)
                {
                    foreach (var answer in question.SurveyDetailList)
                    {
                        answer.Value   = surveyResultList.Where(a => a.UserId == userId && a.QuestionAnswerId == answer.QuestionAnswerId && a.Id == question.Id).First().Value ?? "";
                        answer.Comment = surveyResultList.Where(a => a.UserId == userId && a.QuestionAnswerId == answer.QuestionAnswerId && a.Id == question.Id).First().Comment ?? "";
                    }
                }
            }
            return(vmSurveyList);
        }
示例#2
0
        //public int CreateSurvey(VmSurvey vmSurvey)
        //{
        //    var result = -1;
        //    try
        //    {
        //        var questionRepository = UnitOfWork.GetRepository<ViewSurveyRepository>();

        //        var newSurvey = new Survey
        //        {
        //            Id = vmSurvey.Id,
        //            Name = vmSurvey.Name,
        //            Description = vmSurvey.Description,
        //        };

        //        questionRepository.CreateSurvey(newSurvey);

        //        UnitOfWork.Commit();

        //        result = newSurvey.Id;
        //    }
        //    catch (Exception ex)
        //    {
        //        result = -1;
        //    }

        //    return result;
        //}

        //public bool UpdateSurvey(VmSurvey vmSurvey)
        //{
        //    try
        //    {
        //        var questionRepository = UnitOfWork.GetRepository<ViewSurveyRepository>();

        //        var updateableSurvey = new Survey
        //        {
        //            Id = vmSurvey.Id,
        //            Name = vmSurvey.Name,
        //            Description = vmSurvey.Description,
        //        };

        //        questionRepository.UpdateSurvey(updateableSurvey);

        //        return UnitOfWork.Commit();
        //    }
        //    catch
        //    {
        //        return false;
        //    }

        //}
        public bool UpdateSurvey(string userId, List <VmClientSurveyResult> clientSurveyResult)
        {
            try
            {
                var blPerson = new BLPerson();
                var person   = blPerson.GetPersonByUserId(userId);


                var blTeamMember = new BLTeamMember();

                VmTeamMember teamMember = null;

                var teamId = 0;

                if (person.RoleName.ToLower().Contains("judge") == false)
                {
                    teamMember = blTeamMember.GetTeamMemberByUserId(userId);
                    teamId     = teamMember.TeamId;
                }

                var surveyResultRepository = UnitOfWork.GetRepository <SurveyResultRepository>();

                surveyResultRepository.DeleteSurveyResult(userId, clientSurveyResult.Select(q => q.QuestionId).ToArray());

                var surveyResultDetails = new List <SurveyResultDetail>();

                var surveyResultList = from survey in clientSurveyResult
                                       group new
                {
                    survey.QuestionAnswerId,
                    survey.Value,
                    survey.Comment
                }
                by survey.QuestionId into g
                    select new SurveyResult
                {
                    QuestionId          = g.Key,
                    TeamId              = teamId,
                    UserId              = userId,
                    SurveyResultDetails = (from s in g.ToList()
                                           select new SurveyResultDetail
                    {
                        QuestionAnswerId = s.QuestionAnswerId,
                        Value = s.Value,
                        Comment = s.Comment,
                    }).ToList()
                };

                if (person.RoleName.ToLower().Contains("judge") == false)
                {
                    blTeamMember.UpdateTeamMemberSurvey(userId, true);
                }

                surveyResultRepository.CreateSurveyResult(surveyResultList);

                return(UnitOfWork.Commit());
            }
            catch
            {
                return(false);
            }
        }
示例#3
0
        public IEnumerable <VmTaskBaseGrade> GetStudentGradeReportList(string studentUserId, int teamId = -1)
        {
            var viewTaskTeamRepository = UnitOfWork.GetRepository <ViewTaskTeamRepository>();

            IEnumerable <ViewTaskTeam> taskTeamRepositoryList;

            var          blTeamMember = new BLTeamMember();
            VmTeamMember teamMember   = null;

            if (teamId == -1)
            {
                teamMember = blTeamMember.GetTeamMemberByUserId(studentUserId);
                teamId     = teamMember.TeamId;
            }
            else
            {
                teamMember = blTeamMember.GetTeamMemberByUserAndTeamId(studentUserId, teamId);
            }

            var taskId = teamMember.TaskId.Value;

            var blUserTask = new BLUserTask();

            var judgeUserTaskList = blUserTask.GetUsersByTask(taskId);

            taskTeamRepositoryList = viewTaskTeamRepository.GetTaskTeamByJudgesAndTeam(judgeUserTaskList.ToArray(), teamId).ToList();

            var viewTaskRepository = UnitOfWork.GetRepository <ViewTaskRepository>();

            var taskGradeList = viewTaskRepository.GetViewTaskByIds(new int[] { taskId }).ToList();

            var blTeamGradeDetail   = new BLTeamGradeDetail();
            var teamGradeDetailList = blTeamGradeDetail.GetAllTeamGradeDetailByTaskIds(taskTeamRepositoryList.Select(t => t.TaskId).Distinct().ToArray()).ToList();

            var taskBaseGradeList = (from task in taskTeamRepositoryList
                                     group task by new { task.TaskId, task.TaskName } into g
                                     select new VmTaskBaseGrade
            {
                TaskId = g.Key.TaskId,
                TaskName = g.Key.TaskName,

                GradeList = (from gt in taskGradeList
                             where gt.Id == g.Key.TaskId
                             select new VmGrade
                {
                    Id = gt.GradeId,
                    Name = gt.Grade
                }).ToList(),

                TeamGradeList = (from team in g.ToList()
                                 group team by new { team.TeamId, team.TeamName } into tg
                                 select new VmTeamGrade
                {
                    TeamId = tg.Key.TeamId,
                    TeamName = tg.Key.TeamName,
                }).ToList()
            }).ToList();


            foreach (var taskBaseGrade in taskBaseGradeList)
            {
                foreach (var team in taskBaseGrade.TeamGradeList)
                {
                    team.GradeReportList = new List <VmGradeReport>();

                    foreach (var grade in taskBaseGrade.GradeList)
                    {
                        team.GradeReportList.Add(new VmGradeReport
                        {
                            GradeId   = grade.Id,
                            GradeType = grade.Name,
                            Average   = GetAverageTotal(teamGradeDetailList, taskBaseGrade.TaskId, team.TeamId, grade.Id)
                        });
                    }
                }
            }

            return(taskBaseGradeList);
        }