private static FilterDefinition <PersonCategoryCounter> CreateFilterFromCategory(
     PersonCategoryCounter personCategoryCounter, FilterDefinition <PersonCategoryCounter> filter)
 {
     filter = AddEqFilter(x => x.Race, personCategoryCounter.Race, filter);
     filter = AddEqFilter(x => x.Sex, personCategoryCounter.Sex, filter);
     filter = AddEqFilter(x => x.SchoolLevel, personCategoryCounter.SchoolLevel, filter);
     return(filter);
 }
        private async Task <string> GetExistintIdAsync(PersonCategoryCounter personCategoryCounter)
        {
            var collection = MongoConnection.GetPersonCategoriesCollection();
            var filter     = Builders <PersonCategoryCounter> .Filter.Empty;

            filter = CreateFilterFromCategory(personCategoryCounter, filter);
            var result = await collection.FindAsync(filter);

            return(result.FirstOrDefault()?.Id ?? GuidGenerator.GenerateGuid());
        }
        public async Task Save(ITransaction transaction, PersonCategoryCounter personCategoryCounter)
        {
            var session    = ((MongoSession)transaction).Session;
            var collection = MongoConnection.GetPersonCategoriesCollection();
            var filter     = Builders <PersonCategoryCounter> .Filter.Empty;

            personCategoryCounter.Id = await GetExistintIdAsync(personCategoryCounter);

            await collection.ReplaceOneAsync(
                filter : CreateFilterFromCategory(personCategoryCounter, filter),
                options : new ReplaceOptions {
                IsUpsert = true
            },
                replacement : personCategoryCounter,
                session : session);
        }
Пример #4
0
 protected static void IncrementCategoryCounters(PersonCategoryFilter filter,
                                                 PersonCategoryCounter personCategory)
 {
     personCategory.Count++;
     IncrementNameCounters(filter, personCategory.PersonNameCounters);
 }
Пример #5
0
 protected static void DecrementCategoryCounters(PersonCategoryFilter filter,
                                                 PersonCategoryCounter personCategory)
 {
     personCategory.Count = Math.Max(personCategory.Count - 1, 0);
     DecrementNameCounters(filter, personCategory.PersonNameCounters);
 }