Exemplo n.º 1
0
        public void CreateTournament(string name, string place, DateTime startDate, DateTime endDate, Guid countryId)
        {
            // TODO: Refactor this method if I can

            Guard.WhenArgument(name, nameof(name)).IsNullOrEmpty().Throw();
            Guard.WhenArgument(place, nameof(place)).IsNullOrEmpty().Throw();
            Guard.WhenArgument(startDate, nameof(startDate)).IsLessThan(DateTime.Now).Throw();
            Guard.WhenArgument(endDate, nameof(endDate)).IsLessThan(startDate).Throw();

            var divisionTypes = this.divisionTypeService.GetAllDivisionTypes().ToList();

            if (divisionTypes.Count == 0)
            {
                throw new NullReferenceException("No division types were found!");
            }

            var tournament = new Tournament
            {
                Name      = name,
                Place     = place,
                StartDate = startDate,
                EndDate   = endDate,
                CountryId = countryId
            };

            foreach (var dt in divisionTypes)
            {
                Division division = new Division
                {
                    DivisionTypeId = dt.Id,
                    Tournament     = tournament
                };

                this.dbContext.Divisions.Add(division);
            }

            dbContext.SaveChanges();
        }