Exemplo n.º 1
0
        // ------------------------------------------------------------------------------
        // Methods
        // ------------------------------------------------------------------------------
        public static User Create(long accountId, string email, string name, string password)
        {
            #if DEBUG
            using (MiniProfiler.Current.Step("User.Create")) {
            #endif
                var user = new User {
                    AccountId = accountId,
                    Email = (email ?? "").Trim().ToLower(),
                    Name = (name ?? "").Trim()
                };
                user.SetPassword(password);

                new EFRepository<User>()
                    .Add(user);

                return user;
            #if DEBUG
            }
            #endif
        }
        public static void Remove(User entity)
        {
            #if DEBUG
            using (MiniProfiler.Current.Step("UserCacheManager.Remove")) {
            #endif
                if (_manager == null) {
                    return;
                }

                string key = ENTITY_BY_ID_PATTERN.FormatWith(entity.Id);
                _manager.Remove<User>(key);
            #if DEBUG
            }
            #endif
        }
        public static void Put(User entity)
        {
            #if DEBUG
            using (MiniProfiler.Current.Step("UserCacheManager.Put")) {
            #endif
                if (_manager == null) {
                    return;
                }

                // Store the primary key as referenced by the ID.
                string key = ENTITY_BY_ID_PATTERN.FormatWith(entity.Id);

                _manager.Put<User>(key, entity, TimeSpan.FromMinutes(5));
            #if DEBUG
            }
            #endif
        }
        /// <summary>
        /// Initializes and returns a new <see cref="T:Supportify.Domain.User"/> instance and adds it to the current EntityFramework <see cref="T:System.Data.Objects.ObjectContext"/>.
        /// </summary>
        /// <param name="customize">Custom actions that will be executed for modifying the <see cref="T:Supportify.Domain.User"/> instance.</param>
        /// <returns>The initialized and tracked <see cref="T:Supportify.Domain.User"/> instance.</returns>
        public User CreateUser(Action<User> customize)
        {
            var user = new User();
            customize(user);

            if (user.WithAccount == null) {
                user.WithAccount = CreateAccount();
            }
            if (string.IsNullOrWhiteSpace(user.Name)) {
                user.Name = "User " + RandomString();
            }
            if (string.IsNullOrWhiteSpace(user.Email)) {
                user.Email = "name" + RandomString() + "@company.com";
            }
            user.Email = user.Email.ToLower();
            if (string.IsNullOrWhiteSpace(user.PasswordValue)) {
                user.SetPassword(GetSumIpsum(8, 16));
            }

            _generator.Context.Set<User>().Add(user);

            return user;
        }