Example #1
0
        public void AddSport(ISportDto sportDto)
        {
            Guard.WhenArgument(sportDto, "SportDto can not be null").IsNull().Throw();

            var sportToAdd = this.mapper.Map <Sport>(sportDto);

            if (!this.dbContext.Sports.Any(s => s.Name == sportDto.Name && !s.IsDeleted))
            {
                this.dbContext.Sports.Add(sportToAdd);
                this.dbContext.SaveChanges();
            }
            else
            {
                throw new ArgumentException("A sport with the same name already exists!");
            }
        }
        public string Execute(IList <string> parameters)
        {
            Guard.WhenArgument(parameters.Count, "Count of the parameters.").IsNotEqual(1).Throw();

            string name;

            try
            {
                name = parameters[0];
            }
            catch
            {
                throw new ArgumentException("Failed to parse AddSport command parameters.");
            }

            Guard.WhenArgument(name, "Sport name can not be null!").IsNullOrEmpty().Throw();

            ISportDto sport = this.SportscardFactory.CreateSportDto(name);

            sportService.AddSport(sport);

            return($"Sport {name} was added to database.");
        }