Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Microsoft.AspNetCore Version="1.1.2"
- Microsoft.AspNetCore.Mvc Version="1.1.3"
- Microsoft.Extensions.Logging.Debug Version="1.1.2"
- Microsoft.EntityFrameworkCore.Design Version="1.1.1"
- Microsoft.EntityFrameworkCore.SqlServer Version="1.1.1"
- Microsoft.EntityFrameworkCore.SqlServer.Design Version="1.1.1"
- Pomelo.EntityFrameworkCore.MySql Version="1.1.1"
- Pomelo.EntityFrameworkCore.MySql.Design Version="1.1.1"
- public class UserItem
- {
- public long Id { get; set; }
- [MaxLength(32)]
- public string Username { get; set; }
- [MaxLength(256)]
- public string Password { get; set; } //Hashed Value
- public override bool Equals(object obj){
- if(obj is UserItem){
- return ((UserItem)obj).Id == this.Id;
- }
- return false;
- }
- public virtual ICollection<ConnectionItem> ConnectionItems { get; set; }
- }
- public class ConnectionItem
- {
- public long Id { get; set; }
- public long UserRefID { get; set; }
- [ForeignKey("UserRefID")]
- public virtual UserItem User{ get; set; }
- [MaxLength(32)]
- public string TargetName { get; set; }
- [MaxLength(18)]
- public string TargetAddress {get; set; }
- }
- public class UserContext : DbContext
- {
- public string ConnectionString{get; set;}
- public UserContext(DbContextOptions<UserContext> options) : base(options)
- {
- }
- public DbSet<UserItem> UserItems { get; set; }
- }
- public class ConnectionContext : DbContext
- {
- public string ConnectionString{get; set;}
- public ConnectionContext(DbContextOptions<ConnectionContext> options) : base(options)
- {
- }
- public DbSet<ConnectionItem> ConnectionItems { get; set; }
- }
- public class Startup
- {
- public Startup(IHostingEnvironment env)
- {
- var builder = new ConfigurationBuilder()
- .SetBasePath(env.ContentRootPath)
- .AddJsonFile("appsettings.json", optional: false, reloadOnChange: true)
- .AddJsonFile($"appsettings.{env.EnvironmentName}.json", optional: true)
- .AddEnvironmentVariables();
- Configuration = builder.Build();
- }
- public IConfigurationRoot Configuration { get; }
- // This method gets called by the runtime. Use this method to add services to the container.
- public void ConfigureServices(IServiceCollection services)
- {
- var connection = Configuration["ConnectionStrings:MySQLConnectionString"];
- services.AddDbContext<UserContext>(opt => opt.UseMySql(connection)).AddDbContext<ConexaoContext>(opt => opt.UseMySql(connection));
- // Add framework services.
- services.AddMvc();
- }
- // This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
- public void Configure(IApplicationBuilder app, UserContext uContext, ConexaoContext cContext)
- {
- app.UseMvc();
- InicializaBD.Initialize(uContext);
- InicializaBD.Initialize(cContext);
- }
- }
- public static class InicializaBD
- {
- public static void Initialize(DbContext context)
- {
- context.Database.EnsureCreated();
- context.SaveChanges();
- }
- }
- +-------------------+
- | Tables_in_arduino |
- +-------------------+
- | ConnectionItem |
- | UserItems |
- +-------------------+
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement