ibby
ibby
Explore posts from servers
CC#
Created by ibby on 4/30/2024 in #help
SignInAsync Set-Cookie header not working?
No description
6 replies
CC#
Created by ibby on 4/29/2024 in #help
What should the service layer return back to a controller?
Confused about what the service layer should return to the controller, Dtos? Result object? Is this the correct approach?
public async Task<CreateUserResult> CreateUserAsync(string username, string email, string password)
{
...input validation

username = username.ToLower();
email = email.ToLower();

if (_dbContext.Users.Any(x => x.Username.Equals(username)))
{
return; // Return a result object with a bool flag "IsDuplicateUsername"?
}

if (_dbContext.Users.Any(x => x.Email.Equals(email)))
{
return; // Return a result object with a bool flag "IsDuplicateEmail"?
}

var user = new User(username, email, password.ToHash());

await _dbContext.Users.AddAsync(user);

await _dbContext.SaveChangesAsync();

// return result with everything false?
}
public async Task<CreateUserResult> CreateUserAsync(string username, string email, string password)
{
...input validation

username = username.ToLower();
email = email.ToLower();

if (_dbContext.Users.Any(x => x.Username.Equals(username)))
{
return; // Return a result object with a bool flag "IsDuplicateUsername"?
}

if (_dbContext.Users.Any(x => x.Email.Equals(email)))
{
return; // Return a result object with a bool flag "IsDuplicateEmail"?
}

var user = new User(username, email, password.ToHash());

await _dbContext.Users.AddAsync(user);

await _dbContext.SaveChangesAsync();

// return result with everything false?
}
41 replies