<commit_before>﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Data.Entity;
using System.Net.Http;
using System.Threading.Tasks;
using WestBlueGolfLeagueWeb.Models.Entities;
using WestBlueGolfLeagueWeb.Models.Responses;
using WestBlueGolfLeagueWeb.Models.Responses.Admin;
using WestBlueGolfLeagueWeb.Models.Admin;
using WestBlueGolfLeagueWeb.Models.ScoreEntry;
using System.Net;
using System.Web.Http;


namespace WestBlueGolfLeagueWeb.Controllers.Admin
{
    [Authorize(Roles = AdminRole.Admin.Name + "," + AdminRole.TeamCaptain.Name)]
    public class ScoreEntryController : WestBlueDbApiController
    {
        public ScoreEntryController() : base(true) {  }

        /// <summary>
        /// Get the overall schedule data
        /// </summary>
        /// <returns></returns>
        public async Task<IHttpActionResult> GetScoreEntryData()
        {
            var weeks = (await this.Db.GetWeeksWithMatchUpsForYearAsync(this.CurrentYear)).ToList();

	        var now = DateTimeOffset.UtcNow;

	        var currentWeek = weeks.FirstOrDefault(x => now < new DateTimeOffset(x.date)) ?? weeks.LastOrDefault();

	        Dictionary<int, IEnumerable<player>> lookup =
		        this.Db.GetPlayersWithTeamsForYear(this.CurrentYear, true)
			        .ToLookup(x => x.Item2.id, x => x.Item1)
			        .ToDictionary(x => x.Key, x => (IEnumerable<player>)x);
			
			// TODO: need to carry over dummy team to new year.
	        return Ok(new ScoreEntryDataResponse(currentWeek, weeks, lookup, this.Db.GetTeamsForYear(this.CurrentYear, true)));
        }

        /// <summary>
        /// Get data for a specific week
        /// </summary>
        /// <returns></returns>
        public async Task<IHttpActionResult> GetMatchup(int weekId, int matchupId)
        {
            var matchup = await this.Db.teammatchups
                            .Include(x => x.matches)
                            .Include("matches.results")
                            .Include("matches.results.player")
                            .AsNoTracking()
                            .FirstOrDefaultAsync(x => x.week.id == weekId && x.week.year.value == this.CurrentYear && x.id == matchupId);

            if (matchup == null)
            {<commit_msg>fixing current week for score entry<commit_after>﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Data.Entity;
using System.Net.Http;
using System.Threading.Tasks;
using WestBlueGolfLeagueWeb.Models.Entities;
using WestBlueGolfLeagueWeb.Models.Responses;
using WestBlueGolfLeagueWeb.Models.Responses.Admin;
using WestBlueGolfLeagueWeb.Models.Admin;
using WestBlueGolfLeagueWeb.Models.ScoreEntry;
using System.Net;
using System.Web.Http;


namespace WestBlueGolfLeagueWeb.Controllers.Admin
{
    [Authorize(Roles = AdminRole.Admin.Name + "," + AdminRole.TeamCaptain.Name)]
    public class ScoreEntryController : WestBlueDbApiController
    {
        public ScoreEntryController() : base(true) {  }

        /// <summary>
        /// Get the overall schedule data
        /// </summary>
        /// <returns></returns>
        public async Task<IHttpActionResult> GetScoreEntryData()
        {
            var weeks = (await this.Db.GetWeeksWithMatchUpsForYearAsync(this.CurrentYear)).ToList();

	        var now = DateTimeOffset.UtcNow;

	        var currentWeek = weeks.FirstOrDefault(x => now > new DateTimeOffset(x.date)) ?? weeks.LastOrDefault();

	        Dictionary<int, IEnumerable<player>> lookup =
		        this.Db.GetPlayersWithTeamsForYear(this.CurrentYear, true)
			        .ToLookup(x => x.Item2.id, x => x.Item1)
			        .ToDictionary(x => x.Key, x => (IEnumerable<player>)x);
			
	        return Ok(new ScoreEntryDataResponse(currentWeek, weeks, lookup, this.Db.GetTeamsForYear(this.CurrentYear, true)));
        }

        /// <summary>
        /// Get data for a specific week
        /// </summary>
        /// <returns></returns>
        public async Task<IHttpActionResult> GetMatchup(int weekId, int matchupId)
        {
            var matchup = await this.Db.teammatchups
                            .Include(x => x.matches)
                            .Include("matches.results")
                            .Include("matches.results.player")
                            .AsNoTracking()
                            .FirstOrDefaultAsync(x => x.week.id == weekId && x.week.year.value == this.CurrentYear && x.id == matchupId);

            if (matchup == null)
            {
{'fraction_non_alphanumeric': 0.11515552614162806, 'fraction_numerical': 0.0008824178248400617, 'mean_word_length': 2.4218867924528302, 'pattern_counts': {'":': 0, '<': 30, '<?xml version=': 0, '>': 44, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3232475', 'n_tokens_mistral': 1318, 'n_tokens_neox': 1269, 'n_words': 257}