Example #1
0
        public async Task UpdateAuthorName()
        {
            insertedAuthor = context.GetCollection <Author>().AsQueryable().ToList().Find(a => a.authorFullName == authorName);
            bookRepo       = serviceProvider.GetService <IRepository <Book, string> >();
            await bookRepo.InsertNewAsync(Book.Create("Test Book", "Test description", (AuthorId)insertedAuthor.Id, authorName));

            Policy
            .Handle <TestException>()
            .WaitAndRetry(5, retryAttempt => TimeSpan.FromSeconds(Math.Pow(2, retryAttempt)))
            .Execute(() =>
            {
                insertedAuthor = context.GetCollection <Author>().AsQueryable().ToList().Find(a => a.authorFullName == authorName);
                if (!insertedAuthor.Books.Any(a => a.Title == new BookTitle("Test Book")))
                {
                    throw new TestException();
                }
            });

            var updatedName = new AuthorFullName("Test", "Author 2");
            await authorRepo.ModifyAsync
                (author => author.UpdateAuthorFullName(updatedName), insertedAuthor.Id);

            insertedAuthor = context.GetCollection <Author>().AsQueryable().ToList().Find(a => a.authorFullName == updatedName);
            Assert.IsTrue(insertedAuthor.Books.Any(a => a.Title == new BookTitle("Test Book")));

            var foundBook = context.GetCollection <Book>().AsQueryable().ToList().Find(a => a.Title == new BookTitle("Test Book"));

            Assert.AreEqual(foundBook.AuthorName, updatedName);
        }
 public CurrencyService(IMongoDbContext context)
 {
     _context        = context;
     _Currency       = _context.GetCollection <Currency>(typeof(Currency).Name);
     _AppUser        = _context.GetCollection <AppUser>(typeof(AppUser).Name);
     _CurrencyUpdate = _context.GetCollection <CurrencyUpdate>(typeof(CurrencyUpdate).Name);
     _Account        = _context.GetCollection <Account>(typeof(Account).Name);
 }
Example #3
0
 public async Task <IEnumerable <ContratoDeEmprestimoModel> > ObterContratosAsync(ObterContratosQuery request,
                                                                                  CancellationToken cancellationToken = default) =>
 _mapper.Map <IEnumerable <ContratoDeEmprestimoModel> >(
     await _context.GetCollection <ContratoDeEmprestimoAggregate>()
     .Aggregate()
     .Skip(request.Skip)
     .Limit(request.Take)
     .ToListAsync(cancellationToken));
Example #4
0
 public DepositService(IMongoDbContext context)
 {
     _context     = context;
     _Deposit     = _context.GetCollection <Deposit>(typeof(Deposit).Name);
     _currency    = _context.GetCollection <Currency>(typeof(Currency).Name);
     _appUser     = _context.GetCollection <AppUser>(typeof(AppUser).Name);
     _Depositmeth = _context.GetCollection <DepositMethod>(typeof(DepositMethod).Name);
 }
Example #5
0
        public async Task <bool> DeleteOneAsync <TDocument, TKey>(TDocument document)
            where TDocument : AggregateRootWithId <TKey>
        {
            var collection = _mongoDbContext.GetCollection <TDocument>();
            var filter     = BuilderHelpers.RequiredFilter <TDocument, TKey>(document);
            var deleteOne  = await collection.DeleteOneAsync(filter);

            return(deleteOne.DeletedCount == 1);
        }
 public AppUserService(IMongoDbContext context, IAccountService accserv)
 {
     _context = context;
     _AppUser = _context.GetCollection <AppUser>(typeof(AppUser).Name);
     _accserv = accserv;
     _acc     = _context.GetCollection <Account>(typeof(Account).Name);
     _dep     = _context.GetCollection <Deposit>(typeof(Deposit).Name);
     _bet     = _context.GetCollection <Bet>(typeof(Bet).Name);
     _gU      = _context.GetCollection <GuestUser>(typeof(GuestUser).Name);
 }
Example #7
0
        public AuthenticationService(JwtSettings jwtSettings, IMongoDbContext context
                                     , TokenValidationParameters tokenValidationParameters)

        {
            _context     = context;
            _AppUser     = _context.GetCollection <AppUser>(typeof(AppUser).Name);
            _refresh     = _context.GetCollection <RefreshToken>(typeof(RefreshToken).Name);
            _jwtSettings = jwtSettings;
            _tokenValidationParameters = tokenValidationParameters;
            _gU = context.GetCollection <GuestUser>(typeof(GuestUser).Name);
        }
Example #8
0
        public async Task <IActionResult> Mongo()
        {
            try
            {
                var collection = _mongoContext.GetCollection <OpenCity>();
                var cities     = await collection.Find(it => true).ToListAsync();

                return(Ok(cities));
            }
            catch (Exception ex)
            {
                return(BadRequest(ex.Message));
            }
        }
Example #9
0
        public virtual void Dispose()
        {
            var userIds = UsersToDelete.ToList().Select(e => e.Id);

            if (userIds.Any())
            {
                Context.GetCollection <TUser, TKey>().DeleteMany(e => userIds.Contains(e.Id));
            }
        }
Example #10
0
 public BetServices(IMongoDbContext context, IOfferService offerService,
                    IAccountService AccountS, IBetCounterService count,
                    IBetCounterService betcser)
 {
     _context     = context;
     _bet         = context.GetCollection <Bet>(typeof(Bet).Name);
     _Offer       = offerService;
     _Event       = context.GetCollection <Event>(typeof(Event).Name);
     _account     = context.GetCollection <Account>(typeof(Account).Name);
     _AccountS    = AccountS;
     _count       = count;
     _BetCountCol = context.GetCollection <BetCounter>(typeof(BetCounter).Name);;
     _Layoffer    = _context.GetCollection <LayOffer>(typeof(LayOffer).Name);
     _Backoffer   = _context.GetCollection <BackOffer>(typeof(BackOffer).Name);
     _involved    = _context.GetCollection <InvolvedLayBets>(typeof(InvolvedLayBets).Name);
     _involvedB   = _context.GetCollection <InvolvedBackBets>(typeof(InvolvedBackBets).Name);
     _end         = _context.GetCollection <Ended>(typeof(Ended).Name);
 }
Example #11
0
        public async Task <bool> UpdateOneAsync <TDocument, TKey>(TDocument document) where TDocument : AggregateRootWithId <TKey>
        {
            var mongoCollection  = _dbContext.GetCollection <TDocument>();
            var filter           = BuilderHelpers.RequiredFilter <TDocument, TKey>(document);
            var replaceOneResult = await mongoCollection.ReplaceOneAsync(filter, document);

            return(replaceOneResult.ModifiedCount == 1);
        }
Example #12
0
        public async Task Create(T obj)
        {
            if (obj == null)
            {
                throw new ArgumentNullException(typeof(T).Name);
            }

            DbCollection = _mongoContext.GetCollection <T>(typeof(T).Name);
            await DbCollection.InsertOneAsync(obj);
        }
        private void ApplyEvent(IEvent ev)
        {
            // TODO: Handle incoming events by updating the Mongo database
            switch (ev)
            {
            case CreatedEvent e:
                var resourceType = e.GetEntityType();
                switch (resourceType)
                {
                case ResourceType _ when resourceType == ResourceTypes.Foo:
                    var foo = new Foo
                    {
                        Id        = e.Id,
                        Timestamp = e.Timestamp,
                        UserId    = e.UserId
                    };
                    _db.Add(ResourceTypes.Foo, foo);
                    break;
                }

                break;

            case PropertyChangedEvent e:
                resourceType = e.GetEntityType();
                switch (resourceType)
                {
                case ResourceType _ when resourceType == ResourceTypes.Foo:
                    var originalFoo = _db.GetCollection <Foo>(resourceType).AsQueryable().First(x => x.Id == e.Id);
                    var args        = originalFoo.CreateFooArgs();
                    e.ApplyTo(args);
                    var updatedFoo = new Foo(args)
                    {
                        Id        = e.Id,
                        Timestamp = e.Timestamp,
                        UserId    = originalFoo.UserId
                    };
                    _db.Replace((ResourceTypes.Foo, e.Id), updatedFoo);
                    break;
                }

                break;


            case DeletedEvent e:
                resourceType = e.GetEntityType();
                switch (resourceType)
                {
                case ResourceType _ when resourceType == ResourceTypes.Foo:
                    _db.Delete((ResourceTypes.Foo, e.Id));
                    break;
                }

                break;
            }
        }
Example #14
0
        public void Create()
        {
            var collection = _dbContext.GetCollection <Basket>();

            if (!collection.Find(x => x.CustomerId > 0).Any())
            {
                var basket = Basket.Create(1);

                collection.InsertOne(basket);
            }
        }
Example #15
0
 public ConnectionService(IMongoDbContext context)
 {
     _context = context;
     _hCon    = _context.GetCollection <HomeGroup>(typeof(HomeGroup).Name);
     _lCon    = _context.GetCollection <LiveGroupConnection>(typeof(LiveGroupConnection).Name);
     _SBGroup = _context.GetCollection <SBoardGroups>(typeof(SBoardGroups).Name);
     _hUsrCon = _context.GetCollection <HomeUserConn>(typeof(HomeUserConn).Name);
     _lUsrCon = _context.GetCollection <LiveUserConn>(typeof(LiveUserConn).Name);
     _sUsrCon = _context.GetCollection <SBUserConn>(typeof(SBUserConn).Name);
     _appuser = context.GetCollection <AppUser>(typeof(AppUser).Name);
 }
Example #16
0
        // Configure task to be executed on startup lifecycle to ensure unique index is set.
        public async Task StartAsync(CancellationToken cancellationToken)
        {
            var collection   = _dbContext.GetCollection <SessionFeedback>(_dbSettings.SessionFeedbacksCollectionName);
            var indexKeysDef = Builders <SessionFeedback> .IndexKeys.Ascending(feedback => feedback.UserId).Ascending(feedback => feedback.SessionId);

            var options = new CreateIndexOptions()
            {
                Unique = true
            };

            await collection.Indexes.CreateOneAsync(new CreateIndexModel <SessionFeedback>(indexKeysDef, options), cancellationToken : cancellationToken);
        }
Example #17
0
        private static void CreateIndexes(IMongoDbContext dbContext)
        {
            #region Post Indexs

            dbContext.GetCollection <Post>().Indexes.CreateOneAsync(new CreateIndexModel <Post>(Builders <Post> .IndexKeys.Ascending(x => x.Id), new CreateIndexOptions()
            {
                Name = "Id", Unique = true
            }));
            dbContext.GetCollection <Post>().Indexes.CreateOneAsync(new CreateIndexModel <Post>(Builders <Post> .IndexKeys.Ascending(x => x.UserId), new CreateIndexOptions()
            {
                Name = "UserId"
            }));


            #endregion

            #region Taxonomy Indexs

            dbContext.GetCollection <Taxonomy>(name: "Taxonomies").Indexes.CreateOneAsync(new CreateIndexModel <Taxonomy>(Builders <Taxonomy> .IndexKeys.Ascending(x => x.Id), new CreateIndexOptions()
            {
                Name = "Id", Unique = true
            }));
            dbContext.GetCollection <Taxonomy>(name: "Taxonomies").Indexes.CreateOneAsync(new CreateIndexModel <Taxonomy>(Builders <Taxonomy> .IndexKeys.Ascending(x => x.Type), new CreateIndexOptions()
            {
                Name = "Type"
            }));


            #endregion

            #region User Indexs

            dbContext.GetCollection <User>().Indexes.CreateOneAsync(new CreateIndexModel <User>(Builders <User> .IndexKeys.Ascending(x => x.Id), new CreateIndexOptions()
            {
                Name = "Id", Unique = true
            }));
            dbContext.GetCollection <User>().Indexes.CreateOneAsync(new CreateIndexModel <User>(Builders <User> .IndexKeys.Ascending(x => x.Email), new CreateIndexOptions()
            {
                Name = "Email", Unique = true
            }));



            #endregion

            #region Role Indexs

            dbContext.GetCollection <Role>().Indexes.CreateOneAsync(new CreateIndexModel <Role>(Builders <Role> .IndexKeys.Ascending(x => x.Id), new CreateIndexOptions()
            {
                Name = "Id", Unique = true
            }));

            #endregion
        }
Example #18
0
            public async Task <Unit> Handle(Command request, CancellationToken cancellationToken)
            {
                var nextSequence = await dbContext.GetNextSequenceNumber <Product>(collectionName);

                var product = new Product()
                {
                    Name  = request.Name,
                    Price = request.Price,
                    Id    = nextSequence
                };
                var collection = dbContext.GetCollection <Product>(collectionName);
                await collection.InsertOneAsync(product);

                await dbContext.IncrementSequenceNumberAsync <Product>(collectionName);

                return(Unit.Value);
            }
Example #19
0
        /// <summary>
        /// 获取随机合约编号
        /// </summary>
        /// <returns>编号</returns>
        public long GetContractNum()
        {
            var filter = Builders <Counter> .Filter.Eq(p => p.Id, "randomid");

            var update = Builders <Counter> .Update.Inc(p => p.Value, 1);

            var options = new FindOneAndUpdateOptions <Counter>
            {
                ReturnDocument = ReturnDocument.After,
                IsUpsert       = true
            };

            var result = _mongoDbContext.GetCollection <Counter>().FindOneAndUpdateAsync(filter, update, options);

            result.Wait();
            return(result.Result.Value);
        }
Example #20
0
 public OfferService(IMongoDbContext context,
                     IAccountService accountService, IMapper mapper,
                     IEventServices eventserv,
                     IBetCounterService betcser
                     )
 {
     _context   = context;
     _Layoffer  = _context.GetCollection <LayOffer>(typeof(LayOffer).Name);
     _Bet       = _context.GetCollection <Bet>(typeof(Bet).Name);
     _Backoffer = _context.GetCollection <BackOffer>(typeof(BackOffer).Name);
     _Account   = accountService;
     _mapper    = mapper;
     _involved  = _context.GetCollection <InvolvedLayBets>(typeof(InvolvedLayBets).Name);
     _involvedB = _context.GetCollection <InvolvedBackBets>(typeof(InvolvedBackBets).Name);
     _eventserv = eventserv;
     _notif     = _context.GetCollection <Notification>(typeof(Notification).Name);
     _betcser   = betcser;
 }
Example #21
0
 public MongoApplicationDbContext(IMongoDbContext context)
 {
     UserLatestUpdateTimes = context.GetCollection <UserLatestUpdateTime>();
     SentUpdates           = context.GetCollection <SentUpdate>();
 }
Example #22
0
 public ApplicationDbContext(IMongoDbContext context)
 {
     Updates = context.GetCollection <UpdateEntity>();
 }
Example #23
0
 public Repository(IMongoDbContext <T> context)
 {
     _context    = context;
     _collection = _context.GetCollection();
 }
 /// <summary>
 /// Gets a collections for the type TDocument with a partition key.
 /// </summary>
 /// <typeparam name="TDocument">The document type.</typeparam>
 /// <typeparam name="TKey">The type of the primary key.</typeparam>
 /// <param name="partitionKey">The collection partition key.</param>
 /// <returns></returns>
 public virtual IMongoCollection <TDocument> GetCollection <TDocument, TKey>(string partitionKey = null)
     where TDocument : IDocument <TKey>
     where TKey : IEquatable <TKey>
 {
     return(MongoDbContext.GetCollection <TDocument>(partitionKey));
 }
Example #25
0
 public UserRepository(IMongoDbContext dbContext)
 {
     _users = dbContext.GetCollection <User>();
 }
 public Task <List <Cliente> > List(Cliente filter)
 {
     return(mongoDb.GetCollection <Cliente>().FindSync(FilterDefinition <Cliente> .Empty).ToListAsync());
 }
Example #27
0
 public AccountService(IMongoDbContext context)
 {
     _context = context;
     _Account = _context.GetCollection <Account>(typeof(Account).Name);
     _bet     = _context.GetCollection <Bet>(typeof(Bet).Name);
 }
 public TaxonomyRepository(IMongoDbContext dbContext)
 {
     _taxonomies = dbContext.GetCollection <Taxonomy>(name: "taxonomies");
 }
Example #29
0
 public Handler(IMongoDbContext dbContext, IOptions <DatabaseSettingsOptions> options)
 {
     collection = dbContext.GetCollection <Product>(options.Value.CollectionName);
 }
 public MigratedEntitiesRepository(IMongoDbContext dbContext)
 {
     _collection = dbContext.GetCollection <MigratedEntity>("pgMigratedEntities");
     CreateIndexes();
 }