public async Task <Door> AddDoor(Door door)
        {
            var newEntity = await _context.Doors.AddAsync(door);

            await _context.SaveChangesAsync();

            return(newEntity.Entity);
        }
Beispiel #2
0
        public static async Task SeedAsync(DoorManagementDbContext context, ILoggerFactory loggerFactory)
        {
            try
            {
                if (!await context.Doors.AnyAsync())
                {
                    await context.Doors.AddRangeAsync(new List <Door>()
                    {
                        new Door()
                        {
                            Id = Guid.NewGuid(), Label = "Maintenance facilities", IsOpen = false, IsLocked = false
                        },
                        new Door()
                        {
                            Id = Guid.NewGuid(), Label = "Warehouse Door", IsOpen = false, IsLocked = true
                        },
                        new Door()
                        {
                            Id = Guid.NewGuid(), Label = "Corridors", IsOpen = true, IsLocked = false
                        },
                        new Door()
                        {
                            Id = Guid.NewGuid(), Label = "Terrace Door", IsOpen = true, IsLocked = false
                        },
                        new Door()
                        {
                            Id = Guid.NewGuid(), Label = "Washing Area", IsOpen = true, IsLocked = false
                        },
                        new Door()
                        {
                            Id = Guid.NewGuid(), Label = "Emergency Door", IsOpen = true, IsLocked = false
                        }
                    });

                    await context.SaveChangesAsync();
                }
            }
            catch (Exception exception)
            {
                var log = loggerFactory.CreateLogger <SeedContext>();
                log.LogError(exception.Message);
                throw;
            }
        }