Feature #33: Enhanced Device Importing
Dynamic device importing. better input parsing and 5 additional import fields.
This commit is contained in:
@@ -0,0 +1,25 @@
|
||||
using Disco.Models.Services.Devices.Importing;
|
||||
using Disco.Models.UI.Device;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.ComponentModel.DataAnnotations;
|
||||
using System.Linq;
|
||||
|
||||
namespace Disco.Web.Models.Device
|
||||
{
|
||||
public class ImportHeadersModel : DeviceImportHeadersModel
|
||||
{
|
||||
public IDeviceImportContext Context { get; set; }
|
||||
|
||||
public IEnumerable<Tuple<DeviceImportFieldTypes, string>> HeaderTypes { get; set; }
|
||||
|
||||
public ImportHeadersModel()
|
||||
{
|
||||
HeaderTypes = typeof(DeviceImportFieldTypes)
|
||||
.GetFields()
|
||||
.Select(p => Tuple.Create(p, (DisplayAttribute)p.GetCustomAttributes(typeof(DisplayAttribute), false).FirstOrDefault()))
|
||||
.Where(p => p.Item2 != null)
|
||||
.Select(p => Tuple.Create((DeviceImportFieldTypes)p.Item1.GetRawConstantValue(), p.Item2.Name)).ToList();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,4 +1,5 @@
|
||||
using Disco.Models.Repository;
|
||||
using Disco.Models.Services.Devices.Importing;
|
||||
using Disco.Models.UI.Device;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
@@ -10,11 +11,29 @@ namespace Disco.Web.Models.Device
|
||||
{
|
||||
public class ImportModel : DeviceImportModel
|
||||
{
|
||||
[Required, Display(Name="CSV Import File")]
|
||||
[Required, Display(Name = "CSV Import File")]
|
||||
public HttpPostedFileBase ImportFile { get; set; }
|
||||
|
||||
[Required, Display(Name = "Has Header")]
|
||||
public bool HasHeader { get; set; }
|
||||
|
||||
public IDeviceImportContext CompletedImportSessionContext { get; set; }
|
||||
|
||||
public List<DeviceModel> DeviceModels { get; set; }
|
||||
public List<DeviceProfile> DeviceProfiles { get; set; }
|
||||
public List<DeviceBatch> DeviceBatches { get; set; }
|
||||
|
||||
public IEnumerable<Tuple<string, string, string>> HeaderTypes { get; set; }
|
||||
|
||||
public ImportModel()
|
||||
{
|
||||
HasHeader = true;
|
||||
|
||||
HeaderTypes = typeof(DeviceImportFieldTypes)
|
||||
.GetFields()
|
||||
.Select(p => Tuple.Create(p, (DisplayAttribute)p.GetCustomAttributes(typeof(DisplayAttribute), false).FirstOrDefault()))
|
||||
.Where(p => p.Item2 != null && p.Item1.Name != DeviceImportFieldTypes.IgnoreColumn.ToString())
|
||||
.Select(p => Tuple.Create(p.Item1.Name, p.Item2.Name, p.Item2.Description)).ToList();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,26 +1,35 @@
|
||||
using Disco.Models.BI.Device;
|
||||
using Disco.Models.Services.Devices.Importing;
|
||||
using Disco.Models.UI.Device;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.ComponentModel.DataAnnotations;
|
||||
using System.Linq;
|
||||
using System.Web;
|
||||
|
||||
namespace Disco.Web.Models.Device
|
||||
{
|
||||
public class ImportReviewModel : DeviceImportReviewModel
|
||||
{
|
||||
public string ImportParseTaskId { get; set; }
|
||||
public string ImportFilename { get; set; }
|
||||
public List<ImportDevice> ImportDevices { get; set; }
|
||||
public IDeviceImportContext Context { get; set; }
|
||||
|
||||
public static ImportReviewModel FromImportDeviceSession(ImportDeviceSession session)
|
||||
public int StatisticErrorRecords { get; set; }
|
||||
public int StatisticNewRecords { get; set; }
|
||||
public int StatisticModifiedRecords { get; set; }
|
||||
public int StatisticUnmodifiedRecords { get; set; }
|
||||
|
||||
public int StatisticImportRecords
|
||||
{
|
||||
return new ImportReviewModel()
|
||||
{
|
||||
ImportParseTaskId = session.ImportParseTaskId,
|
||||
ImportFilename = session.ImportFilename,
|
||||
ImportDevices = session.ImportDevices
|
||||
};
|
||||
get { return this.StatisticNewRecords + StatisticModifiedRecords; }
|
||||
}
|
||||
|
||||
public IEnumerable<Tuple<DeviceImportFieldTypes, string>> HeaderTypes { get; set; }
|
||||
|
||||
public ImportReviewModel()
|
||||
{
|
||||
HeaderTypes = typeof(DeviceImportFieldTypes)
|
||||
.GetFields()
|
||||
.Select(p => Tuple.Create(p, (DisplayAttribute)p.GetCustomAttributes(typeof(DisplayAttribute), false).FirstOrDefault()))
|
||||
.Where(p => p.Item2 != null)
|
||||
.Select(p => Tuple.Create((DeviceImportFieldTypes)p.Item1.GetRawConstantValue(), p.Item2.Name)).ToList();
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user