public async Task <IReadOnlyList <FantasyCriticUserWithEmailSettings> > GetAllEmailSettings() { string emailSQL = "select * from tbl_user_emailsettings;"; ILookup <Guid, FantasyCriticUserEmailSettingEntity> userEmailSettings; await using (var connection = new MySqlConnection(_connectionString)) { var emailResult = await connection.QueryAsync <FantasyCriticUserEmailSettingEntity>(emailSQL); userEmailSettings = emailResult.ToLookup(x => x.UserID); } var allUsers = await GetAllUsers(); List <FantasyCriticUserWithEmailSettings> usersWithEmailSettings = new List <FantasyCriticUserWithEmailSettings>(); foreach (var user in allUsers) { var emailSettings = userEmailSettings[user.Id]; if (emailSettings.Any()) { var domainTypes = emailSettings.Select(x => EmailType.FromValue(x.EmailType)).ToList(); usersWithEmailSettings.Add(new FantasyCriticUserWithEmailSettings(user, domainTypes)); } } return(usersWithEmailSettings); }
public async Task <IReadOnlyList <EmailType> > GetEmailSettings(FantasyCriticUser user) { string emailSQL = "select * from tbl_user_emailsettings where UserID = @userID;"; var parameters = new { userID = user.Id }; await using var connection = new MySqlConnection(_connectionString); var emailResult = await connection.QueryAsync <FantasyCriticUserEmailSettingEntity>(emailSQL, parameters); return(emailResult.Select(x => EmailType.FromValue(x.EmailType)).ToList()); }