public string Execute(IList <string> parameters)
        {
            if (parameters.Count == 0)
            {
                return(this.Execute());
            }
            else
            {
                var players = excelImporter.ImportPlayers(parameters[0]);

                writer.WriteLine("Total records in dataset: " + players.Count);

                var counterAdded      = 0;
                var counterDuplicates = 0;

                writer.Write("Importing players' data...");

                var newLog = logger.CreateNewLog("Players import: ");

                foreach (var p in players)
                {
                    try
                    {
                        var newPlayer = modelsFactory.CreatePlayer(
                            p.FirstName,
                            p.LastName,
                            p.Ranking,
                            p.Birthdate,
                            p.Height,
                            p.Weight,
                            p.City,
                            p.Country);

                        this.dataProvider.Players.Add(newPlayer);
                        counterAdded++;
                    }
                    catch (ArgumentException ex)
                    {
                        var logDetail = logger.CreateNewLogDetail(
                            "Excel import problem: " + ex.Message,
                            newLog);

                        counterDuplicates++;
                    }
                }

                this.dataProvider.UnitOfWork.Finished();
                writer.Write(Environment.NewLine);

                newLog.TimeStamp = DateTime.Now;
                newLog.Message   = newLog.Message + String.Format("Records added: {0}, Duplicated records: {1}", counterAdded, counterDuplicates);
                logger.Log(newLog);
                return(String.Format("Records added: {0}{1}Duplicated records: {2}", counterAdded, Environment.NewLine, counterDuplicates));
            }
        }
Example #2
0
        public string Execute(IList <string> parameters)
        {
            writer.Clear();

            if (parameters.Count < 2)
            {
                return(this.Execute());
            }
            else
            {
                string firstName = string.Empty;
                string lastName  = string.Empty;
                string weight    = string.Empty;
                string height    = string.Empty;
                string birthDate = string.Empty;
                string rank      = string.Empty;
                string city      = string.Empty;
                string country   = string.Empty;

                firstName = parameters[0];
                lastName  = parameters[1];

                if (parameters.Count > 2)
                {
                    weight = parameters[2];
                }

                if (parameters.Count > 3)
                {
                    height = parameters[3];
                }

                if (parameters.Count > 4)
                {
                    birthDate = parameters[4];
                }

                if (parameters.Count > 5)
                {
                    rank = parameters[5];
                }

                if (parameters.Count > 6)
                {
                    city = parameters[6];
                }

                if (parameters.Count > 7)
                {
                    country = parameters[7];
                }

                var player = factory.CreatePlayer(firstName, lastName, rank, birthDate, height, weight, city, country);
                if (player != null)
                {
                    dp.Players.Add(player);
                    dp.UnitOfWork.Finished();
                    return($"PLayer {firstName} {lastName} created successfully!");
                }
                else
                {
                    throw new ArgumentNullException("Player cannot be null!");
                }
            }
        }