Exemple #1
0
        public AvatarType GetAvatarById(int Id)
        {
            var avatarTypeLst = DBinitializer.GetAvatarTypes();
            var avatarType    = avatarTypeLst.Find(x => x.Id == Id);

            return(avatarType);
        }
Exemple #2
0
        public IEnumerable <Avatar> ReadAllAvatars()
        {
            // return _avatarLst;
            var avatarLst = DBinitializer.GetAvatars();

            return(avatarLst);
        }
Exemple #3
0
        public Owner GetOwnerById(int Id)
        {
            var ownerLst = DBinitializer.GetOwners();
            var owner    = ownerLst.Find(x => x.Id == Id);

            return(owner);
        }
Exemple #4
0
        public Avatar GetAvatarById(int Id)
        {
            var avatarLst = DBinitializer.GetAvatars();
            var avatar    = avatarLst.Find(x => x.Id == Id);

            return(avatar);
        }
Exemple #5
0
        public static void ApplyDatabaseMigrations()
        {
            DbMigrationsConfiguration dbMgConfig = new DBinitializer()
            {
                ContextType = typeof(POSSectorDBContext)
            };

            using (var databaseContext = new POSSectorDBContext())
            {
                try
                {
                    var db = databaseContext.Database;
                    var migrationConfiguration = dbMgConfig;
                    migrationConfiguration.TargetDatabase = new DbConnectionInfo(db.Connection.ConnectionString, "System.Data.SqlClient");
                    var migrator = new DbMigrator(migrationConfiguration);
                    migrator.Update();
                }
                catch (AutomaticDataLossException adle)
                {
                    dbMgConfig.AutomaticMigrationDataLossAllowed = true;
                    var    mg       = new DbMigrator(dbMgConfig);
                    var    scriptor = new MigratorScriptingDecorator(mg);
                    string script   = scriptor.ScriptUpdate(null, null);
                    throw new Exception(adle.Message + " : " + script);
                }
            }
        }
        // This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
        public void Configure(IApplicationBuilder app, IHostingEnvironment env)
        {
            if (env.IsDevelopment())
            {
                app.UseDeveloperExceptionPage();
                using (var scope = app.ApplicationServices.CreateScope())
                {
                    var ctx = scope.ServiceProvider.GetService <PetShopContext>();
                    DBinitializer.SeedDB(ctx);
                }
            }
            else
            {
                using (var scope = app.ApplicationServices.CreateScope())
                {
                    var ctx = scope.ServiceProvider.GetService <PetShopContext>();
                    ctx.Database.EnsureCreated();
                }
                app.UseHsts();
            }

            app.UseCors(builder => builder.AllowAnyOrigin().AllowAnyHeader().AllowAnyMethod());
            app.UseAuthentication();

            app.UseMvc();
        }
Exemple #7
0
        public AvatarType Create(AvatarType avatarType)
        {
            avatarType.Id = DBinitializer.GetNextIdType();
            var list = DBinitializer.GetAvatarTypes();

            list.Add(avatarType);
            return(avatarType);
        }
Exemple #8
0
        //Those DO NOTHING apperantly...
        // private static List<Avatar> _avatarLst = new List<Avatar>();
        // public static int id = 1;


        public Avatar Create(Avatar avatar)
        {
            avatar.Id = DBinitializer.GetNextId();
            var list = DBinitializer.GetAvatars();

            list.Add(avatar);
            return(avatar);
        }
        // This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
        public void Configure(IApplicationBuilder app, IHostingEnvironment env, LibraryContext LibraryContext)
        {
            if (env.IsDevelopment())
            {
                app.UseDeveloperExceptionPage();
            }

            app.UseMvc();
            DBinitializer.Initialize(LibraryContext);
        }
Exemple #10
0
        //private static List<Owner> _ownerLst = new List<Owner>();
        //static int id = 1;

        public Owner Create(Owner owner)
        {
            //owner.OwnerId = id++;
            //_ownerLst.Add(owner);
            //return owner;

            owner.Id = DBinitializer.GetNextId();
            var list = DBinitializer.GetOwners();

            list.Add(owner);
            return(owner);
        }
Exemple #11
0
        // This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
        public void Configure(IApplicationBuilder app, IWebHostEnvironment env)
        {
            if (env.IsDevelopment())
            {
                app.UseDeveloperExceptionPage();
            }

            //This is new

            using (var scope = app.ApplicationServices.CreateScope())
            {
                var repo   = scope.ServiceProvider.GetRequiredService <IAvatarRepository>();
                var atrepo = scope.ServiceProvider.GetRequiredService <IAvatarTypeRepository>();
                var owrepo = scope.ServiceProvider.GetRequiredService <IOwnerRepository>();
                //repo.Create(new Avatar { Name = "Bunsy", Type ="Bunny", Color ="Blue"});
                //repo.Create(new Avatar { Name = "Chili", Type = "Magician", Color = "Pink" });

                IAvatarRepository     avatarRepository     = new AvatarRepo();
                IAvatarTypeRepository avatarTypeRepository = new AvatarTypeRepo();
                IOwnerRepository      ownerRepository      = new OwnerRepo();

                //new DBinitializer  = new DBinitializer();
                //d.InitData();

                DBinitializer.InitData();
                IAvatarService     avatarService     = new AvatarService(avatarRepository);
                IAvatarTypeService avatarTypeService = new AvatarTypeService(avatarTypeRepository);
                IOwnerService      ownerService      = new OwnerService(ownerRepository);



                //YOU DID GITHUB WIHT TERMINAL !!!


                // app.UseWelcomePage();

                app.UseHttpsRedirection();

                app.UseRouting();

                app.UseAuthorization();

                app.UseEndpoints(endpoints =>
                {
                    endpoints.MapControllers();
                });
            }
        }
        // This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
        public void Configure(IApplicationBuilder app, IWebHostEnvironment env)
        {
            // if (env.IsDevelopment())
            //{

            app.UseDeveloperExceptionPage();
            using (var scope = app.ApplicationServices.CreateScope())
            {
                var ctx = scope.ServiceProvider.GetService <PetShopAppContext>();


                DBinitializer.seedDB(ctx);
                //var petRepo =  scope.ServiceProvider.GetRequiredService<IPetRepository>();
                //var ownerRepo =  scope.ServiceProvider.GetRequiredService<IOwnerRepository>();
                //var petTypeRepo = scope.ServiceProvider.GetRequiredService<IPetTypeRerpository>();

                //var mockDa = new MockData(petRepo, ownerRepo, petTypeRepo);
                //mockDa.InitData();
            }



            //}

            app.UseHttpsRedirection();

            app.UseRouting();

            app.UseAuthorization();

            app.UseEndpoints(endpoints =>
            {
                endpoints.MapControllers();
            });

            app.UseSwagger();

            app.UseSwaggerUI(options =>
            {
                options.SwaggerEndpoint("/swagger/v1/swagger.json", "Swagger Demo API");
            }
                             );
        }
Exemple #13
0
        // This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
        public void Configure(IApplicationBuilder app, IHostingEnvironment env, DBcontext context)
        {
            app.UseSwagger();

            //app.UseSwaggerUi();

            app.UseSession();

            if (env.IsDevelopment())
            {
                app.UseDeveloperExceptionPage();
            }

            app.UseDefaultFiles();
            app.UseStaticFiles();
            app.UseMvc();

            DBinitializer.Initialize(context);
        }
Exemple #14
0
        // This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
        public void Configure(IApplicationBuilder app, IWebHostEnvironment env, DeviceContext devContext)
        {
            if (env.IsDevelopment())
            {
                app.UseDeveloperExceptionPage();
            }
            //app.UseMvc(); //i have to disable something in order to be able to use this
            DBinitializer.Initialize(devContext);
            app.UseHttpsRedirection();

            app.UseRouting();

            app.UseAuthorization();

            app.UseEndpoints(endpoints =>
            {
                endpoints.MapControllers();
            });
        }
Exemple #15
0
        public static void Main(string[] args)
        {
            var host = BuildWebHost(args);

            using (var scope = host.Services.CreateScope())
            {
                var services = scope.ServiceProvider;
                try
                {
                    var context = services.GetRequiredService <MovieContext>();
                    DBinitializer.init(context);
                }
                catch (Exception ex)
                {
                    var logger = services.GetRequiredService <ILogger <Program> >();
                    logger.LogError(ex, "An error occurred while seeding the database.");
                }
            }
            BuildWebHost(args).Run();
        }
Exemple #16
0
        // This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
        public void Configure(IApplicationBuilder app, IHostingEnvironment env, PollContext context)
        {
            app.UseSwagger();
            app.UseSwaggerUI(c => { c.SwaggerEndpoint("/swagger/v1/swagger.json", "Poll API v1"); });
            if (env.IsDevelopment())
            {
                app.UseDeveloperExceptionPage();
            }
            else
            {
                // 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.UseAuthentication();
            app.UseCors("MyPolicy");
            app.UseMvc();
            DBinitializer.Initialize(context);
        }
Exemple #17
0
        public List <Avatar> GetAvatars()
        {
            var avatarLst = DBinitializer.GetAvatars();

            return(avatarLst);
        }
Exemple #18
0
        public List <Owner> GetOwners()
        {
            var ownerLst = DBinitializer.GetOwners();

            return(ownerLst);
        }
Exemple #19
0
 public IEnumerable <AvatarType> ReadAllAvatars()
 {
     return(DBinitializer.GetAvatarTypes());
     //return _avatarTypeLst;
 }
Exemple #20
0
        private List <AvatarType> GetAvatarTypes()
        {
            var avatarTypeLst = DBinitializer.GetAvatarTypes();

            return(avatarTypeLst);
        }