コード例 #1
0
        public async Task <ActionResult <Hotel> > AddHotel([FromBody] Hotel hotel)
        {
            if (await _hotelStore.CheckExistanceAsync(hotel.GetKey()))
            {
                return(ValidationProblem(
                           title: "Resource already exists",
                           detail: string.Format(
                               "{0} at {1},{2},{3} already exists",
                               hotel.HotelChain,
                               hotel.CountryCode,
                               hotel.Town,
                               hotel.Suburb)
                           ));
            }
            await _hotelStore.CreateAsync(hotel);

            return(CreatedAtAction(
                       nameof(GetHotelDetails),
                       hotel.GetKey(),
                       hotel));
        }
コード例 #2
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");
            }
        }