using Disco.Data.Repository; using Disco.Models.Repository; using System; using System.Collections.Generic; using System.Linq; namespace Disco.Services.Devices.Importing { internal class DeviceImportInMemoryCache : IDeviceImportCache { private DiscoDataContext Database; private Lazy> devices; private Lazy> deviceModels; private Lazy> deviceProfiles; private Lazy> deviceBatches; public DeviceImportInMemoryCache(DiscoDataContext Database) { this.Database = Database; this.devices = new Lazy>(() => Database.Devices.Include("DeviceDetails").ToList()); this.deviceModels = new Lazy>(() => Database.DeviceModels.ToList()); this.deviceProfiles = new Lazy>(() => Database.DeviceProfiles.ToList()); this.deviceBatches = new Lazy>(() => Database.DeviceBatches.ToList()); } public Device FindDevice(string DeviceSerialNumber) { return devices.Value.FirstOrDefault(d => d.SerialNumber.Equals(DeviceSerialNumber, StringComparison.OrdinalIgnoreCase)); } public IEnumerable Devices { get { return devices.Value; } } public IEnumerable DeviceModels { get { return deviceModels.Value; } } public IEnumerable DeviceProfiles { get { return deviceProfiles.Value; } } public IEnumerable DeviceBatches { get { return deviceBatches.Value; } } } }