public ActionResult ScoreStats() { try { List <ScoreBLL> Scores; List <ScoreStats> Model; using (ContextBLL ctx = new ContextBLL()) { UserBLL ThisUser = ctx.FindUserByUserName(User.Identity.Name); { if (null == ThisUser) { ViewBag.Exception = new Exception($"Count not find scores for {User.Identity.Name}"); return(View("Error")); } int TotalCount = ctx.ObtainUserScoreCount(ThisUser.UserID); Scores = ctx.GetScoresReltatedToUserID(ThisUser.UserID, 0, TotalCount); } MeaningfulCalculation mc = new MeaningfulCalculation(); Model = mc.CalculateStats(Scores); } return(View("ScoreStats", Model)); } catch (Exception ex) { ViewBag.Exception = ex; return(View("Error")); } }
public void When_ScoreIsNull_Expect_AverageToBeZero() { //arrange MeaningfulCalculation mc = new MeaningfulCalculation(); double expected = 0; //act double actual = mc.CalculateUserAverage(null); //assert Assert.AreEqual(expected, actual); }
public void When_ScoreIsNonNull_Expect_AverageToBeZero() { //arrange MeaningfulCalculation mc = new MeaningfulCalculation(); List <ScoreBLL> Scores = MakeSampleScores(25); double expected = 0; //act double actual = mc.CalculateUserAverage(Scores); //assert Assert.AreNotEqual(expected, actual); }
public void When_NoScores_Expect_AverageToBeZero() { //arrange MeaningfulCalculation mc = new MeaningfulCalculation(); var Scores = MakeSampleScores(0); double expected = 0; //act double actual = mc.CalculateUserAverage(Scores); //assert Assert.AreEqual(expected, actual); }
//returns a stat model for absent charts for practice with averages for benchmarks for attendance //each chart uses the color randomizer for cool color changing properties public StatsModel AbsentChart() { //List of Jpeg Charts to Display StatsModel stats = new StatsModel(); //Attendance pie chart var user = Session["Users"] as Users; List <Users> users = usersBLL.GetUsers().FindAll(m => m.TeamID == user.TeamID && m.RoleID != (int)Role.Coach); List <CountAttendance> count = new List <CountAttendance>(); //store each players practice attendance ratios in a list for each player on the team foreach (Users player in users) { CountAttendance checkAttendance = MeaningfulCalculation.GetPracticeAttendanceUser(player.TeamID, player.UserID); count.Add(checkAttendance); } //get x and y values in array ArrayList xValue = new ArrayList(); int[] yValue = new int[count.Count]; int[] absent = new int[count.Count]; int[] average = new int[count.Count]; int[] absentAverage = new int[count.Count]; int x = 0; foreach (CountAttendance attendance in count) { xValue.Add(attendance.FullName.ToString()); yValue[x] = attendance.NumPresent; absent[x] = attendance.NumAbsent; x++; } // place the names number present absent and the averages for line graphs stats.xValue = xValue; stats.Present = yValue; for (x = 0; x < stats.xValue.Count; x++) { average[x] = yValue.Sum() / yValue.Count(); absentAverage[x] = absent.Sum() / absent.Count(); } stats.Average = average; stats.Absent = absent; stats.AverageAbsent = absentAverage; //store in Session return(stats); }
public ActionResult ScoreStats() { try { List <ScoreBLL> Scores; List <ScoreStats> Model; using (ContextBLL ctx = new ContextBLL()) { int TotalCount = ctx.ObtainScoreCount(); Scores = ctx.GetScores(0, TotalCount); MeaningfulCalculation mc = new MeaningfulCalculation(); Model = mc.CalculateStats(Scores); } return(View("ScoreStats", Model)); } catch (Exception ex) { ViewBag.Exception = ex; return(View("Error")); } }
public ActionResult Login(LoginUser loginUser) { if (ModelState.IsValid) { //Call mapper object to mapp items to the database UserMapper userMapper = new UserMapper(); Users login = userMapper.LoginBLLMapper(loginUser); //call BLL layer Users loginUsers = userBLL.GetUsersByUserName(login.UserName); //display login successful or failed due to input error //if (loginUsers.Password is null) //BUG: Database connectivity has been an issue here is a patch for users not edited by admin //{ // Session["Users"] = loginUsers; // return Redirect("~/User/NewUserHome"); //} if (loginUsers.Password != loginUser.Password) { ViewBag.Message = "Invalid UserName and/or Password"; return(View(loginUser)); } //Call roles BLL Roles role = rolesBLL.GetRoles().Find(m => m.RoleID == loginUsers.RoleID); if (role.RoleType != null) { //DO NOT REMOVE Session["Roles"] = role.RoleType; } else { Session["Roles"] = Roles.Null.RoleType; } Session["UserName"] = loginUsers.UserName; //DO NOT REMOVE Session["Users"] = loginUsers; if (loginUsers.RoleID != Roles.Null.RoleID) { MeaningfulCalculation calculations = new MeaningfulCalculation(attend, userBLL, team, contractsBLL, practiceBLL, gameBLL); Session["Dash"] = calculations.ReturnDashBoard(loginUsers); } //display login successful or failed if (loginUsers.RoleID == Users.Null.UserID) { return(Redirect("~/User/NewUserHome")); } else if (role.RoleType == "Admin") { return(Redirect("~/Home/DashboardAdmin")); } else if (role.RoleType == "Player") { return(Redirect("~/Home/DashBoardPlayer")); } } else { ViewBag.Message = "Login Failed!"; return(View()); } return(Redirect("~/Home/DashboardCoach")); }