예제 #1
0
        // This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
        public void Configure(IApplicationBuilder app, IHostingEnvironment env, ThesisAPIContext context)
        {
            if (env.IsDevelopment())
            {
                app.UseBrowserLink();
                app.UseDeveloperExceptionPage();
            }
            else
            {
                app.UseExceptionHandler("/Home/Error");
            }

            app.UseStaticFiles();

            // Thiết lập Cors
            app.UseCors(builder => builder
                        .AllowAnyOrigin()
                        .AllowAnyMethod()
                        .AllowAnyHeader()
                        .AllowCredentials());

            app.UseMvc(routes =>
            {
                routes.MapRoute(
                    name: "default",
                    template: "{controller=Home}/{action=Index}/{id?}");
            });

            // Auto create db
            context.Database.Migrate();
        }
예제 #2
0
        public static void Initialize(IServiceProvider serviceProvider)
        {
            using (var context = new ThesisAPIContext(
                       serviceProvider.GetRequiredService <DbContextOptions <ThesisAPIContext> >()))
            {
                if (context.Pins.Any() && context.Users.Any() && context.DHTs.Any()) // If Data had value , return
                {
                    return;
                }
                if (!context.Pins.Any())
                {
                    context.Pins.AddRange(
                        new Pin(1, KitKey.Kit001, 0), new Pin(2, KitKey.Kit001, 0), new Pin(3, KitKey.Kit001, 0),
                        new Pin(4, KitKey.Kit001, 0), new Pin(5, KitKey.Kit001, 0),
                        new Pin(9, KitKey.Kit001, 0), new Pin(10, KitKey.Kit001, 0),
                        new Pin(12, KitKey.Kit001, 0), new Pin(13, KitKey.Kit001, 0),
                        new Pin(14, KitKey.Kit001, 0), new Pin(15, KitKey.Kit001, 0),
                        new Pin(1, KitKey.Kit002, 0), new Pin(2, KitKey.Kit002, 0), new Pin(3, KitKey.Kit002, 0),
                        new Pin(4, KitKey.Kit002, 0), new Pin(5, KitKey.Kit002, 0),
                        new Pin(9, KitKey.Kit002, 0), new Pin(10, KitKey.Kit002, 0),
                        new Pin(12, KitKey.Kit002, 0), new Pin(13, KitKey.Kit002, 0),
                        new Pin(14, KitKey.Kit002, 0), new Pin(15, KitKey.Kit002, 0)
                        );
                }
                if (!context.Users.Any())
                {
                    context.Users.AddRange(
                        new User("Hai Bui", "admin", "*****@*****.**", "admin", "919b8459", UserRole.Admin, Gender.Male),
                        new User("User", "user", "*****@*****.**", "user", "", UserRole.User, Gender.Male),
                        new User("User 1", "user1", "*****@*****.**", "user1", "", UserRole.User, Gender.Male),
                        new User("User 2", "user2", "*****@*****.**", "user2", "", UserRole.User, Gender.Female),
                        new User("User 3", "user3", "*****@*****.**", "user3", "", UserRole.User, Gender.Female)
                        );
                }

                context.SaveChanges();
            }
        }
예제 #3
0
 public PinController(ThesisAPIContext context)
 {
     this._repository = new PinRepo(context);
 }
예제 #4
0
        private readonly ThesisAPIContext _context; // DbContext để truy xuất dữ liệu từ CSDL

        public UserRepo(ThesisAPIContext context)
        {
            this._context = context;
        }
예제 #5
0
        private readonly ThesisAPIContext _context; // DbContext để truy xuất dữ liệu từ CSDL

        public PinRepo(ThesisAPIContext context)
        {
            this._context = context;
        }
예제 #6
0
 public UserController(ThesisAPIContext context)
 {
     this._repository = new UserRepo(context);
 }
예제 #7
0
 public DHTController(ThesisAPIContext context)
 {
     this._repository = new DHTRepo(context);
 }