The code should run granted that the models exists. Though it feels as if I did someones homework because there was some syntax errors and models were missing (on purpose?).
public async Task<bool> CreateUser(User userInput) { var validUserTypes = new string[] {"regular", "premium", "trial"} ; var user = userInput.UserType switch { "regular" => new User(userInput.Username), "premium" => new User(userInput.Username, new List<Permission> { "PremiumFeature.Read", "PremiumFeature.Create", }){IsPremium = true}, "trial" => new User(input.Username) { IsOnTrial = true }, _ => new ArgumentOutOfRangeException( "Invalid user type. Must be on of the following {string.Join(" ")" nameof(input.usertype)) }; return await repository.CreateAsync(user); }
public async Task<bool> CreateUser(User Input) {var ValidUserTypes = New[] {"regular", "premium", "trial"} ;- public async Task<bool> CreateUser(User userInput) {
- var validUserTypes = new string[] {"regular", "premium", "trial"} ;
User user;switch (input.UserType) {case "regular":user = new User(input.Username);break;case "premium":user = new User(input.Username, new List<Permission> {"PremiumFeature.Read","PremiumFeature.Create",}) {IsPremium = true,};break;case "trial":user = new User(input.Username) {IsOnTrial = true};break;default:trhwo new ArgumentOutOfRangeException(- var user = userInput.UserType switch {
- "regular" => new User(userInput.Username),
- "premium" => new User(userInput.Username,
- new List<Permission> {
- "PremiumFeature.Read",
- "PremiumFeature.Create",
- }){IsPremium = true},
- "trial" => new User(input.Username) {
- IsOnTrial = true
- },
- _ => new ArgumentOutOfRangeException(
- "Invalid user type. Must be on of the following {string.Join(" ")"
nameof(input.usertype));}bool result = await repository.CreateAsync(user);return result;- nameof(input.usertype))
- };
- return await repository.CreateAsync(user);
- }