AspNetMVC-InventoryManagement-WebApi icon indicating copy to clipboard operation
AspNetMVC-InventoryManagement-WebApi copied to clipboard

Database script missing

Open itsChris opened this issue 4 years ago • 2 comments

Hi falaybeg

thanks for your contribution. i was trying to get that project running in my vs.net 2019 ide. i changed the InventoryDbContext in web.config to point to my sql server. maybe i'm missing something but i believe the SQL database script is not provided in the source? or is it a code-first solution where i can generate the database somehow?

thanks and kind regards

Christian

itsChris avatar Apr 25 '20 07:04 itsChris

Hi itsChris could you please share the database script, code first approach is not working on my ends

arehman2001 avatar Jul 25 '20 14:07 arehman2001

Hello,

Delete all migrations from migrations folder.

Then run the following commands in package-manager console.

Enable-Migrations -Force
Add-Migration init
Update-Database

İf you want initial users also replace seed function at configuration class with this :

 protected override void Seed(NtierApp.Repository.Context.InventoryDbContext context)
        {
            //  This method will be called after migrating to the latest version.

            //  You can use the DbSet<T>.AddOrUpdate() helper extension method 
            //  to avoid creating duplicate seed data.
            if (!(context.Users.Any(u => u.UserName == "[email protected]")))
            {
                var userStore = new UserStore<ApplicationUserr>(context);
                var userManager = new UserManager<ApplicationUserr>(userStore);
                var userToInsert = new ApplicationUserr { UserName = "[email protected]", PhoneNumber = "123123", Email = "[email protected]", RegisteredDate = DateTime.Now };
                userManager.Create(userToInsert, "Password@123");
            }
        }

osmanraifgunes avatar Jul 05 '22 12:07 osmanraifgunes