Ejemplo n.º 1
0
        private IMongoQueryable <Categories> GetCategoryQuery(GetCategoryRequest filter)
        {
            var query = _ctx.GetCollection <Categories>()
                        .AsQueryable()
                        .BaseFilter();

            query = query.OrderByDescending(x => x.CreatedAt);

            if (!string.IsNullOrEmpty(filter.Id))
            {
                query = query.Where(x => x.Id.Equals(filter.Id));
            }

            if (!string.IsNullOrEmpty(filter.Name))
            {
                query = query.Where(x => x.Name.ToLower() == filter.Name.ToLower());
            }

            if (filter.IsActive.HasValue)
            {
                query = query.Where(x => x.IsActive == filter.IsActive);
            }

            if (!string.IsNullOrEmpty(filter.SearchText))
            {
                query = query.Where(x => x.Name.Contains(filter.SearchText) ||
                                    x.Description.Contains(filter.SearchText));
            }


            if (filter.Take.HasValue)
            {
                query = query.Take(filter.Take.Value);
            }

            if (filter.Skip.HasValue)
            {
                query = query.Skip(filter.Skip.Value);
            }

            return(query);
        }
Ejemplo n.º 2
0
        public BookService(IOptions <BookstoreDatabaseSettings> settings, IMongoContext mongoContext)
        {
            //var client = new MongoClient(settings.Value.ConnectionString);
            ////mongoContext.
            //var database = client.GetDatabase(settings.Value.DatabaseName);

            //_books = database.GetCollection<Book>(settings.Value.BooksCollectionName);

            _MongoContext = mongoContext;
            _books        = mongoContext.GetCollection <Book>(settings.Value.BooksCollectionName);
        }
        public async Task <PointQueryResult> FindAsync(string id)
        {
            try
            {
                async Task <PointQueryResult> SearchInDataBaseAsync()
                {
                    return(await _mongoContext.GetCollection <Point>(MongoCollections.Point)
                           .Find(x => x.Id == ObjectId.Parse(id) && x.Active)
                           .Project(x => new PointQueryResult {
                        Name = x.Name, Id = x.Id
                    })
                           .FirstOrDefaultAsync());
                }

                return(await GetFromCacheIfExist($"{CacheKeys.Points}:{id}", SearchInDataBaseAsync));
            }
            catch (Exception ex)
            {
                throw new UserFriendlyException("Error to find the connection", ex);
            }
        }
Ejemplo n.º 4
0
 public Task <User> GetUserByEmailAndPassword(string email, string password)
 {
     try
     {
         return(_context.GetCollection <User>(MongoCollections.User)
                .Find(x => x.Email == email && x.Password == password)
                .FirstOrDefaultAsync());
     }
     catch (Exception ex)
     {
         throw new UserFriendlyException("An error occurs to get user", ex);
     }
 }
Ejemplo n.º 5
0
        public async Task <User> GetUserByName(string name)
        {
            try
            {
                var obj = await _context.GetCollection <User>("User").Find(m => m.Username == name).FirstOrDefaultAsync();

                return(obj);
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
Ejemplo n.º 6
0
        private IMongoQueryable <Reviews> GetReviewQuery(GetReviewRequest filter)
        {
            var query = _ctx.GetCollection <Reviews>()
                        .AsQueryable()
                        .BaseFilter();

            query = query.OrderByDescending(x => x.CreatedAt);

            if (!string.IsNullOrEmpty(filter.Id))
            {
                query = query.Where(x => x.Id.Equals(filter.Id));
            }


            if (!string.IsNullOrEmpty(filter.CatalogId))
            {
                query = query.Where(x => x.CatalogId.Equals(filter.CatalogId));
            }

            if (filter.IsActive.HasValue)
            {
                query = query.Where(x => x.IsActive == filter.IsActive);
            }

            if (filter.Take.HasValue)
            {
                query = query.Take(filter.Take.Value);
            }

            if (filter.Skip.HasValue)
            {
                query = query.Skip(filter.Skip.Value);
            }

            return(query);
        }
Ejemplo n.º 7
0
        private async Task SaveProductRevision(object model, BasicDeliverEventArgs ea)
        {
            try
            {
                var body     = ea.Body;
                var message  = Encoding.UTF8.GetString(body);
                var response = JsonConvert.DeserializeObject <ProductResponse>(message);

                var revisionData = await GetProductRevisions(response.Id);

                var product = response.Map <ProductResponse, Products>();

                if (!string.IsNullOrEmpty(revisionData?.Id))
                {
                    revisionData.Revisions.Add(product);
                    await _context.GetCollection <ProductRevisions>().ReplaceOneAsync(r => r.Id == response.Id, revisionData);
                }
                else
                {
                    var productRevision = new ProductRevisions
                    {
                        Id        = response.Id,
                        Revisions = new List <Products> {
                            product
                        }
                    };

                    await _context.GetCollection <ProductRevisions>().InsertOneAsync(productRevision);
                }
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex);
                throw;
            }
        }
        private IMongoQueryable <Providers> GetProviderQuery(GetProviderRequest filter)
        {
            var query = _ctx.GetCollection <Providers>()
                        .AsQueryable()
                        .BaseFilter();

            if (!string.IsNullOrEmpty(filter.Id))
            {
                query = query.Where(x => x.Id == filter.Id);
            }

            if (filter.IsActive.HasValue)
            {
                query = query.Where(x => x.IsActive == filter.IsActive);
            }

            if (!string.IsNullOrEmpty(filter.SearchText))
            {
                query = query.Where(x => x.Name.Contains(filter.SearchText) ||
                                    x.Description.Contains(filter.SearchText));
            }

            return(query);
        }
Ejemplo n.º 9
0
        private IMongoCollection <TDocument> GetDbSet()
        {
            try
            {
                return(context.GetCollection <TDocument>(typeof(TDocument).Name));
            }
            catch (Exception e)
            {
                logger.LogError(e, "Failed to get collection for entity", new
                {
                    EntityType = typeof(TDocument).Name
                });

                throw;
            }
        }
Ejemplo n.º 10
0
        public async Task SeedAsync(IApplicationBuilder applicationBuilder, ILoggerFactory loggerFactory)
        {
            if (!_context.GetCollection <UsersModel>("UsersModel").AsQueryable().Any())
            {
                if (!_context.GetCollection <UsersModel>("UsersModel").Find(new BsonDocument()).ToList().Any())
                {
                    //await SetIndexesAsync();
                    await SetUsersAsync();
                }
            }

            if (!_context.GetCollection <Questions>("Questions").AsQueryable().Any())
            {
                if (!_context.GetCollection <Questions>("Questions").Find(new BsonDocument()).ToList().Any())
                {
                    //await SetIndexesAsync();
                    await SetQuestionsAsync();
                }
            }
        }
Ejemplo n.º 11
0
 public async Task <List <Questions> > GetQuestionListAsync()
 {
     return(await _context.GetCollection <Questions>("Questions").Find(new BsonDocument()).ToListAsync());
 }
Ejemplo n.º 12
0
 protected void ConfigDbSet()
 {
     DbSet = Context.GetCollection <TEntity>(typeof(TEntity).Name);
 }
Ejemplo n.º 13
0
 public StudentRepository(IMongoContext context)
 {
     collection = context.GetCollection <Student>("students");
 }
Ejemplo n.º 14
0
 public GetGroupQueryModel(IMongoContext context)
 {
     _collection = context.GetCollection <GroupReadModel>();
 }
Ejemplo n.º 15
0
        public async Task <List <Answer> > GetAnswersByQuestionId(Guid id)
        {
            var list = (await _context.GetCollection <Answer>("Answer").FindAsync(m => m.QuestionId == id)).ToList();

            return(list);
        }
 protected Repository(IMongoContext context, IUnitOfWork uow)
 {
     _context = context;
     _uow     = uow;
     DbSet    = _context.GetCollection <TEntity>(typeof(TEntity).Name);
 }
Ejemplo n.º 17
0
 public LogQueryRepository(IMongoContext context)
 {
     _dbSet = context.GetCollection <Log>(typeof(Log).Name);
 }
Ejemplo n.º 18
0
 public async Task <List <UsersModel> > GetUserListAsync()
 {
     return(await _context.GetCollection <UsersModel>("UsersModel").Find(new BsonDocument()).ToListAsync());
 }
Ejemplo n.º 19
0
 public NotificationController(IMongoContext mongoContext)
 {
     _mongoContext = mongoContext;
     _collection   = _mongoContext.GetCollection <NotifyKiosk>();
     _userId       = User.Identity.GetUserId();
 }
Ejemplo n.º 20
0
 private void ConfigDbSet()
 {
     _dbSet = _context.GetCollection <TEntity>(typeof(TEntity).Name);
 }
Ejemplo n.º 21
0
 public MongoRepository(IMongoContext context, string collectionName)
 {
     _context   = context;
     Collection = context.GetCollection <TEntity>(collectionName);
 }
 protected MongoRepository(IMongoContext mongoContext, string collectionName)
 {
     _mongoContext = mongoContext;
     _collection   = _mongoContext.GetCollection <T>(collectionName);
 }
Ejemplo n.º 23
0
        private async Task CreateCollectionCategoryAsync(IMongoContext mongoContext)
        {
            var clientUser = mongoContext.GetCollection <Category>();

            await clientUser.Indexes.CreateOneAsync(Builders <Category> .IndexKeys.Ascending(x => x.CreatedAt));
        }
Ejemplo n.º 24
0
 public CarDAL(IMongoContext context, IUnitOfWork uow, IMapper mapper) : base(context, uow)
 {
     _mapper  = mapper;
     _context = context;
     _brands  = _context.GetCollection <Markalar>("Markalar");
 }
Ejemplo n.º 25
0
 public EventStoreListener(IEventStoreContext eventStoreContext, IMongoContext mongoContext, IStreamHandler eventHandler)
 {
     _eventStoreContext = eventStoreContext;
     _eventHandler      = eventHandler;
     _collection        = mongoContext.GetCollection <EventStorePosition>();
 }
Ejemplo n.º 26
0
 public StreamHandler(IMediator mediator, IMongoContext mongoContext)
 {
     _mediator   = mediator;
     _collection = mongoContext.GetCollection <EventStorePosition>();
 }
Ejemplo n.º 27
0
 protected BaseRepository(IMongoContext context)
 {
     _context = context;
     DbSet    = _context.GetCollection <TEntity>(typeof(TEntity).Name);
 }
Ejemplo n.º 28
0
        public Repository(IMongoContext context)
        {
            Context = context;

            DbSet = Context.GetCollection <T>(typeof(T).Name);
        }
Ejemplo n.º 29
0
 private void ConfigDbSet()
 {
     DbSet = Context.GetCollection <T>(typeof(T).Name);
 }
 public ApplicationName Get()
 {
     return(_mongoContext.GetCollection <ApplicationName>().FindAll().First());
 }