public async Task <IActionResult> MarkDetails(string id) { var target = await _context.Users.SingleOrDefaultAsync(t => t.Id == id); var _model = new MarkDetailsViewModel { Target = target }; var result = target.MyPoints(_context, _model); foreach (var proj in _context.Project.ToList()) { var _tempList = _context .ProjectRecord .Where(t => t.ProjectId == proj.ProjectId && t.DoneUserId == target.Id && t.Keyboarded == false); double Sum = 0; if (_tempList.Count() != 0) { Sum = _tempList.Average(t => t.Point); } _model.ProjectMark.Add(new ProjectMark { MarkValue = Sum, Project = proj }); } _model.Result = result; return(View(_model));; }
//求我的得分 public PointResult MyPoints(ApplicationDbContext DbContext, MarkDetailsViewModel Detail = null) { var AllRecords = DbContext.ProjectRecord .Include(t => t.Project) .Include(t => t.WorkUser) .Include(t => t.WorkUser.UserType) .Where(t => t.DoneUserId == this.Id) .ToList(); var AllProjectsCount = DbContext.Project.Count(); int UserCount = 0; double Sum = 0; double Pons = 0; foreach (var Type in DbContext.UserType) { //只有领导打分的平均分 double TypeAverage = MarkTypePoint(Type, AllRecords, AllProjectsCount, ref UserCount); //如果确实有领导打过分 if (TypeAverage != 0) { //给领导加权计入总和 Sum += TypeAverage * Type.Arg; //总权重增加次类型 Pons += Type.Arg; } if (Detail != null) { Detail.TypeMark.Add(new TypeMark { Type = Type, MarkValue = TypeAverage }); } } //最终得分为带权各类人打分分数和 / 权重和 return(new PointResult { Sum = Sum, FinalResult = Pons == 0 ? 0 : Sum / Pons, DoneUserCount = UserCount, }); }