Bug Fix: #76 importing devices
This commit is contained in:
@@ -47,13 +47,20 @@ namespace Disco.Services.Devices.Importing
|
||||
}
|
||||
else if (RecordAction == EntityState.Added)
|
||||
{
|
||||
// Use 'Add Device Offline' default if available
|
||||
var deviceProfileId = Database.DiscoConfiguration.DeviceProfiles.DefaultAddDeviceOfflineDeviceProfileId;
|
||||
if (deviceProfileId == 0)
|
||||
{
|
||||
deviceProfileId = Database.DiscoConfiguration.DeviceProfiles.DefaultDeviceProfileId;
|
||||
}
|
||||
|
||||
// Create Device
|
||||
device = new Device()
|
||||
{
|
||||
SerialNumber = DeviceSerialNumber.ToUpper(),
|
||||
CreatedDate = DateTime.Now,
|
||||
AllowUnauthenticatedEnrol = true,
|
||||
DeviceProfileId = Database.DiscoConfiguration.DeviceProfiles.DefaultAddDeviceOfflineDeviceProfileId,
|
||||
DeviceProfileId = deviceProfileId,
|
||||
DeviceModelId = 1 // Default 'Unknown Device Model'
|
||||
};
|
||||
Database.Devices.Add(device);
|
||||
@@ -64,7 +71,7 @@ namespace Disco.Services.Devices.Importing
|
||||
return false;
|
||||
}
|
||||
|
||||
bool changesMade = false;
|
||||
bool changesMade = (RecordAction == EntityState.Added);
|
||||
|
||||
foreach (var field in Fields.Cast<DeviceImportFieldBase>())
|
||||
{
|
||||
|
||||
@@ -104,7 +104,10 @@ namespace Disco.Services.Devices.Importing.Fields
|
||||
{
|
||||
currentAssignment.UnassignedDate = DateTime.Now;
|
||||
}
|
||||
}
|
||||
|
||||
if (FieldAction == EntityState.Added || FieldAction == EntityState.Modified)
|
||||
{
|
||||
// Add Assignment
|
||||
if (parsedValue != null)
|
||||
{
|
||||
@@ -133,8 +136,7 @@ namespace Disco.Services.Devices.Importing.Fields
|
||||
var possibleColumns = Context.Header
|
||||
.Select((h, i) => Tuple.Create(h, i))
|
||||
.Where(h => h.Item1.Item2 == DeviceImportFieldTypes.IgnoreColumn &&
|
||||
h.Item1.Item1.IndexOf("user id", System.StringComparison.OrdinalIgnoreCase) >= 0 ||
|
||||
h.Item1.Item1.IndexOf("userid", System.StringComparison.OrdinalIgnoreCase) >= 0
|
||||
h.Item1.Item1.IndexOf("user", System.StringComparison.OrdinalIgnoreCase) >= 0
|
||||
);
|
||||
|
||||
return possibleColumns.Select(h => (int?)h.Item2).FirstOrDefault();
|
||||
|
||||
Reference in New Issue
Block a user