private void txtGenerate_Click(object sender, EventArgs e) { AddressDbContext ctx = new AddressDbContext(); //ctx.Database.EnsureDeleted(); ctx.Database.EnsureCreated(); if (ctx.LongCodes.FirstOrDefault(lc => lc.Address == txtLongAddress.Text) != null) { var lc = ctx.LongCodes.FirstOrDefault(lc => lc.Address == txtLongAddress.Text); var sc = ctx.ShortCodes.Find(lc.LongCodeID); shortAddress = sc.Address; txtShortAddress.Text = shortAddress; } else { Generator gn = new Generator(); Models.LongCode lc = new Models.LongCode { Address = longAddress }; lc.ShortCode = new Models.ShortCode() { LongCodeId = lc.LongCodeID, Address = gn.ShortAddressGenerator(6, longAddress) }; shortAddress = lc.ShortCode.Address; txtShortAddress.Text = shortAddress; ctx.LongCodes.Add(lc); ctx.SaveChanges(); } }
public static AddressDbContext CreateTestDb(DbContextOptions <AddressDbContext> options) { var context = new AddressDbContext(options); context.Database.EnsureCreated(); return(context); }
public AddressRepo(ILogger <AddressRepo> logger, IOptions <DB> dbOptions) { logger.CheckNull(); dbOptions.CheckNull(); _logger = logger; _dbOptions = dbOptions; _context = new AddressDbContext(_dbOptions); }
public async Task <List <IdName> > GetCites(int stateId) { using (var dbContext = new AddressDbContext()) { var items = await dbContext.City .Where(e => e.StateId == stateId) .Select(e => new IdName { Id = e.Id, Name = e.Name, }).ToListAsync(); return(items); } }
public async Task <List <IdName> > GetStates(int countryId) { using (var dbContext = new AddressDbContext()) { var items = await dbContext.State .Where(e => e.CountryId == countryId) .Select(e => new IdName { Id = e.Id, Name = e.Name }).ToListAsync(); return(items); } }
public async Task <List <CountryDto> > GetCountries() { using (var dbContext = new AddressDbContext()) { var items = await dbContext.Country .Select(e => new CountryDto { Id = e.Id, Name = e.Name, SortName = e.SortName }).ToListAsync(); return(items); } }
static void Main(string[] args) { var db = new AddressDbContext(); while (!Console.KeyAvailable) { foreach (var address in db.MyAddresses.ToList()) { Console.WriteLine(address.Address); } } Console.ReadLine(); }
private void btnGeneratorR_Click(object sender, EventArgs e) { AddressDbContext ctx = new AddressDbContext(); ctx.Database.EnsureCreated(); if (ctx.ShortCodes.FirstOrDefault(sc => sc.Address == txtShortAddressR.Text) != null) { var sc = ctx.ShortCodes.FirstOrDefault(sc => sc.Address == txtShortAddressR.Text); var lc = ctx.LongCodes.Find(sc.LongCodeId); shortAddressR = lc.Address; txtLongAddressR.Text = shortAddressR; } else { txtLongAddressR.Text = "Not Found!"; } }
public void Configure(IApplicationBuilder app, IHostingEnvironment env, AddressDbContext context) { if (env.IsDevelopment()) { app.UseDeveloperExceptionPage(); } else { // The default HSTS value is 30 days. You may want to change this for production scenarios, see https://aka.ms/aspnetcore-hsts. app.UseHsts(); } using (var scope = app.ApplicationServices.GetRequiredService <IServiceScopeFactory>().CreateScope()){ scope.ServiceProvider.GetService <AddressDbContext>().Database.Migrate(); } app.UseHttpsRedirection(); app.UseMvc(); app.UseSwagger(); app.UseSwaggerUI(config => { config.SwaggerEndpoint("/swagger/v1/swagger.json", "Address API Documentation"); } ); }
public ProvinceRepository(AddressDbContext dbContext) { _dbContext = dbContext ?? throw new System.ArgumentNullException(nameof(dbContext)); }
public ContinentRepository(AddressDbContext dbContext) { _dbContext = dbContext ?? throw new ArgumentNullException(nameof(dbContext)); }
/// <summary> /// Instantiates a new instance of the <see cref="CityUnitOfWork"/> class. /// </summary> /// <param name="dbContext">database context used to interact with the database</param> /// <exception cref="ArgumentNullException"> /// if <paramref name="dbContext"/> is null /// </exception> public CityUnitOfWork(AddressDbContext dbContext) : base(dbContext) { }
public AddressRepository(AddressDbContext db) { _db = db; }
public AddressRepository(AddressDbContext context) { _db = context; }
/// <summary> /// constructor for the project0 database access /// </summary> /// <param name="context">Dbcontext for accessing the database</param> public DataAccess(AddressDbContext context, IMapper mapper, ILogger <DataAccess> logger) { _context = context ?? throw new ArgumentNullException(nameof(context)); _mapper = mapper ?? throw new ArgumentNullException(nameof(mapper)); _logger = logger ?? throw new ArgumentNullException(nameof(logger)); }
public UnitOfWorkBase(AddressDbContext dbContext) { DbContext = dbContext ?? throw new ArgumentNullException(nameof(dbContext)); _transaction = DbContext.Database.BeginTransaction(IsolationLevel.RepeatableRead); }