예제 #1
0
        private static void CreateUser(UserInfo userInfo, IUsersDal usersDal, Action <Guid> writer, SubscriptionType subscriptionType = SubscriptionType.Promotional)
        {
            try
            {
                // In manual creation context the user email isn't confirmed
                bool isEmailConfirmed = false;
                User user             = usersDal.CreateOrGetUserByEmail(userInfo.UserEmail, isEmailConfirmed, userInfo.Source);
                if (!string.IsNullOrEmpty(userInfo.UserLocation))
                {
                    usersDal.CreateOrUpdateEmailSubscription(new EmailSubscription {
                        IsActive = true, LocationId = userInfo.UserLocation, UserId = user.Id, SubscriptionType = subscriptionType
                    });
                }

                if (userInfo.UserPreferences.Any())
                {
                    usersDal.UpdateUserInfo(user.Id, new Users.Dal.DataModel.UserInfo {
                        Preferences = new UserPreferences {
                            Categories = userInfo.UserPreferences
                        }
                    });
                }
                writer(user.Id);
                Log.Info("User Created. Email={0}, Id={1}, Location={2}, User Email Source {3}, Preferences Count={4}", userInfo.UserEmail, user.Id, userInfo.UserLocation, userInfo.Source, userInfo.UserPreferences.Count);
            }
            catch (Exception exception)
            {
                if (exception.InnerException.Message == "Cant update a suppressed user")
                {
                    Trace.WriteLine(string.Format("Cannot create user {0} - Suppressed user", userInfo.UserEmail));
                }
            }
        }