Exemplo n.º 1
0
        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();
            }
        }
Exemplo n.º 2
0
        public static AddressDbContext CreateTestDb(DbContextOptions <AddressDbContext> options)
        {
            var context = new AddressDbContext(options);

            context.Database.EnsureCreated();
            return(context);
        }
Exemplo n.º 3
0
        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);
            }
        }
Exemplo n.º 7
0
        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();
        }
Exemplo n.º 8
0
        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!";
            }
        }
Exemplo n.º 9
0
        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");
            }
                             );
        }
Exemplo n.º 10
0
 public ProvinceRepository(AddressDbContext dbContext)
 {
     _dbContext = dbContext ?? throw new System.ArgumentNullException(nameof(dbContext));
 }
Exemplo n.º 11
0
 public ContinentRepository(AddressDbContext dbContext)
 {
     _dbContext = dbContext ?? throw new ArgumentNullException(nameof(dbContext));
 }
Exemplo n.º 12
0
 /// <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)
 {
 }
Exemplo n.º 13
0
 public AddressRepository(AddressDbContext db)
 {
     _db = db;
 }
Exemplo n.º 14
0
 public AddressRepository(AddressDbContext context)
 {
     _db = context;
 }
Exemplo n.º 15
0
 /// <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));
 }
Exemplo n.º 16
0
 public UnitOfWorkBase(AddressDbContext dbContext)
 {
     DbContext    = dbContext ?? throw new ArgumentNullException(nameof(dbContext));
     _transaction = DbContext.Database.BeginTransaction(IsolationLevel.RepeatableRead);
 }