public List <AwardObject> GetAllAwards(string token) { List <AwardObject> awardCompetitions = new List <AwardObject>(); bool notValid = context.Users.Where(x => x.Token == token).FirstOrDefault() == null; if (notValid) { return(awardCompetitions); } var competitionsUserPartakesIn = from UserCompetitionTotalScore in context.UserCompetitionTotalScores where (UserCompetitionTotalScore.User.Token == token) select new { UserCompetitionTotalScore.Competition, UserCompetitionTotalScore.Average, UserCompetitionTotalScore.Total }; foreach (var comp in context.Competitions) { if (competitionsUserPartakesIn.Where(x => x.Competition.Id == comp.Id).Count() != 0) { AwardObject awardObject = new AwardObject { CompetitionName = comp.Name, IsCompetitionLocked = false, Total = GetTotalScore(token, comp.Name), //REMOVE Accuracy = (int)competitionsUserPartakesIn .Where(x => x.Competition.Id == comp.Id).First().Average, TotalAward = CheckAward.Total(competitionsUserPartakesIn .Where(x => x.Competition.Id == comp.Id).First().Total, false, comp.Name, context), AccuracyAward = CheckAward.Accuracy(((int)competitionsUserPartakesIn .Where(x => x.Competition.Id == comp.Id).First().Average), false, comp.Name, context), BestInMonth = CheckAward.MonthBest(comp.Id, token, context) }; awardCompetitions.Add(awardObject); } else { AwardObject awardObject = new AwardObject { CompetitionName = comp.Name, IsCompetitionLocked = true, Total = "0", Accuracy = 0, TotalAward = CheckAward.Total(0, true, comp.Name, context), AccuracyAward = CheckAward.Accuracy(0, true, comp.Name, context), BestInMonth = "No Award" }; awardCompetitions.Add(awardObject); } } return(awardCompetitions); }
public IActionResult ScoreCapture([FromBody] ScoreCapture scoreCapture) { if (ModelState.IsValid) { var competition = _context.Competitions.Where(x => x.Name == scoreCapture.CompetitionName).FirstOrDefault <Competition>(); if (competition == null) { return(new NotFoundObjectResult("Competition not found")); } var user = _context.Users.Where(x => x.Token == scoreCapture.Token).FirstOrDefault <User>(); if (user == null) { return(new NotFoundObjectResult("User not found")); } var score = new Score() { UserScore = scoreCapture.UserScore, PictureURL = scoreCapture.PictureURL, Competition = competition, User = user, Latitude = scoreCapture.Latitude, Longitude = scoreCapture.Longitude, UploadDate = DateTime.Now }; _context.Scores.Add(score); _context.SaveChanges(); //update time spent at skietbaan CheckAward.UpdateHoursSpent(_context, score); //update User Competition Stats Calculations calculations = new Calculations(_context); calculations.performCalculations(user.Id, competition.Id); return(Ok("Score Added Successfully")); } else { return(new BadRequestObjectResult("score cannot be null")); } }
public HoursAward GetHours(string token) { return(CheckAward.Hours(token, context)); }