Exemple #1
0
        /// <summary>
        /// Asynchronously save repositories to permanent storage.
        /// </summary>
        /// <returns>Task with total number of elements persisted.</returns>
        public async Task <int> CommitAsync()
        {
            //First, remove all existing elements from storage
            _persistor.Reset();

            var brokerIds = await BrokerRepo.GetAllAsync().Select(b => b.Id).ToListAsync();

            var saleIds = await SaleRepo.GetAllAsync().Select(b => b.Id).ToListAsync();

            var policyIds = await PolicyRepo.GetAllAsync().Select(b => b.Id).ToListAsync();

            //Ids of entities to be stored
            var storage = new SummaryStorage()
            {
                BrokerIds = brokerIds,
                SaleIds   = saleIds,
                PolicyIds = policyIds
            };

            _persistor.PersistObject("SUMMARY", storage);

            //Save all brokers
            await BrokerRepo.GetAllAsync().ForEachAsync(b => _persistor.PersistObject(IBrokerRepository.StoragePrefix + b.Id, b));

            //Save all sales
            await SaleRepo.GetAllAsync().ForEachAsync(s => _persistor.PersistObject(ISaleRepository.StoragePrefix + s.Id, s));

            //Save all policies
            await PolicyRepo.GetAllAsync().ForEachAsync(p => _persistor.PersistObject(IPolicyRepository.StoragePrefix + p.Id, p));

            return(1 + brokerIds.Count + saleIds.Count); //total number of stored elements
        }
Exemple #2
0
        /// <summary>
        /// Retrieves the broker object having identifier <paramref name="Id"/> from the database.
        /// </summary>
        /// <param name="Id">The identifier of the broker.</param>
        /// <returns>The semi-populated broker entity if exists, or null.</returns>
        /// <remarks>The object based attributes of the entity that are persisted as XML are not populated by default. In order to fully populate the entity, call the <see cref="Materialize"/> method.</remarks>
        public Broker GetBroker(Int64 Id)
        {
            Broker b = BrokerRepo.Get(Id);

            return(b);
        }
Exemple #3
0
 public IEnumerable <Broker> GetBroker()
 {
     return(BrokerRepo.Get());
 }