Advertisement
Guest User

Untitled

a guest
Aug 17th, 2017
463
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.17 KB | None | 0 0
  1. Microsoft.AspNetCore Version="1.1.2"
  2. Microsoft.AspNetCore.Mvc Version="1.1.3"
  3. Microsoft.Extensions.Logging.Debug Version="1.1.2"
  4. Microsoft.EntityFrameworkCore.Design Version="1.1.1"
  5. Microsoft.EntityFrameworkCore.SqlServer Version="1.1.1"
  6. Microsoft.EntityFrameworkCore.SqlServer.Design Version="1.1.1"
  7. Pomelo.EntityFrameworkCore.MySql Version="1.1.1"
  8. Pomelo.EntityFrameworkCore.MySql.Design Version="1.1.1"
  9.  
  10. public class UserItem
  11. {
  12. public long Id { get; set; }
  13.  
  14. [MaxLength(32)]
  15. public string Username { get; set; }
  16.  
  17. [MaxLength(256)]
  18. public string Password { get; set; } //Hashed Value
  19.  
  20. public override bool Equals(object obj){
  21. if(obj is UserItem){
  22. return ((UserItem)obj).Id == this.Id;
  23. }
  24. return false;
  25. }
  26.  
  27. public virtual ICollection<ConnectionItem> ConnectionItems { get; set; }
  28. }
  29.  
  30. public class ConnectionItem
  31. {
  32. public long Id { get; set; }
  33.  
  34. public long UserRefID { get; set; }
  35.  
  36. [ForeignKey("UserRefID")]
  37. public virtual UserItem User{ get; set; }
  38.  
  39. [MaxLength(32)]
  40. public string TargetName { get; set; }
  41.  
  42. [MaxLength(18)]
  43. public string TargetAddress {get; set; }
  44. }
  45.  
  46. public class UserContext : DbContext
  47. {
  48. public string ConnectionString{get; set;}
  49. public UserContext(DbContextOptions<UserContext> options) : base(options)
  50. {
  51. }
  52.  
  53. public DbSet<UserItem> UserItems { get; set; }
  54. }
  55.  
  56. public class ConnectionContext : DbContext
  57. {
  58. public string ConnectionString{get; set;}
  59. public ConnectionContext(DbContextOptions<ConnectionContext> options) : base(options)
  60. {
  61. }
  62.  
  63. public DbSet<ConnectionItem> ConnectionItems { get; set; }
  64.  
  65. }
  66.  
  67. public class Startup
  68. {
  69. public Startup(IHostingEnvironment env)
  70. {
  71. var builder = new ConfigurationBuilder()
  72. .SetBasePath(env.ContentRootPath)
  73. .AddJsonFile("appsettings.json", optional: false, reloadOnChange: true)
  74. .AddJsonFile($"appsettings.{env.EnvironmentName}.json", optional: true)
  75. .AddEnvironmentVariables();
  76. Configuration = builder.Build();
  77. }
  78. public IConfigurationRoot Configuration { get; }
  79.  
  80. // This method gets called by the runtime. Use this method to add services to the container.
  81. public void ConfigureServices(IServiceCollection services)
  82. {
  83. var connection = Configuration["ConnectionStrings:MySQLConnectionString"];
  84. services.AddDbContext<UserContext>(opt => opt.UseMySql(connection)).AddDbContext<ConexaoContext>(opt => opt.UseMySql(connection));
  85. // Add framework services.
  86. services.AddMvc();
  87. }
  88.  
  89. // This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
  90. public void Configure(IApplicationBuilder app, UserContext uContext, ConexaoContext cContext)
  91. {
  92. app.UseMvc();
  93. InicializaBD.Initialize(uContext);
  94. InicializaBD.Initialize(cContext);
  95. }
  96. }
  97.  
  98. public static class InicializaBD
  99. {
  100. public static void Initialize(DbContext context)
  101. {
  102. context.Database.EnsureCreated();
  103. context.SaveChanges();
  104. }
  105. }
  106.  
  107. +-------------------+
  108. | Tables_in_arduino |
  109. +-------------------+
  110. | ConnectionItem |
  111. | UserItems |
  112. +-------------------+
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement