public IDictionary<string, object> LoadTempData(ControllerContext controllerContext) { using (var db = new MongoDbContext(_connectionString)) { var sessionId = controllerContext.HttpContext.Request.UserHostAddress; var tempRecord = db.TempData.AsQueryable().FirstOrDefault(d => d.SessionId == sessionId); if (tempRecord != null) { db.TempData.Remove(Query.EQ("_id", tempRecord.SessionId)); return tempRecord.Data; } return null; } }
public void SaveTempData(ControllerContext controllerContext, IDictionary<string, object> values) { using (var db = new MongoDbContext(_connectionString)) { if (values != null) { var sessionId = controllerContext.HttpContext.Request.UserHostAddress; if (!string.IsNullOrEmpty(sessionId)) { db.TempData.Insert(new TempData() { Data = values.ToDictionary(k => k.Key, v => v.Value), SessionId = sessionId }); } } } }
public CrowdChatModule(MongoDbContext mongoDbContext) { this.mongoDbContext = mongoDbContext; }
public GoodsOrderingRepositry(IConfiguration config) { dbContext = MongoDbContext.getMongoDbContext(config); //geting singletone object of database collection = dbContext.getDataBase().GetCollection <GoodsOrdering>("GoodsOrdering"); //use singletone object to get database //and call that database to get collection of GoodsOrdering }
// This method gets called by the runtime. Use this method to add services to the container. public void ConfigureServices(IServiceCollection services) { //services.AddCors(); services.AddMvc().SetCompatibilityVersion(CompatibilityVersion.Version_2_2); var settings = new Models.Settings(Configuration); services.AddSingleton(settings); var context = new MongoDbContext(settings.MongoConnectionString, settings.DbName); services.AddTransient <MongoDB.Driver.IMongoDatabase>((x) => new MongoDbContext(settings.MongoConnectionString, settings.DbName).Database); services.AddIdentity <Models.ApplicationUser, Models.ApplicationRole>(options => { options.Password.RequireDigit = false; options.Password.RequiredLength = 3; options.Password.RequireNonAlphanumeric = false; options.Password.RequireUppercase = false; options.Password.RequireLowercase = false; options.Lockout.DefaultLockoutTimeSpan = TimeSpan.FromMinutes(30); options.Lockout.MaxFailedAccessAttempts = 10; options.SignIn.RequireConfirmedEmail = false; options.SignIn.RequireConfirmedPhoneNumber = false; // ApplicationUser settings options.User.RequireUniqueEmail = true; options.User.AllowedUserNameCharacters = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789@.-_"; }).AddMongoDbStores <IMongoDbContext>(context).AddDefaultTokenProviders(); services.AddAuthentication(x => { x.DefaultAuthenticateScheme = JwtBearerDefaults.AuthenticationScheme; x.DefaultChallengeScheme = JwtBearerDefaults.AuthenticationScheme; }) .AddJwtBearer(x => { x.RequireHttpsMetadata = false; x.SaveToken = true; x.TokenValidationParameters = new TokenValidationParameters { ValidateIssuerSigningKey = true, IssuerSigningKey = new SymmetricSecurityKey(Encoding.ASCII.GetBytes(settings.JwtSecurityKey)), ValidateIssuer = false, ValidateAudience = false }; }); services.ConfigureCoreApp(); services.AddSwaggerGen(options => { options.SwaggerDoc("v1", new Info { Title = "DocIT API", Version = "v0.1.0", Description = "DocIT REST API", Contact = new Contact { Name = "DocIT API Developers", Email = "*****@*****.**", Url = "https://localhost:5000" } }); options.AddSecurityDefinition("Bearer", new ApiKeyScheme { In = "header", Description = "Please enter into field the word 'Bearer' following by space and JWT", Name = "Authorization", Type = "apiKey" }); options.AddSecurityRequirement(new Dictionary <string, IEnumerable <string> > { { "Bearer", Enumerable.Empty <string>() }, }); var basePath = AppContext.BaseDirectory; var assemblyName = System.Reflection.Assembly.GetEntryAssembly().GetName().Name; var fileName = Path.GetFileName(assemblyName + ".xml"); options.IncludeXmlComments(System.IO.Path.Combine(basePath, fileName)); // options.SchemaFilter<SchemaFilter>(); //options.OperationFilter<SecurityRequirementsOperationFilter>(); }); services.AddCors(options => { options.AddPolicy("AllowMyOrigin", builder1 => builder1 .WithOrigins("*") .WithHeaders("*") .WithMethods("*") .WithExposedHeaders("X-Pagination") .SetPreflightMaxAge(TimeSpan.FromSeconds(2520)) ); }); DocIT.Core.AutoMapperConfig.RegisterMappings(); }
public PassoController(MongoDbContext context) { _passoRepository = context.GetPassoRepository(); _context = context; }
public async Task TestAddAndUpdateMultipleObservations() { //----------------------------------------------------------------------------------------------------------- // Arrange - Database connection, etc. //----------------------------------------------------------------------------------------------------------- MongoDbContext dbContext = new MongoDbContext(MongoUrl, DatabaseName, CollectionName); await dbContext.Mongodb.DropCollectionAsync(CollectionName); var observationRepository = new VersionedDocumentRepositoryObservation <SpeciesObservation>(dbContext); const int numberOfObservations = 10000; //----------------------------------------------------------------------------------------------------------- // Arrange - Create <DataProviderId, CatalogNumber> index //----------------------------------------------------------------------------------------------------------- var indexDefinition = Builders <VersionedDocumentObservation <SpeciesObservation> > .IndexKeys.Combine( Builders <VersionedDocumentObservation <SpeciesObservation> > .IndexKeys.Ascending(f => f.DataProviderId), Builders <VersionedDocumentObservation <SpeciesObservation> > .IndexKeys.Ascending(f => f.CatalogNumber)); CreateIndexOptions opts = new CreateIndexOptions { Unique = true }; await observationRepository.Collection.Indexes.CreateOneAsync(new CreateIndexModel <VersionedDocumentObservation <SpeciesObservation> >(indexDefinition, opts)); //----------------------------------------------------------------------------------------------------------- // Arrange - Create <CompositeId> index //----------------------------------------------------------------------------------------------------------- //await observationRepository.Collection.Indexes.CreateOneAsync(Builders<VersionedDocumentObservation<SpeciesObservation>>.IndexKeys.Ascending(_ => _.CompositeId), opts); //----------------------------------------------------------------------------------------------------------- // Arrange - Create original observations //----------------------------------------------------------------------------------------------------------- var speciesObservations = SpeciesObservationTestRepository.CreateRandomObservations(numberOfObservations); //----------------------------------------------------------------------------------------------------------- // Act - Insert documents first version //----------------------------------------------------------------------------------------------------------- await observationRepository.InsertDocumentsAsync(speciesObservations); //----------------------------------------------------------------------------------------------------------- // Act - Update two observations and insert //----------------------------------------------------------------------------------------------------------- speciesObservations[0].RecordedBy = "Art Vandelay"; speciesObservations[2].RecordedBy = "Peter Van Nostrand"; // Insert again. The function make diff check on all observations and updates only those that have changed. await observationRepository.InsertDocumentsAsync(speciesObservations); //----------------------------------------------------------------------------------------------------------- // Assert //----------------------------------------------------------------------------------------------------------- var obs0 = await observationRepository.GetDocumentAsync(speciesObservations[0].DataProviderId, speciesObservations[0].CatalogNumber); var obs1 = await observationRepository.GetDocumentAsync(speciesObservations[1].DataProviderId, speciesObservations[1].CatalogNumber); var obs2 = await observationRepository.GetDocumentAsync(speciesObservations[2].DataProviderId, speciesObservations[2].CatalogNumber); obs0.Version.Should().Be(2, "This observation has been updated"); obs1.Version.Should().Be(1, "This observation has not been updated"); obs2.Version.Should().Be(2, "This observation has been updated"); }
public FuncionarioReadOnlyRepositoryDenormalize(MongoDbContext context) : base(context, "Funcionarios") { }
public OrderRepository(MongoDbContext context) : base(context) { }
public EventsController(IEventRepository eventRepository, IMapper mapper, IOptions <Settings> settings) { _context = new MongoDbContext(settings); _eventRepository = eventRepository; _mapper = mapper; }
public DbCreateActorHandler(ILogger <DbCreateActorHandler> logger, IGeoTaskManagerDbContext dbContext) { Logger = logger; DbContext = (MongoDbContext)dbContext; }
public HijackingTestResultRepository(MongoDbContext context) : base(context) { }
public Repository(MongoDbContext context) { this.Context = context; }
public TalksService() { dbContext = new MongoDbContext(); }
public EstateValidator(MongoDbContext <Estate> db) { this.db = db; }
public DbGetGeoByIdHandler(ILogger <DbGetGeoByIdHandler> logger, IGeoTaskManagerDbContext dbContext) { Logger = logger; DbContext = (MongoDbContext)dbContext; }
public UserQuery(MongoDbContext db) { _db = db; }
public AnnouncementRepositry(IConfiguration config) { dbContext = MongoDbContext.getMongoDbContext(config); //geting singletone object of database collection = dbContext.getDataBase().GetCollection <Announcement>("Announcement"); //use singletone object to get database //and call that database to get collection of Announcement }
public AccountController(MongoDbContext context) { _dbContext = context; }
public Repository(IOptions <MongoSettings> settings) { _context = new MongoDbContext(settings); _collection = _context.GetCollection <TEntity>(); }
public UserExistsQuery(MongoDbContext db) { this._db = db; }
public async Task TestAddAndUpdateOneObservationCreatingDifferentVersions() { //----------------------------------------------------------------------------------------------------------- // Arrange - Database connection, etc. //----------------------------------------------------------------------------------------------------------- MongoDbContext dbContext = new MongoDbContext(MongoUrl, DatabaseName, CollectionName); await dbContext.Mongodb.DropCollectionAsync(CollectionName); var observationRepository = new VersionedDocumentRepositoryObservation <SpeciesObservation>(dbContext); //----------------------------------------------------------------------------------------------------------- // Arrange - Observation versions. One original version and 3 different updated versions. //----------------------------------------------------------------------------------------------------------- SpeciesObservation originalObservation = SpeciesObservationTestRepository.CreateRandomObservation(); var observationVersion2 = (SpeciesObservation)originalObservation.Clone(); observationVersion2.RecordedBy = "Peter van Nostrand"; var observationVersion3 = (SpeciesObservation)observationVersion2.Clone(); observationVersion3.CoordinateX = 54.234; var observationVersion4 = (SpeciesObservation)observationVersion3.Clone(); observationVersion4.RecordedBy = "Art Vandelay"; //----------------------------------------------------------------------------------------------------------- // Arrange - Variables //----------------------------------------------------------------------------------------------------------- int dataProviderId = originalObservation.DataProviderId; string catalogNumber = originalObservation.CatalogNumber; //----------------------------------------------------------------------------------------------------------- // Act //----------------------------------------------------------------------------------------------------------- await observationRepository.InsertDocumentAsync(originalObservation); // Version 1, First insert await observationRepository.InsertDocumentAsync(observationVersion2); // Version 2, Change [RecordedBy] await observationRepository.InsertDocumentAsync(observationVersion3); // Version 3, Change [CoordinateX] await observationRepository.DeleteDocumentAsync(dataProviderId, catalogNumber); // Version 4, Delete document await observationRepository.InsertDocumentAsync(observationVersion4); // Version 5, Change [RecordedBy] await observationRepository.DeleteDocumentAsync(dataProviderId, catalogNumber); // Version 6, Delete document //----------------------------------------------------------------------------------------------------------- // Act - Restore versions //----------------------------------------------------------------------------------------------------------- var restoredVer6 = await observationRepository.RestoreDocumentAsync(dataProviderId, catalogNumber, 6); var restoredVer5 = await observationRepository.RestoreDocumentAsync(dataProviderId, catalogNumber, 5); var restoredVer4 = await observationRepository.RestoreDocumentAsync(dataProviderId, catalogNumber, 4); var restoredVer3 = await observationRepository.RestoreDocumentAsync(dataProviderId, catalogNumber, 3); var restoredVer2 = await observationRepository.RestoreDocumentAsync(dataProviderId, catalogNumber, 2); var restoredVer1 = await observationRepository.RestoreDocumentAsync(dataProviderId, catalogNumber, 1); //----------------------------------------------------------------------------------------------------------- // Assert //----------------------------------------------------------------------------------------------------------- restoredVer6.Should().BeNull("the observation was deleted in version 6"); restoredVer5.Should().BeEquivalentTo(observationVersion4, "in version 5, the observationVersion4 was inserted"); restoredVer4.Should().BeNull("the observation was deleted in version 4"); restoredVer3.Should().BeEquivalentTo(observationVersion3, "in version 3, the observationVersion3 was inserted"); restoredVer2.Should().BeEquivalentTo(observationVersion2, "in version 2, the observationVersion2 was inserted"); restoredVer1.Should().BeEquivalentTo(originalObservation, "in the first version, the observationVersion1 was inserted"); }
//construtor para a injeção de dependência.. public UsuarioCache(MongoDbContext mongoDbContext) { this.mongoDbContext = mongoDbContext; }
public MongoDbConsentStore(MongoDbContext context) : base(context.GetCollection <MongoDbConsent>("of.auth.consent")) { }
public UserRespository(MongoDbContext context) : base(context) { }
public RepositoryMongoDb(MongoDbContext context) { Db = context; collection = Db.GetCollection <TEntity>(); }
public NoteRepository(IOptions <Settings> settings) { _context = new MongoDbContext(settings); }
public PeopleRepository(IOptions <DbSettings> settings) { _context = new MongoDbContext(settings); }
public BranchService() { _repositoryService = new RepositoriesService(); _context = new MongoDbContext(); }
static ChatController() { MongoDatabase = new MongoDbContext(); }
public RefreshTokenRepository(MongoDbContext context) { _context = context; }
public SqliteMongoConnectionManager() { _db = new MongoDbContext(); }
public ShoppingListsRepository(MongoDbContext dbContext) { _shoppingLists = dbContext.ShoppingLists; }
private void InitializeCrowdChatModule() { var mongoDbContext = new MongoDbContext(); this.crowdChatModule = new CrowdChatModule(mongoDbContext); }
public BrowseProductsQueryHandler(MongoDbContext context) : base(context) { }