示例#1
0
        public static async Task SeedTestUsers(UserManager <ApplicationUser> userManager, HotelStore hotelStore)
        {
            var systemAdmin = userManager.FindByNameAsync("*****@*****.**").Result;

            if (systemAdmin == null)
            {
                systemAdmin = new ApplicationUser
                {
                    Email = "*****@*****.**",
                    Role  = RoomMonitorConstants.UserRoles.SystemAdmin
                };
                var result = await userManager.CreateAsync(systemAdmin, "test");

                if (!result.Succeeded)
                {
                    throw new Exception(result.Errors.First().Description);
                }

                Log.Debug("systemAdmin created");
            }
            else
            {
                Log.Debug("systemAdmin already exists");
            }


            Hotel hotel = new Hotel {
                HotelChain = "TestHotel1", CountryCode = "GR", Town = "Athens", Suburb = "Aigaleo", NumStar = 5
            };

            if (!await hotelStore.CheckExistanceAsync(hotel.GetKey()))
            {
                await hotelStore.CreateAsync(hotel);

                Log.Debug("TestHotel1 created");
            }
            else
            {
                Log.Debug("TestHotel1 already exists");
            }


            var hotelAdmin = userManager.FindByNameAsync("*****@*****.**").Result;

            if (hotelAdmin == null)
            {
                hotelAdmin = new ApplicationUser
                {
                    Email       = "*****@*****.**",
                    Role        = RoomMonitorConstants.UserRoles.HotelAdmin,
                    HotelChain  = hotel.HotelChain,
                    CountryCode = hotel.CountryCode,
                    Town        = hotel.Town,
                    Suburb      = hotel.Suburb
                };
                var result = await userManager.CreateAsync(hotelAdmin, "test");

                if (!result.Succeeded)
                {
                    throw new Exception(result.Errors.First().Description);
                }

                Log.Debug("hotelAdmin created");
            }
            else
            {
                Log.Debug("hotelAdmin already exists");
            }

            var hotelEmployee = userManager.FindByNameAsync("*****@*****.**").Result;

            if (hotelEmployee == null)
            {
                hotelEmployee = new ApplicationUser
                {
                    Email       = "*****@*****.**",
                    Role        = RoomMonitorConstants.UserRoles.HotelEmployee,
                    HotelChain  = hotel.HotelChain,
                    CountryCode = hotel.CountryCode,
                    Town        = hotel.Town,
                    Suburb      = hotel.Suburb
                };
                var result = await userManager.CreateAsync(hotelEmployee, "test");

                if (!result.Succeeded)
                {
                    throw new Exception(result.Errors.First().Description);
                }

                Log.Debug("hotelEmployee created");
            }
            else
            {
                Log.Debug("hotelEmployee already exists");
            }
        }
示例#2
0
 public HotelController(HotelStore hotelStore)
 {
     _hotelStore = hotelStore;
 }