Exemple #1
0
        public static void CreateStartingPlayer(StartingPlayerDTO startingPlayerDTO)
        {
            // ballpark instance of Player class in Retrosheet_Persist.Retrosheet
            var startingPlayer = convertToEntity(startingPlayerDTO);

            // entity data model
            //var dbCtx = new retrosheetDB();
            var dbCtx = new retrosheetEntities();

            dbCtx.Starting_Player.Add(startingPlayer);
            try
            {
                dbCtx.SaveChanges();
            }
            catch (DbEntityValidationException dbEx)
            {
                foreach (var validationErrors in dbEx.EntityValidationErrors)
                {
                    foreach (var validationError in validationErrors.ValidationErrors)
                    {
                        Trace.TraceInformation("Property: {0} Error: {1}",
                                               validationError.PropertyName,
                                               validationError.ErrorMessage);
                    }
                }
            }
            catch (Exception e)
            {
                string text;
                text = e.Message;
            }
        }
Exemple #2
0
        private static Starting_Player convertToEntity(StartingPlayerDTO startingPlayerDTO)
        {
            var startingPlayer = new Starting_Player();

            startingPlayer.record_id      = startingPlayerDTO.RecordID;
            startingPlayer.game_id        = startingPlayerDTO.GameID;
            startingPlayer.player_id      = startingPlayerDTO.PlayerID;
            startingPlayer.game_team_code = startingPlayerDTO.GameTeamCode;
            startingPlayer.batting_order  = startingPlayerDTO.BattingOrder;
            startingPlayer.field_position = startingPlayerDTO.FieldPosition;
            startingPlayer.team_id        = startingPlayerDTO.TeamId;

            return(startingPlayer);
        }
Exemple #3
0
        private static void ReadWriteStartingPlayerFile()
        {
            string[] columnValue;
            string   textLine = null;

            using (StreamReader reader = new StreamReader(@"C:\users\mmr\documents\retrosheet\2016 Regular Season\Output\2016SLN\2016SLN_start"))
            {
                while (!reader.EndOfStream)
                {
                    try
                    {
                        textLine = reader.ReadLine();
                    }
                    catch (Exception e)
                    {
                        // Let the user know what went wrong.
                        Console.WriteLine("The " + @"C:\users\mmr\documents\retrosheet\2016 Regular Season\Output\2016SLN\2016SLN_start" + " file could not be read:");
                        Console.WriteLine(e.Message);
                        Console.ReadLine();
                    }

                    columnValue = textLine.Split('|');

                    StartingPlayerDTO startingPlayerDTO = new StartingPlayerDTO();

                    startingPlayerDTO.RecordID      = Guid.NewGuid();
                    startingPlayerDTO.GameID        = columnValue[0];
                    startingPlayerDTO.PlayerID      = columnValue[2];
                    startingPlayerDTO.GameTeamCode  = Convert.ToInt16(columnValue[4]);
                    startingPlayerDTO.BattingOrder  = Convert.ToInt16(columnValue[5]);
                    startingPlayerDTO.FieldPosition = Convert.ToInt16(columnValue[6]);

                    StartingPlayerPersist.CreateStartingPlayer(startingPlayerDTO);

                    Console.WriteLine(textLine);
                }
            }
        }