/// <summary>
        /// Initializes and returns a new <see cref="T:Supportify.Domain.Account"/> 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.Account"/> instance.</param>
        /// <returns>The initialized and tracked <see cref="T:Supportify.Domain.Account"/> instance.</returns>
        public Account CreateAccount(Action<Account> customize)
        {
            var account = new Account();
            customize(account);

            if (string.IsNullOrWhiteSpace(account.Name)) {
                account.Name = "Company " + RandomString();
            }

            _generator.Context.Set<Account>().Add(account);

            return account;
        }
示例#2
0
        // ------------------------------------------------------------------------------
        // Methods
        // ------------------------------------------------------------------------------
        public static Account Create()
        {
            #if DEBUG
            using (MiniProfiler.Current.Step("Account.Create")) {
            #endif
                var account = new Account();

                new EFRepository<Account>()
                    .Add(account);

                return account;
            #if DEBUG
            }
            #endif
        }
        public static void Put(Account entity)
        {
            #if DEBUG
            using (MiniProfiler.Current.Step("AccountCacheManager.Put")) {
            #endif
                if (_manager == null) {
                    return;
                }

                string key = ENTITY_BY_ID_PATTERN.FormatWith(entity.Id);
                _manager.Put<Account>(key, entity, TimeSpan.FromMinutes(5));

                string apiTag = ENTITY_BY_KEY_PATTERN.FormatWith(entity.Key);
                _manager.Put<Account>(apiTag, entity, TimeSpan.FromMinutes(5));
            #if DEBUG
            }
            #endif
        }
        public static void Remove(Account entity)
        {
            #if DEBUG
            using (MiniProfiler.Current.Step("AccountCacheManager.Remove")) {
            #endif
                if (_manager == null) {
                    return;
                }

                string key = ENTITY_BY_ID_PATTERN.FormatWith(entity.Id);
                _manager.Remove<Account>(key);

                string apiTag = ENTITY_BY_KEY_PATTERN.FormatWith(entity.Key);
                _manager.Remove<Account>(apiTag);

                UserCacheManager.RemoveAllByAccountId(entity.Id);
            #if DEBUG
            }
            #endif
        }