Esempio n. 1
0
        static int Main(string[] args)
        {
            RootCommand root = new RootCommand();

            Command addUser = new Command("adduser")
            {
                new Option <string>(new string[] { "--username", "-u" }, description: "The name of the user/account"),
                new Option <string>(new string[] { "--password", "-p" }, description: "The password for the new user/account"),
            };

            addUser.Handler = CommandHandler.Create <string, string>(async(username, password) =>
            {
                IConfiguration config = new ConfigurationBuilder()
                                        .AddJsonFile("appsettings.json", true, true)
                                        .AddJsonFile("secrets.json", true, true)
                                        .Build();

                CalorieContext db = new CalorieContext(config);

                AuthService auth = new AuthService(db);

                await auth.CreateUserAsync(username, password);

                Console.WriteLine("User {0} created", username);
            });

            root.Add(addUser);

            return(root.InvokeAsync(args).Result);
        }
Esempio n. 2
0
        public static void Main(string[] args)
        {
            IHost host = CreateHostBuilder(args).Build();

            using (IServiceScope serviceScope = host.Services.CreateScope())
            {
                CalorieContext context = serviceScope.ServiceProvider.GetRequiredService <CalorieContext>();

                context.Database.EnsureCreated();
            }

            host.Run();
        }
Esempio n. 3
0
 public CalorieService(CalorieContext DB)
 {
     _db = DB;
 }
 public CalorieRepository(CalorieContext calorieContext)
 {
     CalorieContext = calorieContext;
 }
Esempio n. 5
0
 public AuthService(CalorieContext DB)
 {
     _db = DB;
 }