示例#1
0
        protected override void Seed(BookingApp.Models.BAContext context)
        {
            /****/

            if (!context.Roles.Any(r => r.Name == "Admin"))
            {
                var store   = new RoleStore <IdentityRole>(context);
                var manager = new RoleManager <IdentityRole>(store);
                var role    = new IdentityRole {
                    Name = "Admin"
                };

                manager.Create(role);
            }

            if (!context.Roles.Any(r => r.Name == "Manager"))
            {
                var store   = new RoleStore <IdentityRole>(context);
                var manager = new RoleManager <IdentityRole>(store);
                var role    = new IdentityRole {
                    Name = "Manager"
                };

                manager.Create(role);
            }

            if (!context.Roles.Any(r => r.Name == "AppUser"))
            {
                var store   = new RoleStore <IdentityRole>(context);
                var manager = new RoleManager <IdentityRole>(store);
                var role    = new IdentityRole {
                    Name = "AppUser"
                };

                manager.Create(role);
            }


            var userStore   = new UserStore <BAIdentityUser>(context);
            var userManager = new UserManager <BAIdentityUser>(userStore);

            if (!context.Users.Any(u => u.UserName == "mitja"))
            {
                var user1 = new BAIdentityUser()
                {
                    Id = "mitja", UserName = "******", Email = "*****@*****.**", PasswordHash = BAIdentityUser.HashPassword("mitja")
                };
                userManager.Create(user1);
                userManager.AddToRole(user1.Id, "Admin");
            }

            BAIdentityUser user = new BAIdentityUser()
            {
                Id = "stefan", UserName = "******", Email = "*****@*****.**", PasswordHash = BAIdentityUser.HashPassword("stefan")
            };

            if (!context.Users.Any(u => u.UserName == "stefan"))
            {
                userManager.Create(user);
                userManager.AddToRole(user.Id, "Manager");
            }

            if (!context.Users.Any(u => u.UserName == "user"))
            {
                var user1 = new BAIdentityUser()
                {
                    Id = "user", UserName = "******", Email = "*****@*****.**", PasswordHash = BAIdentityUser.HashPassword("user")
                };
                userManager.Create(user1);
                userManager.AddToRole(user1.Id, "AppUser");
            }

            user.Accomodations    = new List <Accommodation>();
            user.Comments         = new List <Comment>();
            user.RoomReservations = new List <RoomReservations>();



            var accomod  = new Accommodation();
            var accomod2 = new Accommodation();
            var accomods = new List <Accommodation>()
            {
                accomod, accomod2
            };

            var accomType = new AccommodationType();

            accomType.Name = "Motel";
            // accomType.Accommodations = accomods;

            var accomType2 = new AccommodationType();

            accomType2.Name = "Hotel";
            // accomType2.Accommodations = accomods;

            var place  = new Place();
            var place2 = new Place();

            var room  = new Room();
            var room2 = new Room();
            var rooms = new List <Room>()
            {
                room, room2
            };

            var country = new Country();

            country.Name = "Serbia";
            //country.Regions = new List<Region>() { region, region2 };
            country.Code = 43;
            //region.Country = country;

            var country2 = new Country();

            country2.Name = "Serbia";
            //country2.Regions = new List<Region>() { region2 };
            country2.Code = 44;
            //region2.Country = country2;


            var region = new Region();

            region.Name    = "Zlatibor";
            region.Country = country;
            //region.Places = new List<Place>() { place, place2 };

            var region2 = new Region();

            region2.Name    = "Jahorina";
            region2.Country = country2;
            // region2.Places = new List<Place>() { place, place2 };

            place.Name     = "place1";
            place.RegionId = 1;
            //place.Accommodations = new List<Accommodation>() { accomod, accomod2 };

            place2.Name     = "place2";
            place2.RegionId = 1;
            //place2.Accommodations = new List<Accommodation>() { accomod, accomod2 };

            accomod.Address  = "Jovana Subotica";
            accomod.Approved = true;
            accomod.User     = user;
            //accomod.Comments = comments;
            accomod.AvrageGrade      = 50;
            accomod.Description      = "opisAccom";
            accomod.AccomodationType = accomType;
            accomod.ImageURL         = "http://arhiva.alo.rs/resources/img/10-07-2014/single_news/1300330-sako1.jpg";
            accomod.Latitude         = 41.9271155;
            accomod.Longitude        = 19.2364064;
            accomod.Place            = place;
            accomod.Name             = "Vila Rijana";
            //accomod.Rooms = rooms;

            accomod2.Address  = "Nikole Pasica";
            accomod2.Approved = true;
            accomod2.User     = user;
            //accomod2.Comments = comments;
            accomod2.AvrageGrade      = 40;
            accomod2.Description      = "opisAccom2";
            accomod2.AccomodationType = accomType2;
            accomod2.ImageURL         = "https://s-ec.bstatic.com/images/hotel/max1024x768/741/74116567.jpg";
            accomod2.Latitude         = 42.286238;
            accomod2.Longitude        = 18.8327733;
            accomod2.Place            = place2;
            accomod2.Name             = "Hotel Moskva";
            //accomod.Rooms = rooms;

            var comment = new Comment()
            {
                User = user, Text = "dobar", Grade = 10, Accomodation = accomod
            };
            var comment2 = new Comment()
            {
                User = user, Text = "los", Grade = 2, Accomodation = accomod2
            };

            room.Description   = "opisSobe1";
            room.PricePerNight = 100;
            room.RoomNumber    = 4;
            room.BedCount      = 3;
            room.Accomodation  = accomod;
            //room.RoomReservations = new List<RoomReservations>() { roomReservations, roomReservations2 };

            room2.Description   = "opisSobe12";
            room2.PricePerNight = 97;
            room2.RoomNumber    = 6;
            room2.BedCount      = 3;
            room2.Accomodation  = accomod2;
            //room2.RoomReservations = new List<RoomReservations>() { roomReservations, roomReservations2 };

            var roomReservations  = new RoomReservations();
            var roomReservations2 = new RoomReservations();

            roomReservations.Room      = room;
            roomReservations.User      = user;
            roomReservations.Timestamp = DateTime.Now.ToString();
            roomReservations.StartDate = new DateTime(2017, 1, 1).ToString();
            roomReservations.EndDate   = new DateTime(2017, 2, 2).ToString();

            roomReservations2.Room      = room2;
            roomReservations2.User      = user;
            roomReservations2.Timestamp = DateTime.Now.ToString();
            roomReservations2.StartDate = new DateTime(2017, 3, 3).ToString();
            roomReservations2.EndDate   = new DateTime(2017, 4, 4).ToString();

            context.Accommodations.AddOrUpdate(accomod);
            context.Accommodations.AddOrUpdate(accomod2);

            // context.Users
            context.Rooms.AddOrUpdate(room);
            context.Rooms.AddOrUpdate(room2);

            context.RoomReservationss.AddOrUpdate(roomReservations);
            context.RoomReservationss.AddOrUpdate(roomReservations2);

            context.Comments.AddOrUpdate(comment);
            context.Comments.AddOrUpdate(comment2);

            context.SaveChanges();
        }
示例#2
0
        protected override void Seed(BookingApp.Models.BAContext 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. E.g.
            //
            //    context.People.AddOrUpdate(
            //      p => p.FullName,
            //      new Person { FullName = "Andrew Peters" },
            //      new Person { FullName = "Brice Lambson" },
            //      new Person { FullName = "Rowan Miller" }
            //    );
            //

            if (!context.Roles.Any(r => r.Name == "Admin"))
            {
                var store   = new RoleStore <IdentityRole>(context);
                var manager = new RoleManager <IdentityRole>(store);
                var role    = new IdentityRole {
                    Name = "Admin"
                };

                manager.Create(role);
            }

            if (!context.Roles.Any(r => r.Name == "Manager"))
            {
                var store   = new RoleStore <IdentityRole>(context);
                var manager = new RoleManager <IdentityRole>(store);
                var role    = new IdentityRole {
                    Name = "Manager"
                };

                manager.Create(role);
            }

            if (!context.Roles.Any(r => r.Name == "AppUser"))
            {
                var store   = new RoleStore <IdentityRole>(context);
                var manager = new RoleManager <IdentityRole>(store);
                var role    = new IdentityRole {
                    Name = "AppUser"
                };

                manager.Create(role);
            }

            var userStore   = new UserStore <BAIdentityUser>(context);
            var userManager = new UserManager <BAIdentityUser>(userStore);


            AppUser appUser = new AppUser();

            appUser.LastName         = "admin";
            appUser.Name             = "admin";
            appUser.RoomReservations = new List <RoomReservation>();
            appUser.Comments         = new List <Comment>();
            appUser.Accommodations   = new List <Accommodation>();
            appUser.IsBanned         = false;

            context.AppUsers.Add(appUser);
            context.SaveChanges();

            if (!context.Users.Any(u => u.UserName == "admin"))
            {
                var userr = context.AppUsers.Where(u => u.Name == "admin" && u.LastName == "admin").FirstOrDefault();
                var user  = new BAIdentityUser()
                {
                    Id = "admin", UserName = "******", Email = "*****@*****.**", AppUserId = userr.Id, PasswordHash = BAIdentityUser.HashPassword("admin")
                };
                userManager.Create(user);
                userManager.AddToRole(user.Id, "Admin");
            }


            Country country = new Country();

            country.Id      = 1;
            country.Name    = "Serbia";
            country.Code    = "RS";
            country.Regions = new List <Region>();

            Country country2 = new Country();

            country2.Id      = 2;
            country2.Name    = "France";
            country2.Code    = "FR";
            country2.Regions = new List <Region>();

            Region region = new Region();

            region.Country = country;
            region.Id      = 1;
            region.Name    = "Vojvodina";
            region.Places  = new List <Place>();
            country.Regions.Add(region);

            Place place = new Place();

            place.Id             = 1;
            place.Name           = "Novi Sad";
            place.Region         = region;
            place.Accommodations = new List <Accommodation>();
            region.Places.Add(place);

            AccommodationType accType = new AccommodationType();

            accType.Name = "Hostel";

            AccommodationType accType2 = new AccommodationType();

            accType2.Name = "Motel";

            AppUser apu = new AppUser();

            apu.Name     = "Marina";
            apu.LastName = "Bobar";


            Accommodation acc = new Accommodation();

            acc.AccommodationType = accType;
            acc.Name         = "Laguna";
            acc.Place        = place;
            acc.Rooms        = new List <Room>();
            acc.Address      = "Kisacka 5";
            acc.Approved     = false;
            acc.AverageGrade = 0;
            acc.Comments     = new List <Comment>();
            acc.Description  = "blabla";
            acc.Latitude     = 0;
            acc.Longitude    = 0;
            acc.Owner        = apu;

            try
            {
                context.Countries.Add(country);
                context.Countries.Add(country2);
                context.Places.Add(place);
                context.Regions.Add(region);
                //  context.AccommodationTypes.Add(accType);
                //  context.AccommodationTypes.Add(accType2);
                context.Accommodations.Add(acc);
                context.SaveChanges();
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message);
            }
        }
示例#3
0
        protected override void Seed(BAContext context)
        {
            if (!context.Roles.Any(r => r.Name == "Admin"))
            {
                var store   = new RoleStore <IdentityRole>(context);
                var manager = new RoleManager <IdentityRole>(store);
                var role    = new IdentityRole {
                    Name = "Admin"
                };

                manager.Create(role);
            }

            if (!context.Roles.Any(r => r.Name == "Manager"))
            {
                var store   = new RoleStore <IdentityRole>(context);
                var manager = new RoleManager <IdentityRole>(store);
                var role    = new IdentityRole {
                    Name = "Manager"
                };

                manager.Create(role);
            }

            if (!context.Roles.Any(r => r.Name == "AppUser"))
            {
                var store   = new RoleStore <IdentityRole>(context);
                var manager = new RoleManager <IdentityRole>(store);
                var role    = new IdentityRole {
                    Name = "AppUser"
                };

                manager.Create(role);
            }

            var userStore   = new UserStore <BAIdentityUser>(context);
            var userManager = new UserManager <BAIdentityUser>(userStore);

            if (!context.Users.Any(u => u.UserName == "admin"))
            {
                var user1 = new BAIdentityUser()
                {
                    Id = "admin", UserName = "******", Email = "*****@*****.**", PasswordHash = BAIdentityUser.HashPassword("admin")
                };
                userManager.Create(user1);
                userManager.AddToRole(user1.Id, "Admin");
            }

            BAIdentityUser user = new BAIdentityUser()
            {
                Id = "user1", UserName = "******", Email = "*****@*****.**", PasswordHash = BAIdentityUser.HashPassword("user")
            };

            if (!context.Users.Any(u => u.UserName == "user1"))
            {
                userManager.Create(user);
                userManager.AddToRole(user.Id, "Manager");
            }

            if (!context.Users.Any(u => u.UserName == "user2"))
            {
                var user1 = new BAIdentityUser()
                {
                    Id = "user2", UserName = "******", Email = "*****@*****.**", PasswordHash = BAIdentityUser.HashPassword("user")
                };
                userManager.Create(user1);
                userManager.AddToRole(user1.Id, "AppUser");
            }

            //user.Accomodations = new List<Accommodation>();
            //user.Comments = new List<Comment>();
            //user.RoomReservations = new List<RoomReservation>();

            context.SaveChanges();

            Country country = new Country();

            country.Id      = 1;
            country.Name    = "Serbia";
            country.Code    = "RS";
            country.Regions = new List <Region>();

            Region region = new Region();

            region.Country = country;
            region.Id      = 1;
            region.Name    = "Vojvodina";
            region.Places  = new List <Place>();
            country.Regions.Add(region);

            Place place = new Place();

            place.Id            = 1;
            place.Name          = "Novi Sad";
            place.Region        = region;
            place.Accomodations = new List <Accommodation>();
            region.Places.Add(place);

            AccommodationType accType = new AccommodationType();

            accType.Id             = 1;
            accType.Name           = "Lux";
            accType.Accommodations = new List <Accommodation>();

            Accommodation acc = new Accommodation();

            acc.Id           = 1;
            acc.Address      = "Hanke Paldum 22";
            acc.Approved     = false;
            acc.AverageGrade = 5;
            acc.Comments     = new List <Comment>();
            acc.Description  = "Lux apartmants.";
            acc.ImageUrl     = "slika";
            acc.Latitude     = 0;
            acc.Longitude    = 0;
            acc.Name         = "Luxy";
            acc.Owner        = user;
            acc.Place        = place;
            acc.Rooms        = new List <Room>();
            accType.Accommodations.Add(acc);
            //user.Accomodations.Add(acc);

            Room room = new Room();

            room.Accomodation     = acc;
            room.BedCount         = 2;
            room.Description      = "Soba 704";
            room.Id               = 1;;
            room.PricePerNight    = 56;
            room.RoomNumber       = 1;
            room.RoomReservations = new List <RoomReservation>();
            acc.Rooms.Add(room);

            RoomReservation roomRes = new RoomReservation();

            roomRes.EndDate   = DateTime.Now;
            roomRes.StartDate = DateTime.Now;
            roomRes.Timestamp = DateTime.Now;
            roomRes.User      = user;
            roomRes.Room      = room;
            roomRes.Id        = 1;
            //user.RoomReservations.Add(roomRes);

            Comment comm = new Comment();

            comm.Accomodation = acc;
            comm.Grade        = 4;
            comm.Text         = "Bravissimo.";
            comm.User         = user;
            comm.Id           = 1;
            //user.Comments.Add(comm);

            try
            {
                context.Accommodations.Add(acc);
                context.AccommodationTypes.Add(accType);
                context.Comments.Add(comm);
                context.Countries.Add(country);
                context.Places.Add(place);
                context.Regions.Add(region);
                context.RoomReservations.Add(roomRes);
                context.Rooms.Add(room);
                context.SaveChanges();
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message);
            }
        }
示例#4
0
        protected override void Seed(BookingApp.Models.BAContext 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. E.g.
            //
            //    context.People.AddOrUpdate(
            //      p => p.FullName,
            //      new Person { FullName = "Andrew Peters" },
            //      new Person { FullName = "Brice Lambson" },
            //      new Person { FullName = "Rowan Miller" }
            //    );
            //

            if (!context.Roles.Any(r => r.Name == "Admin"))
            {
                var store   = new RoleStore <IdentityRole>(context);
                var manager = new RoleManager <IdentityRole>(store);
                var role    = new IdentityRole {
                    Name = "Admin"
                };

                manager.Create(role);
            }

            if (!context.Roles.Any(r => r.Name == "Manager"))
            {
                var store   = new RoleStore <IdentityRole>(context);
                var manager = new RoleManager <IdentityRole>(store);
                var role    = new IdentityRole {
                    Name = "Manager"
                };

                manager.Create(role);
            }

            if (!context.Roles.Any(r => r.Name == "AppUser"))
            {
                var store   = new RoleStore <IdentityRole>(context);
                var manager = new RoleManager <IdentityRole>(store);
                var role    = new IdentityRole {
                    Name = "AppUser"
                };

                manager.Create(role);
            }

            var userStore   = new UserStore <BAIdentityUser>(context);
            var userManager = new UserManager <BAIdentityUser>(userStore);

            if (!context.Users.Any(u => u.UserName == "admin"))
            {
                var user = new BAIdentityUser()
                {
                    Id = "admin", UserName = "******", Email = "*****@*****.**", PasswordHash = BAIdentityUser.HashPassword("admin")
                };
                userManager.Create(user);
                userManager.AddToRole(user.Id, "Admin");
            }

            AccommodationType acctype = new AccommodationType();

            acctype.Id   = 88;
            acctype.Name = "Buras";

            AppUser user1 = new AppUser();

            user1.Email    = "*****@*****.**";
            user1.Id       = 0;
            user1.Password = "******";
            user1.Username = "******";

            Country country = new Country();

            country.Code = 123854;
            country.Id   = 13;
            country.Name = "Srbija";


            Place place = new Place();

            place.Id   = 2;
            place.Name = "Mesto";

            Region region = new Region();

            region.Id   = 5;
            region.Name = "Area55";
            region.m_Place.Add(place);
            region.Country = country;

            place.Region = region;

            context.Countries.Add(country);
            context.Places.Add(place);
            context.AccommodationsTypes.Add(acctype);
            context.AppUsers.Add(user1);

            Accommodation acc = new Accommodation();

            acc.Address           = "Addr";
            acc.Approved          = true;
            acc.AverageGrade      = 3;
            acc.Description       = "ey";
            acc.Id                = 16;
            acc.Latitude          = 12.2;
            acc.Longitude         = 23.25;
            acc.Name              = "Delux";
            acc.ImageURL          = "url";
            acc.Place             = place;
            acc.AccommodationType = acctype;
            //acc.m_Comment.Add(new Comment());
            //acc.m_Room.Add(new Room());
            acc.AppUser = user1;
            context.Accommodations.Add(acc);

            Comment comment = new Comment();

            comment.Grade         = 3;
            comment.Text          = "awe";
            comment.Accommodation = acc;
            comment.AppUser       = user1;

            context.Comments.Add(comment);

            Room room = new Room();

            room.BedCount      = 3;
            room.Description   = "DarkRoom Hehe";
            room.PricePerNight = 23;
            room.RoomNumber    = 7;
            room.Accommodation = acc;

            context.Rooms.Add(room);

            RoomReservation rez = new RoomReservation();

            rez.StartDate = DateTime.Now;
            rez.EndDate   = DateTime.Now;
            rez.Timestamp = DateTime.Now;
            rez.Room      = room;
            rez.AppUser   = user1;

            context.RoomReservationss.Add(rez);

            if (!context.Users.Any(u => u.UserName == "ja"))
            {
                var _appUser = context.AppUsers.FirstOrDefault(a => a.Email == "*****@*****.**");
                var user3    = new BAIdentityUser()
                {
                    Id = "ja", UserName = "******", Email = "*****@*****.**", PasswordHash = BAIdentityUser.HashPassword("ja")
                };
                userManager.Create(user3);
                userManager.AddToRole(user3.Id, "AppUser");
            }
        }