public CockpitUsersController(
     IUserRepository userRepo,
     EliteDataContext context,
     IUnitOfWork uof,
     UserManager <User> userManager,
     IMapper mapper,
     IConfirmResp confirmResponse,
     ILogger <CockpitUsersController> logger,
     ILoggerManager nLogger
     )
 {
     _userRepo    = userRepo;
     _unitOfWork  = uof;
     _userManager = userManager;
     _mapper      = mapper ?? throw new ArgumentNullException(nameof(mapper));
     _confirm     = confirmResponse;
     _logger      = logger;
     _nLogger     = nLogger;
 }
Ejemplo n.º 2
0
        //public static void ConfigureLoggerService(this IServiceCollection services) =>
        //    services.AddScoped<ILoggerManager, LoggerManager>();


        // This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
        public void Configure(IApplicationBuilder app, IWebHostEnvironment env, EliteDataContext context)
        {
            if (env.IsDevelopment())
            {
                app.UseDeveloperExceptionPage();
            }
            else
            {
                app.UseExceptionHandler(appBuilder => {
                    appBuilder.Run(async context => {
                        context.Response.StatusCode = 500;
                        await context.Response.WriteAsync("An unexpected fault happened. Try again later.");
                    });
                });
                // The default HSTS value is 30 days. You may want to change this for production scenarios, see https://aka.ms/aspnetcore-hsts.
                app.UseHsts();
            }



            // app.UseHttpsRedirection();

            //           app.UseDefaultFiles(); // It will prompt kestrel to look for default files like index.html from the wwwroot directory ** but this is done prior to deployment.
            app.UseStaticFiles();
            app.UseStaticFiles(new StaticFileOptions
            {
                FileProvider = new PhysicalFileProvider(Path.Combine(Directory.GetCurrentDirectory(), "Resources")),
                RequestPath  = new PathString("/Resources")
            });

            //if (!env.IsDevelopment())
            //{
            //    app.UseSpaStaticFiles();
            //}

            app.UseRouting(); // Routing here helps the app to locate which action method to call first, and because
            //                  authorization is placed at the action method, the authorization middleware must come after "app.useRouting()" middleware.

            //app.UseHealthChecks("/hc");
            app.UseCors("EliteCorsPolicy");

            // setup the identity middleware
            app.UseAuthentication(); // Know who you are // This will decrypt and validate the token, based on the configurations specified in the AddJwtBearer()
            app.UseAuthorization();  // Now that we know who you are, are you allowed to go here or there?


            /* Setup the attribute based routing  */
            app.UseEndpoints(endpoints =>
            {
                endpoints.MapControllers();
                endpoints.MapFallbackToController("Index", "Fallback");
            });

            //app.UseEndpoints(endpoints =>
            //{
            //    endpoints.MapControllerRoute(
            //        name: "default",
            //        pattern: "api/{controller}/{action=Index}/{id?}");
            //});


            DbInitializer.Initialize(context);
        }
Ejemplo n.º 3
0
        public static void Initialize(EliteDataContext context)
        {
            context.Database.EnsureCreated();
            // Don't put any data seeds in these tables if there is some data in them already
            string path = AppContext.BaseDirectory;       // Get the root directory

            string[] ss       = Regex.Split(path, "bin"); // Split the path at the bin keyword
            string   filePath = ss[0] + @"Seeds\";        // Append the Seeds folder to the rood dir path


            if (!context.Codes.Any())
            {
                var codesList = SeedingHelper.CsvToCodes(filePath + "Codes.csv");
                foreach (Code c in codesList)
                {
                    context.Codes.Add(c);
                }

                context.SaveChanges();
            }


            if (!context.FaqItems.Any())
            {
                var faqList = SeedingHelper.CsvToFaq(filePath + "Faq.csv");
                foreach (Faq f in faqList)
                {
                    context.FaqItems.Add(f);
                }

                context.SaveChanges();
            }


            //if (!context.Members.Any())
            //{
            //    var membersList = SeedingHelper.CsvToMember(filePath + "Members.csv");
            //    foreach (Member m in membersList)
            //    {
            //        context.Members.Add(m);
            //    }

            //    context.SaveChanges();
            //}


            //if (!context.Subscriptions.Any())
            //{
            //    var subscriptionsList = SeedingHelper.CsvToSubscription(filePath + "Subscriptions.csv");
            //    foreach (Subscription s in subscriptionsList)
            //    {
            //        context.Subscriptions.Add(s);
            //    }

            //    context.SaveChanges();
            //}


            //if (!context.Users.Any())
            //{
            //    var usersList = SeedingHelper.CsvToUser(filePath + "Users.csv");
            //    foreach (User u in usersList)
            //    {
            //        context.Users.Add(u);
            //    }

            //    context.SaveChanges();
            //}
        }