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

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

                var counterAdded      = 0;
                var counterDuplicates = 0;

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

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

                foreach (var t in tournaments)
                {
                    try
                    {
                        var newTournament = modelsFactory.CreateTournament(
                            t.Name,
                            t.StartDate,
                            t.EndDate,
                            t.PrizeMoney,
                            t.Category,
                            t.PlayersCount,
                            t.City,
                            t.Country,
                            t.Surface,
                            t.SurfaceSpeed);

                        this.dataProvider.Tournaments.Add(newTournament);
                        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));
            }
        }
示例#2
0
        public string Execute(IList <string> parameters)
        {
            writer.Clear();

            if (parameters.Count < 9)
            {
                return(this.Execute());
            }
            else
            {
                var name         = parameters[0];
                var surfaceType  = parameters[1];
                var categoryName = parameters[2];
                var cityName     = parameters[3];

                var startDate = parameters[4];
                var endDate   = parameters[5];

                var prizeMoney = parameters[6];

                var playersCount = parameters[7];

                var countryName = parameters[8];

                var surfaceSpeed = dp.Surfaces
                                   .Find(s => s.Type == surfaceType)
                                   .Select(t => t.Speed)
                                   .FirstOrDefault();

                Tournament tournament = factory.CreateTournament(name,
                                                                 startDate,
                                                                 endDate,
                                                                 prizeMoney,
                                                                 categoryName,
                                                                 playersCount,
                                                                 cityName,
                                                                 countryName,
                                                                 surfaceType,
                                                                 surfaceSpeed);
                if (tournament != null)
                {
                    dp.Tournaments.Add(tournament);
                    dp.UnitOfWork.Finished();
                    return($"Tournament {name} created successfully!");
                }
                else
                {
                    throw new ArgumentNullException("Tournament cannot be null!");
                }
            }
        }