/// <summary> /// Register a user + email combination for recieving marketing emails. Intelligently /// select whether to create new users or update existing user information. /// </summary> /// <param name="name">User's name</param> /// <param name="email">User's email address</param> /// <returns>Marketing user as saved in the database.</returns> public async Task <MarketingUser> RegisterUser(string name, string email) { MarketingUser mu; try { // Check if there is a matching email that is subscribed mu = await _database.GetActiveMarketingUserByEmail(email); // User exists and is subscribed throw new MarketingUserAlreadySubscribedException(); } catch (MarketingUserNotFoundException) { // If not, add to database and mark for recieving marketing emails mu = await _database.CreateMarketingUser(name, email); } // Return the new marketing user. return(mu); }