public async Task ReceiveAsync(AuthenticationTokenReceiveContext context) { var allowedOrigin = context.OwinContext.Get <string>(OAuthServerProvider.Client_AllowedOriginKey); if (allowedOrigin == null) { allowedOrigin = "*"; // TODO: investigate why this value is null. } context.OwinContext.Response.Headers.Add("Access-Control-Allow-Origin", new[] { allowedOrigin }); string hashedTokenId = Encryptor.GetHash(context.Token); using (var dbContext = new AppDatabaseContext()) { var repo = new RefreshTokenRepo(dbContext); { var refreshToken = repo.GetById(hashedTokenId); if (refreshToken != null) { //Get protectedTicket from refreshToken class context.DeserializeTicket(refreshToken.ProtectedTicket); repo.Delete(hashedTokenId); repo.SaveChanges(); } } } await Task.FromResult <object>(null); }
public ArticlesTest() { options = new DbContextOptionsBuilder <AppDatabaseContext>(). UseInMemoryDatabase(databaseName: "AppDatabaseArticles").Options; db = new AppDatabaseContext(options); var article1 = new Article { Id = firstArticleId, Title = "Article 1" }; var article2 = new Article { Id = secondArticleId, Title = "Article 2" }; try { db.Articles.Add(article1); db.Articles.Add(article2); db.SaveChanges(); } catch (ArgumentException) { db.Articles.RemoveRange(db.Articles); } }
public ProductsController() { this.db = new AppDatabaseContext(); var productRepo = new ProductRepository(db); this.productService = new ProductService(productRepo); }
public virtual void CleanUp() { // Delete the database using (var dbContext = new AppDatabaseContext()) { dbContext.Database.Delete(); }; }
public BaseHandler(AppDatabaseContext context) { _repoWrapper = new RepositoryWrapper(context); var config = new MapperConfiguration(cfg => { cfg.AddProfile <ArticleProfile>(); }); _mapper = config.CreateMapper(); }
private static Client GetClientFromDb(string clientId) { Client client; using (var appDbContext = new AppDatabaseContext()) { client = new ClientRepo(appDbContext).GetById(clientId); } return(client); }
protected virtual void Dispose(bool disposing) { if (!this.disposed) { if (disposing) { _dbContext.Dispose(); _dbContext = null; this.disposed = true; } } }
private void AddTestCountries() { var countries = DummyDataGenerator.GetCountries(10); using (var appDbcontext = new AppDatabaseContext()) { foreach (var country in countries) { appDbcontext.Countries.Add(country); } appDbcontext.SaveChanges(); } }
private void AddTestUsers() { var userStore = new UserStore <AppUser, AppRole, long, ExternalUserLogin, AppUserAppRoleMapping, AppUserClaim>(new AppDatabaseContext()); var userManager = new UserManager <AppUser, long>(userStore); var dbContext = new AppDatabaseContext(); var addresses = dbContext.Addresses.ToList(); var testUsers = DummyDataGenerator.GetUsers(UsersCount, addresses); foreach (var user in testUsers) { userManager.Create(user, Constants.DefaultUsers.DefaultTestUserPassword); } }
public virtual void SetUp() { // Creates a new database using (var dbContext = new AppDatabaseContext()) { AppDatabaseContext.Create(); }; // Add common test data to the database AddTestCountries(); AddTestStates(); AddTestCities(); AddTestAddresses(); }
private void AddTestStates() { var states = DummyDataGenerator.GetStates(10); using (var appDbcontext = new AppDatabaseContext()) { var country = appDbcontext.Countries.First(); foreach (var state in states) { state.CountryId = country.Id; appDbcontext.States.Add(state); } appDbcontext.SaveChanges(); } }
private void AddTestCities() { var cities = DummyDataGenerator.GetCities(10); using (var appDbcontext = new AppDatabaseContext()) { var state = appDbcontext.States.First(); foreach (var city in cities) { city.StateId = state.Id; appDbcontext.Cities.Add(city); } appDbcontext.SaveChanges(); } }
private void AddTestAddresses() { var addresses = DummyDataGenerator.GetAddresses(10); using (var appDbcontext = new AppDatabaseContext()) { var countries = appDbcontext.Countries.ToList(); var states = appDbcontext.States.ToList(); var cities = appDbcontext.Cities.ToList(); foreach (var address in addresses) { var random = new Random(); var country = countries[random.Next(0, countries.Count - 1)]; var state = states[random.Next(0, states.Count - 1)]; var city = cities[random.Next(0, cities.Count - 1)]; address.CityId = city.Id; appDbcontext.Addresses.Add(address); } appDbcontext.SaveChanges(); } }
/// <summary> /// Explicitly loads all audio and images associated with the specified page. /// Additional information pages are loaded recursively in the same way. /// </summary> /// <param name="page"></param> public static void LoadPageDetails(Page page) { // Loading must happen in one DbContext scope so that // references between pages are correctly fixed up. using (var db = new AppDatabaseContext(QueryTrackingBehavior.TrackAll)) { db.Attach(page); var pageEntry = db.Entry(page); pageEntry.Navigation(nameof(Page.Audio)).Load(); switch (page) { case ImagePage imagePage: db.Entry(imagePage).Navigation(nameof(ImagePage.Image)).Load(); break; case TimeSliderPage timeSliderPage: pageEntry.Navigation(nameof(TimeSliderPage.SliderImages)).Load(); foreach (var img in timeSliderPage.SliderImages) { db.Entry(img).Navigation(nameof(TimeSliderPageImage.Image)).Load(); } break; } var subpageNav = pageEntry.Navigation(nameof(Page.AdditionalInformationPagesRefs)); // Recursively load additional information pages // (Note: page references may be circular - this check breaks the recursion) if (!subpageNav.IsLoaded) { subpageNav.Load(); foreach (var subpageRef in page.AdditionalInformationPagesRefs) { db.Entry(subpageRef).Navigation(nameof(JoinPagePage.AdditionalInformationPage)).Load(); LoadPageDetails(subpageRef.AdditionalInformationPage); } } } }
public async Task CreateAsync(AuthenticationTokenCreateContext context) { var clientid = context.Ticket.Properties.Dictionary[OAuthServerProvider.ClientIdKey]; if (string.IsNullOrEmpty(clientid)) { return; } var refreshTokenId = Guid.NewGuid().ToString("n"); using (var dbContext = new AppDatabaseContext()) { var repo = new RefreshTokenRepo(dbContext); var refreshTokenLifeTime = context.OwinContext.Get <string>(OAuthServerProvider.Client_RefreshTokenLifeTimeKey); long userId = -1; long.TryParse(context.Ticket.Identity.Claims.FirstOrDefault(c => c.Type == ClaimTypes.NameIdentifier).Value, out userId); var token = new RefreshToken() { Id = Encryptor.GetHash(refreshTokenId), // stored hashed values only ClientId = clientid, UserId = userId, IssuedOnUtc = DateTime.UtcNow, ExpiresOnUtc = DateTime.UtcNow.AddMinutes(Convert.ToDouble(refreshTokenLifeTime)) }; context.Ticket.Properties.IssuedUtc = token.IssuedOnUtc; context.Ticket.Properties.ExpiresUtc = token.ExpiresOnUtc; token.ProtectedTicket = context.SerializeTicket(); repo.Insert(token); repo.SaveChanges(); context.SetToken(refreshTokenId); } await Task.FromResult <object>(null); }
internal static ProductPageModel GetPageModel(int currentPageNum, AppDatabaseContext ctx, Product.SortType sortType, string searchName, int minPrice, int maxPrice) { var pageCount = ctx.Products.Count() / MAX_PAGE_LENGTH; if (ctx.Products.Count() % MAX_PAGE_LENGTH != 0) { pageCount++; } if (pageCount <= currentPageNum) { return(EMPTY_MODEL); } ProductPageModel model = new ProductPageModel { _sortType = sortType.ToString(), _pageCount = pageCount, _currentPageNum = currentPageNum, _entries = ctx.GetSortedQuery(currentPageNum * MAX_PAGE_LENGTH, MAX_PAGE_LENGTH, sortType, searchName, minPrice, maxPrice) }; return(model); }
public async Task UpdateArticleSuccessTest() { var queryHandler = new GetArticleQueryHandler(db); var getArticleQuery = new GetArticleQuery(firstArticleId); var article = await queryHandler.Handle(getArticleQuery, CancellationToken.None); db = new AppDatabaseContext(options); var sut = new UpdateArticleCommandHandler(db); var updatedArticleCommand = new UpdateArticleCommand { Id = firstArticleId, Title = "Updated Article Title" }; var result = await sut.Handle(updatedArticleCommand, CancellationToken.None); var updatedArticle = queryHandler.Handle(getArticleQuery, CancellationToken.None); Assert.IsType <Unit>(result); Assert.NotNull(updatedArticle); }
public Form1() { InitializeComponent(); var opBuilder = new DbContextOptionsBuilder <AppDatabaseContext>(); var conStringBuilder = new SqliteConnectionStringBuilder(); conStringBuilder.DataSource = @"AppDB.db"; opBuilder.UseSqlite(conStringBuilder.ConnectionString); this.context = new AppDatabaseContext(opBuilder.Options); this.chm = new ChannelManager(this.context); this.cm = new ConnectorManager(this.context); this.ctwm = new ConnectorToWireManager(this.context); this.dm = new DeviceManager(this.context); this.mm = new MeasurementManager(this.context); this.om = new ObstacleManager(this.context); this.omm = new ObstacleAmountManager(this.context); this.wm = new WireManager(this.context); this.wam = new WireAttenuationManager(this.context); this.nfi.NumberDecimalSeparator = "."; Init(); }
public ConnectorRepository(AppDatabaseContext context) : base(context) { }
public Terminal(AppDatabaseContext db) { _db = db; }
public Faq(AppDatabaseContext db) { _db = db; }
public WireAttenuationManager(AppDatabaseContext context) { this.rep = new WireAttenuationRepository(context); }
public LessonRepository(AppDatabaseContext context) { _context = context; }
public RequestType(AppDatabaseContext db) { _db = db; }
public EntityFrameworkRepository(AppDatabaseContext context) { Context = context; DbSet = context.Set <TEntity>(); }
public UserRepository(AppDatabaseContext context) : base(context) { }
public Rairing(AppDatabaseContext db) { _db = db; }
public StatisticsRepository(AppDatabaseContext context) { _context = context; }
public Gallery(AppDatabaseContext db) { _db = db; }
public ComplexityRepository(AppDatabaseContext context) { _context = context; }