public ActionResult EditSurvey(int id, string mode = "edit") { SurveyInfo model = _cdeSurveyManager.GetCdeSurveyInfoById(id); if (model == null || model.TenantId != CurrentUser.TenantId) { model = new SurveyInfo(); } _cdeSurveyManager.LoadSendUsers(model); ViewBag.config = _configManager.GetConfig(CurrentTenant.TenantId); ViewBag.mode = string.IsNullOrEmpty(mode) ? "edit" : mode; return(View(model)); }
public ActionResult SurveyReport(int userSurveyId) { Cde_Report report = _reportManager.GetReport(userSurveyId); UserSurvey userSurvey = _surveyManager.GetSurveyInfoByUserSurveyId(userSurveyId); report.Survey = userSurvey.Survey; report.User = _userManager.GetUserById(userSurvey.UserId); report.Survey.Exampaper = _exampaperManager.GetFullExampaper(userSurvey.Survey.ExampaperId); report.SendUsers.AddRange(_userSendSurveyManager.GetSurveySendUsers(userSurveyId)); _surveyManager.LoadSendUsers(report.Survey); Cde_Configuration config = _configManager.GetConfig(CurrentTenant.TenantId); ViewBag.surveyConfig = config; List <Cde_SurveyReplyAnswer> userAnswers = _userSendSurveyManager.GetUsersReplyAnswers(userSurveyId); foreach (Cde_SurveyReplyAnswer answer in userAnswers) { Cde_SurveySendUsers anuser = report.SendUsers.Find(p => p.UserId == answer.UserID); if (anuser != null) { answer.Relationship = anuser.Relationship; } } foreach (Cde_IndexQuestion question in report.Survey.Exampaper.Questions) { IEnumerable <Cde_SurveyReplyAnswer> qans = userAnswers.Where(p => p.QuestionId == question.QuestionId); question.ReplyAnswers.AddRange(qans); IEnumerable <Cde_SurveyReplyAnswer> lans = qans.Where(p => p.Relationship == 0); IEnumerable <Cde_SurveyReplyAnswer> colans = qans.Where(p => p.Relationship == 1); IEnumerable <Cde_SurveyReplyAnswer> subans = qans.Where(p => p.Relationship == 2); IEnumerable <Cde_SurveyReplyAnswer> selfans = qans.Where(p => p.Relationship == 3); double ls = lans.Any() ? lans.Average(p => p.Score) : 0d; double cs = colans.Any() ? colans.Average(p => p.Score) : 0d; double sus = subans.Any() ? subans.Average(p => p.Score) : 0d; double ss = selfans.Any() ? selfans.Average(p => p.Score) : 0d; question.AverageScore = (ls * config.LeaderWeight / 100d + cs * config.ColleagueWeight / 100d + sus * config.SubordinateWeight / 100d + ss * config.SelfWeight / 100d); question.OtherScore = (ls * config.LeaderWeight / 100d + cs * config.ColleagueWeight / 100d + sus * config.SubordinateWeight / 100d) * (1 - config.SelfWeight / 100d); question.SelfScore = ss; } foreach (Cde_ReportIndex index in report.IndexList) { index.OtherScore = (index.LeaderScore * config.LeaderWeight / 100m + index.ColleagueScore * config.ColleagueWeight / 100m + index.SubordinateScore * config.SubordinateWeight / 100m) / (1M - config.SelfWeight / 100m); } return(View(report)); }