Ejemplo n.º 1
0
        public async Task <string> StartNewSeason(UpsertSeasonRequest request)
        {
            var seasons = await _seasonRepository.GetSeasons();

            var existingSeasonOnDate = seasons.SingleOrDefault(x => x.StartDate == request.StartDate);

            if (existingSeasonOnDate != null)
            {
                throw new ArgumentException("Already a season with this date");
            }

            var existingSameName = seasons.SingleOrDefault(x => x.Name == request.Name);

            if (existingSameName != null)
            {
                throw new ArgumentException("Already a season with same name");
            }

            var newSeason = new Season
            {
                StartDate = request.StartDate,
                Name      = request.Name
            };

            await _seasonRepository.CreateNewSeason(newSeason);

            return(newSeason.Name);
        }
        public async Task <IActionResult> StartNewSeason(UpsertSeasonRequest request)
        {
            if (request.StartDate <= DateTime.Today)
            {
                throw new ArgumentException("Date must be in the future");
            }
            var seasonName = await _seasonLogic.StartNewSeason(request);

            return(Ok(seasonName));
        }