public static async Task AddTestData(
            HotelApiDbContext context,
            IDateLogicService dateLogicService,
            UserManager <UserEntity> userManager)
        {
            if (context.Rooms.Any())
            {
                // Already has data
                return;
            }

            context.Rooms.Add(new RoomEntity
            {
                Id   = Guid.Parse("ee2b83be-91db-4de5-8122-35a9e9195976"),
                Name = "Driscoll Suite",
                Rate = 23959
            });

            var oxford = context.Rooms.Add(new RoomEntity
            {
                Id   = Guid.Parse("301df04d-8679-4b1b-ab92-0a586ae53d08"),
                Name = "Oxford Suite",
                Rate = 10119,
            }).Entity;

            var today = DateTimeOffset.Now;
            var start = dateLogicService.AlignStartTime(today);
            var end   = start.Add(dateLogicService.GetMinimumStay());

            var adminUser = userManager.Users
                            .SingleOrDefault(u => u.Email == "*****@*****.**");

            context.Bookings.Add(new BookingEntity
            {
                Id        = Guid.Parse("2eac8dea-2749-42b3-9d21-8eb2fc0fd6bd"),
                Room      = oxford,
                CreatedAt = DateTimeOffset.UtcNow,
                StartAt   = start,
                EndAt     = end,
                Total     = oxford.Rate,
                User      = adminUser
            });

            await context.SaveChangesAsync();
        }
        public static async Task AddTestDataAsync(HotelApiDbContext context, IDateLogicService dateLogicService) //zabezpecuje seedovanie DB
        {
            if (context.Rooms.Any())
            {
                //already has data
                return;
            }

            var oxford = context.Rooms.Add(new RoomEntity
            {
                Id   = Guid.Parse("301df04d-8679-4b1b-ab92-0a586ae53d08"),
                Name = "Oxford Suite",
                Rate = 10119,
            }).Entity;

            context.Rooms.Add(new RoomEntity
            {
                Id   = Guid.Parse("ee2b83be-91db-4de5-8122-35a9e9195976"),
                Name = "Driscoll Suite",
                Rate = 23959
            });

            var today = DateTimeOffset.Now;
            var start = dateLogicService.AlignStartTime(today);
            var end   = start.Add(dateLogicService.GetMinimumStay());

            context.Bookings.Add(new BookingEntity
            {
                Id        = Guid.Parse("2eac8dea-2749-42b3-9d21-8eb2fc0fd6bd"),
                Room      = oxford,
                CreatedAt = DateTimeOffset.UtcNow,
                StartAt   = start,
                EndAt     = end,
                Total     = oxford.Rate,
            });

            await context.SaveChangesAsync();
        }
Esempio n. 3
0
        public static async Task AddTestData(HotelApiDbContext context)
        {
            if (context.Rooms.Any())
            {
                return;
            }

            context.Rooms.Add(new RoomEntity
            {
                Id   = Guid.Parse("301df04d-8679-4b1b-ab92-0a586ae53d08"),
                Name = "Oxford Suite",
                Rate = 10119,
            });

            context.Rooms.Add(new RoomEntity
            {
                Id   = Guid.Parse("ee2b83be-91db-4de5-8122-35a9e9195976"),
                Name = "Driscoll Suite",
                Rate = 23959
            });

            await context.SaveChangesAsync();
        }