public async Task <DomainValidationResult <Promotion> > CreatePromotionAsync( string promotionalCode, Currency currency, TimeSpan duration, DateTime expiredAt ) { var result = new DomainValidationResult <Promotion>(); if (!await _promotionRepository.IsPromotionalCodeAvailableAsync(promotionalCode)) { result.AddFailedPreconditionError("The promotional code isn't available"); } if (result.IsValid) { var promotion = new Promotion( promotionalCode, currency, duration, new DateTimeProvider(expiredAt)); _promotionRepository.Create(promotion); await _promotionRepository.CommitAsync(); return(promotion); } return(result); }