private async void Init(string serialNumber) { CurrentDevice = new Models.Device.Device(); MultiDevices = new ObservableCollection <Models.Device.Device>(); IsEdit = !string.IsNullOrEmpty(serialNumber); if (IsEdit) { await GetAndAssignDevice(serialNumber); CurrentDevice = Device; } else { Device = new Models.Device.Device(); DeviceEvents = new ObservableCollection <DeviceEvent>(); } await GetDeviceMetadata(); }
private async Task <bool> VaildateChageAsync(Models.Device.Device device) { bool valid = true; if (string.IsNullOrEmpty(device.SerialNumber)) { Notify(ErrorCode.ValidationError, $"SerialNumber is not set in 'Individual device info' tab."); valid = false; } if (device.Model == null) { Notify(ErrorCode.ValidationError, $"Model is not set in 'Individual device info' tab."); valid = false; } if (device.OwnedBy == null) { Notify(ErrorCode.ValidationError, $"Owner of the device is not set in 'Individual device info' tab."); valid = false; } if (device.AcquisitionDate == DateTime.MinValue) { Notify(ErrorCode.ValidationError, $"Acquisition date of the device is not set in 'Individual device info' tab."); valid = false; } if (device.AcquisitionDate > DateTime.Now) { Notify(ErrorCode.ValidationError, $"Acquisition date of the device cannot be set to future, in 'Individual device info' tab."); valid = false; } if (MultiDevices.Count == 0 && !IsEdit) { Notify(ErrorCode.ValidationError, $"List of the device individual info cannot be empty , in 'Individual device info' tab."); valid = false; } if (device.Status == null) { Notify(ErrorCode.ValidationError, $"Acquisition status field cannot be empty, in 'Common data' tab."); valid = false; } if (device.InitialLocation == null) { Notify(ErrorCode.ValidationError, $"Device owner field cannot be empty, in 'Common data' tab."); valid = false; } if (device.SfDate == DateTime.MinValue) { Notify(ErrorCode.ValidationError, $"Invoice date of the device is not set in 'Common data' tab."); valid = false; } if (device.SfDate > DateTime.Now) { Notify(ErrorCode.ValidationError, $"Invoice date of the device cannot be set to future, in 'Common data' tab."); valid = false; } if (device.DeviceEvents == null || device.DeviceEventsCount == 0) { Notify(ErrorCode.ValidationError, $"Device event cannot be empty, in 'Device events' tab."); valid = false; } else { for (var i = 0; i < device.DeviceEventsCount; i++) { if (device.DeviceEvents[i].Status == null) { Notify(ErrorCode.ValidationError, $"Device event {i + 1} 'Event status' field cannot be empty, in 'Device events' tab."); valid = false; } if (device.DeviceEvents[i].Location == null) { Notify(ErrorCode.ValidationError, $"Device event {i + 1} 'Current client' field cannot be empty, in 'Device events' tab."); valid = false; } if (device.DeviceEvents[i].Date == DateTime.MinValue) { Notify(ErrorCode.ValidationError, $"Device event {i + 1} 'Date of event' field cannot be empty, in 'Device events' tab."); valid = false; } if (device.DeviceEvents[i].Date > DateTime.Now) { Notify(ErrorCode.ValidationError, $"Device event {i + 1} 'Date of event' field cannot be set in the future, in 'Device events' tab."); valid = false; } } } if (await AnyDevicesWithSerialNumber(device.SerialNumber) || MultiDevices.Count(x => x.SerialNumber == device.SerialNumber) > 1) { Notify($"Serial number '{device.SerialNumber}' is not unique"); } return(valid); }