public Task Execute(string name, DateTime birthdate) { var modelState = new Notification(); if (!(name?.Length > 0)) { modelState.Add(nameof(name), "Name has length smaller than 0"); } else if (!name.Contains(' ')) { modelState.Add(nameof(name), "Name has a bad format"); } var now = DateTime.UtcNow; if (birthdate > now.AddYears(-18)) { modelState.Add(nameof(birthdate), "Minor is not allowed"); } if (birthdate < now.AddYears(-150)) { modelState.Add(nameof(birthdate), "Immortals not allowed"); } if (modelState.IsValid) { return(_useCase.Execute(name, birthdate)); } _outputPort?.Invalid(modelState); return(Task.CompletedTask); }
public Task ExecuteAsync(Guid accountId, decimal amount, string currency) { var modelState = new ApplicationResult(); if (accountId == Guid.Empty) { modelState.Add(nameof(accountId), "AccountId is required."); } if (currency != Currency.Dollar.Code && currency != Currency.Euro.Code && currency != Currency.Real.Code && currency != Currency.MexicanPeso.Code) { modelState.Add(nameof(currency), $"Currency {currency} is invalid."); } if (amount <= 0) { modelState.Add(nameof(amount), "Amount should be positive and greather than zero."); } if (modelState.IsValid) { return(_useCase.ExecuteAsync(accountId, amount, currency)); } _outputPort?.Invalid(modelState); return(Task.CompletedTask); }
public async Task ExecuteAsync(string userName, string password) { var result = await _userService.SignInAsync(userName, password); if (result.IsT1) { _notification.Add("Detail", "User name or password are invalid"); _outputPort.Invalid(); return; } var user = await _userRepository.GetAsync(userName); var(token, expiresIn) = _userService.CreateToken(user); _outputPort.Ok(new(token, expiresIn)); }
public Task ExecuteAsync(Guid accountId) { var modelState = new ApplicationResult(); if (accountId == Guid.Empty) { modelState.Add(nameof(accountId), "AccountId is required."); } if (modelState.IsValid) { return(_useCase.ExecuteAsync(accountId)); } _outputPort?.Invalid(modelState); return(Task.CompletedTask); }