I have the following classes:
DataAccessFactory:
public class DataAccessFactory
{
public static IUserAccessLayer User() => new UserAccessLayer(new DataContext());
public static IAuthenticationAccessLayer Authentication() => new AuthenticationAccessLayer(new DataAccess.DataContext());
}
AuthenticationAccessLayer:
public class AuthenticationAccessLayer : IAuthenticationAccessLayer
{
private readonly DataContext context;
public AuthenticationAccessLayer(DataContext context)
{
this.context = context;
}
public async void RegisterAsync(UserRegisterModel model)
{
context.User.Add(new UserModel()
{
EmailAddress = model.Email,
PasswordHash = model.PasswordHash,
PasswordSalt = model.PasswordSalt
});
}
public async Task<bool> EmailExist(string email)
{
var user = await context.User.Where(x => x.EmailAddress.Equals(email)).FirstOrDefaultAsync();
if (user == null)
return false;
else
return true;
}
}
UserStore:
public class UserStore : ViewModelBase
{
public UserStore()
{
}
public UserStore(int userID)
{
this.UserID = userID;
}
#region Authentication
public async Task<bool> AuthenticateAsync(LoginModel model)
{
return await DataAccessFactory.Authentication().LoginAsync(model);
}
public async void RegisterUserAsync(UserRegisterModel model)
{
var store = DataAccessFactory.Authentication();
//check if unique email
if(await store.EmailExist(model.Email))
throw new ValidationException($"Email {model.Email} is already registered.");
store.RegisterAsync(model);
}
#endregion
}
My question is, in the UserStore, in the RegisterUserAsync
function, will the UserRegisterModel
get added to the DB before the EmailExist
function returns or throw an exception?
AuthenticationAccessLayer.RegisterAsync
is not actuallyasync
. Thecontext.User.Add
is not returned, nor is itTask
returning...