<commit_before>﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using DailySoccer.Shared.Models;
using DailySoccer.DAC.EF;

namespace DailySoccer.Shared.DAC
{
    public class AccountDataAccess : IAccountDataAccess
    {
        public AccountInformation CreateAccount()
        {
            using (var dctx = new DailySoccer.DAC.EF.DailySoccerModelContainer())
            {
                var SecrectCode = Guid.NewGuid().ToString();
                var newGuest = new AccountInformation()
                {
                    SecrectCode = SecrectCode,
                    CurrentOrderedCoupon = 0,
                    Points = 0,
                    MaximumGuessAmount = 5,
                };

                dctx.Accounts.Add(new Account
                {
                    Points = newGuest.Points,
                    SecrectCode = newGuest.SecrectCode,
                });
                dctx.SaveChanges();

                return newGuest;
            }
        }

        public AccountInformation GetAccountBySecrectCode(string secrectCode)
        {
            var isArgumentValid = !string.IsNullOrEmpty(secrectCode);
            if (!isArgumentValid) return null;

            using (var dctx = new DailySoccer.DAC.EF.DailySoccerModelContainer())
            {
                var selectedAccount = dctx.Accounts
                    .FirstOrDefault(it => it.SecrectCode.Equals(secrectCode, StringComparison.CurrentCultureIgnoreCase));
                if (selectedAccount == null) return null;

                return new AccountInformation
                {
                    MaximumGuessAmount = 5,
                    Points = selectedAccount.Points,
                    SecrectCode = selectedAccount.SecrectCode,
                };
            }
        }

        public IEnumerable<GuessMatchInformation> GetGuessMatchsByAccountSecrectCode(string secrectCode)
        {
            var isArgumentValid = !string.IsNullOrEmpty(secrectCode);
            if (!isArgumentValid) return Enumerable.Empty<GuessMatchInformation>();

            using (var dctx = new DailySoccer.DAC.EF.DailySoccerModelContainer())
            {
                var selectedAccount = dctx.Accounts
                    .Include("GuessMatches")
                    .Where(it => it.SecrectCode.Equals(secrectCode, StringComparison.CurrentCultureIgnoreCase))
                    .FirstOrDefault();
                if (selectedAccount == null) return Enumerable.Empty<GuessMatchInformation>();

                var result = selectedAccount.GuessMatches
                    .Select(it => new GuessMatchInformation
                    {
                        Id = it.Id,
                        AccountSecrectCode = it.Account.SecrectCode,
                        GuessTeamId = it.GuessTeamId,
                        MatchId = it.MatchId,
                        PredictionPoints = it.PredictionPoints
                    }).ToList();

                return result;
            }
        }

        public IEnumerable<LeagueInformation> GetAllLeagues()
        {
            // TODO: GetAllLeagues
            throw new NotImplementedException();
        }

        public void SetFavoriteTeam(SetFavoriteTeamRequest request)
        {
            // TODO: SetFavoriteTeam
            throw new NotImplementedException();
        }
    }
}<commit_msg>Implement Set/Get Favorite team complete.<commit_after>﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using DailySoccer.Shared.Models;
using DailySoccer.DAC.EF;

namespace DailySoccer.Shared.DAC
{
    public class AccountDataAccess : IAccountDataAccess
    {
        public AccountInformation CreateAccount()
        {
            using (var dctx = new DailySoccer.DAC.EF.DailySoccerModelContainer())
            {
                var SecrectCode = Guid.NewGuid().ToString();
                var newGuest = new AccountInformation()
                {
                    SecrectCode = SecrectCode,
                    CurrentOrderedCoupon = 0,
                    Points = 0,
                    MaximumGuessAmount = 5,
                };

                dctx.Accounts.Add(new Account
                {
                    Points = newGuest.Points,
                    SecrectCode = newGuest.SecrectCode,
                });
                dctx.SaveChanges();

                return newGuest;
            }
        }

        public AccountInformation GetAccountBySecrectCode(string secrectCode)
        {
            var isArgumentValid = !string.IsNullOrEmpty(secrectCode);
            if (!isArgumentValid) return null;

            using (var dctx = new DailySoccer.DAC.EF.DailySoccerModelContainer())
            {
                var selectedAccount = dctx.Accounts
                    .FirstOrDefault(it => it.SecrectCode.Equals(secrectCode, StringComparison.CurrentCultureIgnoreCase));
                if (selectedAccount == null) return null;

                return new AccountInformation
                {
                    MaximumGuessAmount = 5,
                    Points = selectedAccount.Points,
                    SecrectCode = selectedAccount.SecrectCode,
                };
            }
        }

        public IEnumerable<GuessMatchInformation> GetGuessMatchsByAccountSecrectCode(string secrectCode)
        {
            var isArgumentValid = !string.IsNullOrEmpty(secrectCode);
            if (!isArgumentValid) return Enumerable.Empty<GuessMatchInformation>();

            using (var dctx = new DailySoccer.DAC.EF.DailySoccerModelContainer())
            {
                var selectedAccount = dctx.Accounts
                    .Include("GuessMatches")
                    .Where(it => it.SecrectCode.Equals(secrectCode, StringComparison.CurrentCultureIgnoreCase))
                    .FirstOrDefault();
                if (selectedAccount == null) return Enumerable.Empty<GuessMatchInformation>();

                var result = selectedAccount.GuessMatches
                    .Select(it => new GuessMatchInformation
                    {
                        Id = it.Id,
                        AccountSecrectCode = it.Account.SecrectCode,
                        GuessTeamId = it.GuessTeamId,
                        MatchId = it.MatchId,
                        PredictionPoints = it.PredictionPoints
                    }).ToList();

                return result;
            }
        }

        public IEnumerable<LeagueInformation> GetAllLeagues()
        {
            using (var dctx = new DailySoccer.DAC.EF.DailySoccerModelContainer())
            {
                var result = dctx.FavoriteTeams
                    .Select(it => new LeagueInformation
                    {
                        TeamId = it.Id,
                        LeagueName = it.LeagueName,
                        TeamName = it.TeamName
                    }).ToList();
                return result;
            }
        }

        public void SetFavoriteTeam(SetFavoriteTeamRequest request)
        {
            using (var dctx = new DailySoccer.DAC.EF.DailySoccerModelContainer())
            {
                var selectedAccount = dctx.Accounts.FirstOrDefault(it => it.SecrectCode.Equals(request.UserId, StringComparison.CurrentCultureIgnoreCase));
                if (selectedAccount == null) return;

                var selectedTeam = dctx.FavoriteTeams.FirstOrDefault(it => it.Id == request.SelectedTeamId);
                if (selectedTeam == null) return;

                selectedAccount.FavoriteTeam = selectedTeam;
                dctx.SaveChanges();
            }
        }
    }
}
{'fraction_non_alphanumeric': 0.07465007776049767, 'fraction_numerical': 0.0010368066355624676, 'mean_word_length': 1.5227198430859759, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 20, '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': '4156182', 'n_tokens_mistral': 1957, 'n_tokens_neox': 1805, 'n_words': 346}