public CompetitionPostApiModel Map(Mannschaftskampf mannschaftskampf, List <Einzelkampf> einzelkaempfe)
        {
            CompetitionPostApiModel apiModel = new CompetitionPostApiModel
            {
                SaisonId         = mannschaftskampf.SaisonId,
                CompetitionId    = mannschaftskampf.WettkampfId,
                HomePoints       = mannschaftskampf.HeimPunkte.ToString(),
                OpponentPoints   = mannschaftskampf.GastPunkte.ToString(),
                Audience         = mannschaftskampf.AnzahlZuschauer.ToString(),
                EditorComment    = mannschaftskampf.Kommentar,
                RefereeName      = mannschaftskampf.Schiedsrichter_Nachname,
                RefereeGivenname = mannschaftskampf.Schiedsrichter_Vorname,
                StartTime        = mannschaftskampf.EchterKampfbeginn.ToString(@"hh\:mm\:ss"),
                EndTime          = mannschaftskampf.EchtesKampfende.ToString(@"hh\:mm\:ss"),
                BoutList         = MapEinzelkaempfe(einzelkaempfe)
            };

            return(apiModel);
        }
Exemple #2
0
        public async Task <Tuple <Mannschaftskampf, List <Einzelkampf> > > Get_Mannschaftskampf_Async(string saisonId, string wettkampfId)
        {
            MannschaftskampfMapper wettkampfMapper = new MannschaftskampfMapper();

            JObject response = await _rdbService.Get_CompetitionSystem_Async(
                "getCompetition",
                new List <KeyValuePair <string, string> >()
            {
                new KeyValuePair <string, string>("sid", saisonId),
                new KeyValuePair <string, string>("cid", wettkampfId),
            });

            CompetitionApiModel apiModel = response["competition"].ToObject <CompetitionApiModel>();

            JToken[] kaempfeJArray = response["competition"]["_boutList"].ToArray();

            Mannschaftskampf   mannschaftskampf = wettkampfMapper.Map(apiModel);
            List <Einzelkampf> einzelKaempfe    = _einzelkampfMapper.Map(kaempfeJArray);

            return(new Tuple <Mannschaftskampf, List <Einzelkampf> >(mannschaftskampf, einzelKaempfe));
        }
        public async Task Uebermittle_Ergebnis_Async(Mannschaftskampf mannschaftskampf, List <Einzelkampf> einzelkaempfe)
        {
            CompetitionPostApiModel apiModel = _mapper.Map(mannschaftskampf, einzelkaempfe);

            List <ValidationResult> validationResults = new List <ValidationResult>();
            bool isValid = ValidationHelper.IsValidate(apiModel, fehlerListe => validationResults = fehlerListe);

            if (!isValid)
            {
                List <KeyValuePair <string, string> > validierungsFehler = new List <KeyValuePair <string, string> >();
                foreach (var validationResult in validationResults)
                {
                    validierungsFehler.AddRange(validationResult.MemberNames.Select(member =>
                                                                                    new KeyValuePair <string, string>(member, validationResult.ErrorMessage)));
                }

                throw new ApiValidierungException(validierungsFehler);
            }

            //TODO: Impl. finalisieren
            var httpResponse = await _rdbService.Sende_Ergebnis_Async(apiModel : apiModel);
        }
        public MannschaftskampfViewModel Map(Mannschaftskampf model)
        {
            var viewModel = new MannschaftskampfViewModel(model.SaisonId, model.WettkampfId)
            {
                HeimMannschaft          = model.HeimMannschaft,
                GastMannschaft          = model.GastMannschaft,
                HeimPunkte              = model.HeimPunkte,
                GastPunkte              = model.GastPunkte,
                Kampfdatum              = model.Kampfdatum,
                GeplanterKampfbeginn    = model.GeplanterKampfbeginn,
                EchterKampfbeginn       = model.EchterKampfbeginn,
                EchtesKampfende         = model.EchtesKampfende,
                AnzahlZuschauer         = model.AnzahlZuschauer,
                Wettkampfstaette        = model.Wettkampfstaette,
                Schiedsrichter_Vorname  = model.Schiedsrichter_Vorname,
                Schiedsrichter_Nachname = model.Schiedsrichter_Nachname,
                Sieger = model.Sieger,
                IstErgebnisGeprueft = model.IstErgebnisGeprueft,
                Kommentar           = model.Kommentar,
            };

            return(viewModel);
        }
        public Mannschaftskampf Map(CompetitionApiModel apiModel)
        {
            Mannschaftskampf result = new Mannschaftskampf
            {
                SaisonId                = apiModel.SaisonId,
                WettkampfId             = apiModel.CompetitionId,
                HeimMannschaft          = apiModel.HomeTeamName,
                GastMannschaft          = apiModel.OpponentTeamName,
                Wettkampfstaette        = apiModel.Location,
                Kommentar               = apiModel.EditorComment,
                Schiedsrichter_Vorname  = apiModel.RefereeGivenname,
                Schiedsrichter_Nachname = apiModel.RefereeName,
                IstErgebnisGeprueft     = !string.IsNullOrEmpty(apiModel.ControlledAt) && !string.IsNullOrEmpty(apiModel.ControlledBy)
            };

            try
            {
                result.Kampfdatum           = DateTime.Parse(apiModel.BoutDate);
                result.GeplanterKampfbeginn = TimeSpan.Parse(apiModel.ScaleTime);

                result.EchterKampfbeginn = !string.IsNullOrEmpty(apiModel.StartTime) ? TimeSpan.Parse(apiModel.StartTime) : new TimeSpan(0, 0, 0);
                result.EchtesKampfende   = !string.IsNullOrEmpty(apiModel.EndTime) ? TimeSpan.Parse(apiModel.EndTime) : new TimeSpan(0, 0, 0);
                result.AnzahlZuschauer   = !string.IsNullOrEmpty(apiModel.Audience) ? int.Parse(apiModel.Audience) : 0;
            }
            catch (Exception ex)
            {
                throw new ApiMappingException("Wettkampfmapping Kampfdaten-Parsing", ex);
            }

            try
            {
                if (!string.IsNullOrEmpty(apiModel.HomePoints))
                {
                    result.HeimPunkte = int.Parse(apiModel.HomePoints);
                    if (!string.IsNullOrEmpty(apiModel.ValidatedHomePoints))
                    {
                        result.HeimPunkte = int.Parse(apiModel.ValidatedHomePoints);
                    }
                }

                if (!string.IsNullOrEmpty(apiModel.OpponentPoints))
                {
                    result.GastPunkte = int.Parse(apiModel.OpponentPoints);
                    if (!string.IsNullOrEmpty(apiModel.ValidatedOpponentPoints))
                    {
                        result.GastPunkte = int.Parse(apiModel.ValidatedOpponentPoints);
                    }
                }
            }
            catch (Exception ex)
            {
                throw new ApiMappingException("Wettkampfmapping Mannschaftspunkte-Parsing", ex);
            }

            try
            {
                if (!string.IsNullOrEmpty(apiModel.Decision))
                {
                    if (apiModel.Decision.Equals("home", StringComparison.OrdinalIgnoreCase))
                    {
                        result.Sieger = HeimGast.Heim;
                    }
                    else if (apiModel.Decision.Equals("opponent", StringComparison.OrdinalIgnoreCase))
                    {
                        result.Sieger = HeimGast.Gast;
                    }
                    else
                    {
                        result.Sieger = HeimGast.Unbekannt;
                    }
                }
            }
            catch (Exception ex)
            {
                throw new ApiMappingException("Wettkampfmapping Sieger-Parsing", ex);
            }

            return(result);
        }