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); }
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); } }
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); } }
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; } }
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); }
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); }
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; } }
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(); } } }
public async Task <List <Questions> > GetQuestionListAsync() { return(await _context.GetCollection <Questions>("Questions").Find(new BsonDocument()).ToListAsync()); }
protected void ConfigDbSet() { DbSet = Context.GetCollection <TEntity>(typeof(TEntity).Name); }
public StudentRepository(IMongoContext context) { collection = context.GetCollection <Student>("students"); }
public GetGroupQueryModel(IMongoContext context) { _collection = context.GetCollection <GroupReadModel>(); }
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); }
public LogQueryRepository(IMongoContext context) { _dbSet = context.GetCollection <Log>(typeof(Log).Name); }
public async Task <List <UsersModel> > GetUserListAsync() { return(await _context.GetCollection <UsersModel>("UsersModel").Find(new BsonDocument()).ToListAsync()); }
public NotificationController(IMongoContext mongoContext) { _mongoContext = mongoContext; _collection = _mongoContext.GetCollection <NotifyKiosk>(); _userId = User.Identity.GetUserId(); }
private void ConfigDbSet() { _dbSet = _context.GetCollection <TEntity>(typeof(TEntity).Name); }
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); }
private async Task CreateCollectionCategoryAsync(IMongoContext mongoContext) { var clientUser = mongoContext.GetCollection <Category>(); await clientUser.Indexes.CreateOneAsync(Builders <Category> .IndexKeys.Ascending(x => x.CreatedAt)); }
public CarDAL(IMongoContext context, IUnitOfWork uow, IMapper mapper) : base(context, uow) { _mapper = mapper; _context = context; _brands = _context.GetCollection <Markalar>("Markalar"); }
public EventStoreListener(IEventStoreContext eventStoreContext, IMongoContext mongoContext, IStreamHandler eventHandler) { _eventStoreContext = eventStoreContext; _eventHandler = eventHandler; _collection = mongoContext.GetCollection <EventStorePosition>(); }
public StreamHandler(IMediator mediator, IMongoContext mongoContext) { _mediator = mediator; _collection = mongoContext.GetCollection <EventStorePosition>(); }
protected BaseRepository(IMongoContext context) { _context = context; DbSet = _context.GetCollection <TEntity>(typeof(TEntity).Name); }
public Repository(IMongoContext context) { Context = context; DbSet = Context.GetCollection <T>(typeof(T).Name); }
private void ConfigDbSet() { DbSet = Context.GetCollection <T>(typeof(T).Name); }
public ApplicationName Get() { return(_mongoContext.GetCollection <ApplicationName>().FindAll().First()); }