private async void Load() { var historyService = Ioc.Resolve <HistoryService>(); var history = await historyService.GetHistory(); var employes = new List <Employee>(); var devices = new List <Device>(); var result = new List <HistoryDeviceEmployeeEntry>(); string сonnectionString = Path.Combine(ApplicationData.Current.LocalFolder.Path, "TestStand.sqlite"); var сonnection = new SQLiteAsyncConnection(сonnectionString); foreach (var historyItem in history) { var i = new HistoryDeviceEmployeeEntry(); var device = devices.FirstOrDefault(e => e.Id == historyItem.DeviceId); if (device == null) { device = await сonnection.Table <Device>().Where(r => r.Id == historyItem.DeviceId).FirstOrDefaultAsync(); devices.Add(device); } var employee = employes.FirstOrDefault(e => e.BadgeId == historyItem.BadgeId); if (employee == null) { employee = await сonnection.Table <Employee>().Where(r => r.BadgeId == historyItem.BadgeId).FirstOrDefaultAsync(); if (employee != null) { employes.Add(employee); } } i.Employee = employee; i.HistoryEntry = historyItem; i.Device = device; result.Add(i); } History = result.OrderByDescending(x => x.HistoryEntry.Date).ToList(); }
private async void LoadData() { var historyService = Ioc.Resolve <HistoryService>(); var history = await historyService.GetHistoryByDevice(Device.Id); var employes = new List <Employee>(); var result = new List <HistoryDeviceEmployeeEntry>(); string сonnectionString = Path.Combine(ApplicationData.Current.LocalFolder.Path, "TestStand.sqlite"); var сonnection = new SQLiteAsyncConnection(сonnectionString); foreach (var historyItem in history) { var i = new HistoryDeviceEmployeeEntry(); var employee = employes.FirstOrDefault(e => e.BadgeId == historyItem.BadgeId); if (employee == null) { employee = await сonnection.Table <Employee>().Where(r => r.BadgeId == historyItem.BadgeId).FirstOrDefaultAsync(); if (employee != null) { employes.Add(employee); } } i.Employee = employee; i.HistoryEntry = historyItem; result.Add(i); } History = result.ToList(); History.Reverse(); if (!string.IsNullOrEmpty(Device.BadgeId)) { Employee employeeWithThisDevice = await Ioc.Resolve <EmployeeService>().GetEmployeeByBadgeId(Device.BadgeId); } }