コード例 #1
0
    public void Handle(Serie4Registered e, string aggregateId)
    {
        Roster        roster        = DocumentSession.Load <Roster>(e.RosterId);
        string        id            = SeasonResults.GetId(roster.Season);
        SeasonResults seasonResults = DocumentSession.Load <SeasonResults>(id);

        seasonResults.Add(roster.BitsMatchId, roster.Id !, roster.Date, roster.Turn, e.MatchSerie);
    }
コード例 #2
0
    public void Handle(MatchResult4Registered e, string aggregateId)
    {
        Roster        roster        = DocumentSession.Load <Roster>(e.RosterId);
        string        id            = SeasonResults.GetId(roster.Season);
        SeasonResults seasonResults = DocumentSession.Load <SeasonResults>(id);

        if (seasonResults == null)
        {
            seasonResults = new SeasonResults(roster.Season);
            DocumentSession.Store(seasonResults);
        }

        seasonResults.RemoveWhere(e.BitsMatchId, e.RosterId);
    }
コード例 #3
0
    public ActionResult GeneratePdf(PostModel postModel)
    {
        // find out current season
        int           season        = CompositionRoot.DocumentSession.LatestSeasonOrDefault(SystemTime.UtcNow.Year);
        SeasonResults seasonResults = CompositionRoot.DocumentSession.Load <SeasonResults>(SeasonResults.GetId(season));

        if (seasonResults == null)
        {
            ModelState.AddModelError("resultat", "Det finns inga resultat för säsongen.");
        }

        if (ModelState.IsValid == false)
        {
            return(RedirectToAction("EliteMedals", "MatchResult"));
        }

        EliteMedals eliteMedals = CompositionRoot.DocumentSession.Load <EliteMedals>(EliteMedals.TheId);
        Dictionary <string, Player> playersDict = CompositionRoot.DocumentSession.Query <Player, PlayerSearch>()
                                                  .Where(p => p.PlayerStatus == Player.Status.Active)
                                                  .ToDictionary(x => x.Id);
        EliteMedalsViewModel viewModel = new(season, playersDict, eliteMedals, seasonResults !);

        string       templateFilename = ConfigurationManager.AppSettings["ElitemedalsTemplateFilename"];
        MemoryStream stream           = new();
        string       archiveFileName  = $"Elitmedaljer_{CompositionRoot.CurrentTenant.TeamFullName}_{season}-{season + 1}.zip";

        using (ZipArchive zip = new(stream, ZipArchiveMode.Create, true))
        {
            EliteMedalsViewModel.PlayerInfo[] playersThatHaveMedalsToAchieve =
                viewModel.Players
                .Where(x => x.ExistingMedal != EliteMedals.EliteMedal.EliteMedalValue.Gold5)
                .OrderBy(x => x.Name)
                .ToArray();
            List <string> listOfMissingPersonalNumbers = new();
            foreach (EliteMedalsViewModel.PlayerInfo player in playersThatHaveMedalsToAchieve)
            {
                PlayerMedalInfo playerMedalInfo = new(
                    player.Name,
                    player.PersonalNumber,
                    player.FormattedExistingMedal(),
                    player.FormattedNextMedal(),
                    player.TopThreeResults);
                CreateFileEntryResult result = CreateFileEntry(
                    zip,
                    templateFilename,
                    playerMedalInfo,
                    CompositionRoot.CurrentTenant,
                    postModel);
                if (result == CreateFileEntryResult.MissingPersonalNumber)
                {
                    listOfMissingPersonalNumbers.Add(player.Name);
                }
            }

            if (listOfMissingPersonalNumbers.Any())
            {
                foreach (string playerName in listOfMissingPersonalNumbers)
                {
                    ModelState.AddModelError(playerName, $"{playerName} saknar personnummer i fliken Medlemmar.");
                }

                return(RedirectToAction("EliteMedals", "MatchResult"));
            }
        }

        _ = stream.Seek(0, SeekOrigin.Begin);
        return(File(stream, "application/zip", archiveFileName));
    }
コード例 #4
0
    public ActionResult EliteMedals(int?season)
    {
        if (season.HasValue == false)
        {
            season = CompositionRoot.DocumentSession.LatestSeasonOrDefault(SystemTime.UtcNow.Year);
        }

        Dictionary <string, Player> playersDict = CompositionRoot.DocumentSession.Query <Player, PlayerSearch>()
                                                  .Where(p => p.PlayerStatus == Player.Status.Active)
                                                  .ToDictionary(x => x.Id);
        EliteMedals eliteMedals = CompositionRoot.DocumentSession.Load <EliteMedals>(Domain.EliteMedals.TheId);

        if (eliteMedals == null)
        {
            eliteMedals = new EliteMedals();
            CompositionRoot.DocumentSession.Store(eliteMedals);
        }

        SeasonResults seasonResults = CompositionRoot.DocumentSession.Load <SeasonResults>(SeasonResults.GetId(season.Value));

        if (seasonResults == null)
        {
            seasonResults = new SeasonResults(season.Value);
            CompositionRoot.DocumentSession.Store(seasonResults);
        }

        EliteMedalsViewModel viewModel = new(season.Value, playersDict, eliteMedals, seasonResults);

        return(View(viewModel));
    }