GIT: perform LF normalization
This commit is contained in:
@@ -1,17 +1,17 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Web;
|
||||
using System.ComponentModel.DataAnnotations;
|
||||
using System.Web.Mvc;
|
||||
|
||||
namespace Disco.Web.Models.Device
|
||||
{
|
||||
public class AddOfflineModel
|
||||
{
|
||||
public Disco.Models.Repository.Device Device { get; set; }
|
||||
public List<Disco.Models.Repository.DeviceProfile> DeviceProfiles { get; set; }
|
||||
public List<SelectListItem> DeviceBatches { get; set; }
|
||||
public int DefaultDeviceProfileId { get; set; }
|
||||
}
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Web;
|
||||
using System.ComponentModel.DataAnnotations;
|
||||
using System.Web.Mvc;
|
||||
|
||||
namespace Disco.Web.Models.Device
|
||||
{
|
||||
public class AddOfflineModel
|
||||
{
|
||||
public Disco.Models.Repository.Device Device { get; set; }
|
||||
public List<Disco.Models.Repository.DeviceProfile> DeviceProfiles { get; set; }
|
||||
public List<SelectListItem> DeviceBatches { get; set; }
|
||||
public int DefaultDeviceProfileId { get; set; }
|
||||
}
|
||||
}
|
||||
@@ -1,111 +1,111 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.ComponentModel.DataAnnotations;
|
||||
using System.Data.SqlClient;
|
||||
using System.Linq;
|
||||
using System.Web;
|
||||
using System.Web.Mvc;
|
||||
|
||||
namespace Disco.Web.Models.InitialConfig
|
||||
{
|
||||
public class DatabaseModel
|
||||
{
|
||||
public DatabaseModel()
|
||||
{
|
||||
// Set Defaults
|
||||
this.Server = "(local)";
|
||||
this.DatabaseName = "Disco";
|
||||
this.AuthMethod = "SSPI";
|
||||
}
|
||||
|
||||
public static DatabaseModel FromConnectionString(string ConnectionString)
|
||||
{
|
||||
var result = new DatabaseModel();
|
||||
|
||||
try
|
||||
{
|
||||
var csb = new SqlConnectionStringBuilder(ConnectionString);
|
||||
|
||||
if (!string.IsNullOrEmpty(csb.DataSource))
|
||||
result.Server = csb.DataSource;
|
||||
if (!string.IsNullOrEmpty(csb.InitialCatalog))
|
||||
result.DatabaseName = csb.InitialCatalog;
|
||||
if (csb.IntegratedSecurity)
|
||||
{
|
||||
result.AuthMethod = "SSPI";
|
||||
}
|
||||
else
|
||||
{
|
||||
result.AuthMethod = "SQL";
|
||||
result.Auth_SQL_Username = csb.UserID;
|
||||
result.Auth_SQL_Password = csb.Password;
|
||||
}
|
||||
}
|
||||
catch (Exception)
|
||||
{
|
||||
// Ignore Parsing errors
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
public SqlConnectionStringBuilder ToConnectionString()
|
||||
{
|
||||
var csb = new SqlConnectionStringBuilder()
|
||||
{
|
||||
DataSource = this.Server,
|
||||
InitialCatalog = this.DatabaseName,
|
||||
IntegratedSecurity = (this.AuthMethod.Equals("SSPI", StringComparison.InvariantCultureIgnoreCase)),
|
||||
UserID = (this.AuthMethod.Equals("SQL", StringComparison.InvariantCultureIgnoreCase)) ? this.Auth_SQL_Username : string.Empty,
|
||||
Password = (this.AuthMethod.Equals("SQL", StringComparison.InvariantCultureIgnoreCase)) ? this.Auth_SQL_Password : string.Empty,
|
||||
ApplicationName = "Disco WebApp",
|
||||
MultipleActiveResultSets = true,
|
||||
Pooling = true
|
||||
};
|
||||
|
||||
return csb;
|
||||
}
|
||||
|
||||
[Required(ErrorMessage = "The Server name is required")]
|
||||
public string Server { get; set; }
|
||||
[Required(ErrorMessage = "The Database name is required")]
|
||||
public string DatabaseName { get; set; }
|
||||
[Required(ErrorMessage = "The Authentication Method is required")]
|
||||
public string AuthMethod { get; set; }
|
||||
|
||||
[CustomValidation(typeof(DatabaseModel), "SqlAuthRequired", ErrorMessage = "When using SQL Authentication a Username is required")]
|
||||
public string Auth_SQL_Username { get; set; }
|
||||
[DataType(DataType.Password), CustomValidation(typeof(DatabaseModel), "SqlAuthRequired", ErrorMessage="When using SQL Authentication a Password is required")]
|
||||
public string Auth_SQL_Password { get; set; }
|
||||
|
||||
public List<SelectListItem> AuthMethods
|
||||
{
|
||||
get
|
||||
{
|
||||
return new List<SelectListItem>(){
|
||||
new SelectListItem(){
|
||||
Value="SSPI", Text="Integrated Authentication", Selected=true
|
||||
},
|
||||
new SelectListItem(){
|
||||
Value="SQL", Text="SQL Authentication", Selected=false
|
||||
}
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
public static ValidationResult SqlAuthRequired(object value, ValidationContext validationContext)
|
||||
{
|
||||
var instance = validationContext.ObjectInstance as DatabaseModel;
|
||||
|
||||
if (instance != null && instance.AuthMethod != null && instance.AuthMethod.Equals("SQL", StringComparison.InvariantCultureIgnoreCase))
|
||||
{
|
||||
var stringValue = value as string;
|
||||
if (string.IsNullOrWhiteSpace(stringValue))
|
||||
return null; // Invalid
|
||||
}
|
||||
|
||||
return ValidationResult.Success;
|
||||
}
|
||||
|
||||
}
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.ComponentModel.DataAnnotations;
|
||||
using System.Data.SqlClient;
|
||||
using System.Linq;
|
||||
using System.Web;
|
||||
using System.Web.Mvc;
|
||||
|
||||
namespace Disco.Web.Models.InitialConfig
|
||||
{
|
||||
public class DatabaseModel
|
||||
{
|
||||
public DatabaseModel()
|
||||
{
|
||||
// Set Defaults
|
||||
this.Server = "(local)";
|
||||
this.DatabaseName = "Disco";
|
||||
this.AuthMethod = "SSPI";
|
||||
}
|
||||
|
||||
public static DatabaseModel FromConnectionString(string ConnectionString)
|
||||
{
|
||||
var result = new DatabaseModel();
|
||||
|
||||
try
|
||||
{
|
||||
var csb = new SqlConnectionStringBuilder(ConnectionString);
|
||||
|
||||
if (!string.IsNullOrEmpty(csb.DataSource))
|
||||
result.Server = csb.DataSource;
|
||||
if (!string.IsNullOrEmpty(csb.InitialCatalog))
|
||||
result.DatabaseName = csb.InitialCatalog;
|
||||
if (csb.IntegratedSecurity)
|
||||
{
|
||||
result.AuthMethod = "SSPI";
|
||||
}
|
||||
else
|
||||
{
|
||||
result.AuthMethod = "SQL";
|
||||
result.Auth_SQL_Username = csb.UserID;
|
||||
result.Auth_SQL_Password = csb.Password;
|
||||
}
|
||||
}
|
||||
catch (Exception)
|
||||
{
|
||||
// Ignore Parsing errors
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
public SqlConnectionStringBuilder ToConnectionString()
|
||||
{
|
||||
var csb = new SqlConnectionStringBuilder()
|
||||
{
|
||||
DataSource = this.Server,
|
||||
InitialCatalog = this.DatabaseName,
|
||||
IntegratedSecurity = (this.AuthMethod.Equals("SSPI", StringComparison.InvariantCultureIgnoreCase)),
|
||||
UserID = (this.AuthMethod.Equals("SQL", StringComparison.InvariantCultureIgnoreCase)) ? this.Auth_SQL_Username : string.Empty,
|
||||
Password = (this.AuthMethod.Equals("SQL", StringComparison.InvariantCultureIgnoreCase)) ? this.Auth_SQL_Password : string.Empty,
|
||||
ApplicationName = "Disco WebApp",
|
||||
MultipleActiveResultSets = true,
|
||||
Pooling = true
|
||||
};
|
||||
|
||||
return csb;
|
||||
}
|
||||
|
||||
[Required(ErrorMessage = "The Server name is required")]
|
||||
public string Server { get; set; }
|
||||
[Required(ErrorMessage = "The Database name is required")]
|
||||
public string DatabaseName { get; set; }
|
||||
[Required(ErrorMessage = "The Authentication Method is required")]
|
||||
public string AuthMethod { get; set; }
|
||||
|
||||
[CustomValidation(typeof(DatabaseModel), "SqlAuthRequired", ErrorMessage = "When using SQL Authentication a Username is required")]
|
||||
public string Auth_SQL_Username { get; set; }
|
||||
[DataType(DataType.Password), CustomValidation(typeof(DatabaseModel), "SqlAuthRequired", ErrorMessage="When using SQL Authentication a Password is required")]
|
||||
public string Auth_SQL_Password { get; set; }
|
||||
|
||||
public List<SelectListItem> AuthMethods
|
||||
{
|
||||
get
|
||||
{
|
||||
return new List<SelectListItem>(){
|
||||
new SelectListItem(){
|
||||
Value="SSPI", Text="Integrated Authentication", Selected=true
|
||||
},
|
||||
new SelectListItem(){
|
||||
Value="SQL", Text="SQL Authentication", Selected=false
|
||||
}
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
public static ValidationResult SqlAuthRequired(object value, ValidationContext validationContext)
|
||||
{
|
||||
var instance = validationContext.ObjectInstance as DatabaseModel;
|
||||
|
||||
if (instance != null && instance.AuthMethod != null && instance.AuthMethod.Equals("SQL", StringComparison.InvariantCultureIgnoreCase))
|
||||
{
|
||||
var stringValue = value as string;
|
||||
if (string.IsNullOrWhiteSpace(stringValue))
|
||||
return null; // Invalid
|
||||
}
|
||||
|
||||
return ValidationResult.Success;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
@@ -1,181 +1,181 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.ComponentModel.DataAnnotations;
|
||||
using System.Diagnostics;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Security;
|
||||
using System.Security.Permissions;
|
||||
using System.Security.Principal;
|
||||
using System.Web;
|
||||
|
||||
namespace Disco.Web.Models.InitialConfig
|
||||
{
|
||||
public class FileStoreModel
|
||||
{
|
||||
public FileStoreModel()
|
||||
{
|
||||
DirectoryModel = FileStoreModel.FileStoreDirectoryModel.DirectoryRoots();
|
||||
}
|
||||
|
||||
[Required(), CustomValidation(typeof(FileStoreModel), "DirectoryPermissionRequired")]
|
||||
public string FileStoreLocation { get; set; }
|
||||
|
||||
public FileStoreDirectoryModel DirectoryModel { get; set; }
|
||||
|
||||
public void ExpandDirectoryModel()
|
||||
{
|
||||
if (!string.IsNullOrWhiteSpace(FileStoreLocation))
|
||||
{
|
||||
var branches = this.FileStoreLocation.ToUpper().Split(Path.DirectorySeparatorChar);
|
||||
var branchesCase = this.FileStoreLocation.Split(Path.DirectorySeparatorChar);
|
||||
FileStoreDirectoryModel branchModel;
|
||||
FileStoreDirectoryModel branchParent = this.DirectoryModel;
|
||||
for (int i = 0; i < branches.Length; i++)
|
||||
{
|
||||
var branch = branches[i];
|
||||
if (branchParent.SubDirectories.TryGetValue(branch, out branchModel))
|
||||
{
|
||||
branchModel.ExpandSubDirectories();
|
||||
}
|
||||
else
|
||||
{
|
||||
// New
|
||||
branchModel = FileStoreDirectoryModel.FromNew(branchesCase[i], Path.Combine(branchParent.Path, branchesCase[i]));
|
||||
branchParent.SubDirectories.Add(branchModel.Name.ToUpper(), branchModel);
|
||||
}
|
||||
|
||||
branchParent = branchModel;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static ValidationResult DirectoryPermissionRequired(object value, ValidationContext validationContext)
|
||||
{
|
||||
var instance = validationContext.ObjectInstance as FileStoreModel;
|
||||
|
||||
if (instance != null && !string.IsNullOrEmpty(instance.FileStoreLocation))
|
||||
{
|
||||
var stringValue = value as string;
|
||||
|
||||
DirectoryInfo info = new DirectoryInfo(stringValue);
|
||||
|
||||
if (!info.Exists)
|
||||
{
|
||||
// Try and Create
|
||||
try
|
||||
{
|
||||
info.Create();
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
return new ValidationResult(string.Format("Unable to Create Directory '{0}'; [{1}] {2}", info.FullName, ex.GetType().Name, ex.Message));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return ValidationResult.Success;
|
||||
}
|
||||
|
||||
|
||||
public class FileStoreDirectoryModel
|
||||
{
|
||||
public string Name { get; set; }
|
||||
public string Path { get; set; }
|
||||
public bool IsNew { get; set; }
|
||||
public bool Selectable { get; set; }
|
||||
public Dictionary<string, FileStoreDirectoryModel> SubDirectories { get; set; }
|
||||
|
||||
internal static FileStoreDirectoryModel FromInfo(DirectoryInfo info)
|
||||
{
|
||||
return new FileStoreDirectoryModel()
|
||||
{
|
||||
Name = info.Name,
|
||||
Path = info.FullName,
|
||||
IsNew = false,
|
||||
Selectable = (info.Root.Name != info.Name)
|
||||
};
|
||||
}
|
||||
internal static FileStoreDirectoryModel FromNew(string Name, string FullPath)
|
||||
{
|
||||
return new FileStoreDirectoryModel()
|
||||
{
|
||||
Name = Name,
|
||||
Path = FullPath,
|
||||
IsNew = true,
|
||||
Selectable = true,
|
||||
SubDirectories = new Dictionary<string, FileStoreDirectoryModel>()
|
||||
};
|
||||
}
|
||||
internal static FileStoreDirectoryModel FromInfo(DriveInfo info)
|
||||
{
|
||||
return new FileStoreDirectoryModel()
|
||||
{
|
||||
Name = info.Name.Substring(0, 2),
|
||||
Path = info.RootDirectory.Name,
|
||||
IsNew = false,
|
||||
Selectable = false
|
||||
};
|
||||
}
|
||||
internal static FileStoreDirectoryModel FromPath(string DirectoryPath, bool ExpandSubDirectories)
|
||||
{
|
||||
DirectoryInfo info = new DirectoryInfo(DirectoryPath);
|
||||
|
||||
if (info.Exists)
|
||||
{
|
||||
var fsd = FromInfo(info);
|
||||
|
||||
if (ExpandSubDirectories)
|
||||
fsd.ExpandSubDirectories();
|
||||
|
||||
return fsd;
|
||||
}
|
||||
else
|
||||
return null;
|
||||
}
|
||||
|
||||
internal static FileStoreDirectoryModel DirectoryRoots()
|
||||
{
|
||||
var root = new FileStoreDirectoryModel()
|
||||
{
|
||||
Name = "ROOT",
|
||||
Path = null,
|
||||
IsNew = false,
|
||||
Selectable = false,
|
||||
SubDirectories = new Dictionary<string, FileStoreDirectoryModel>()
|
||||
};
|
||||
|
||||
foreach (var driveInfo in DriveInfo.GetDrives())
|
||||
{
|
||||
if (driveInfo.DriveType == DriveType.Fixed)
|
||||
root.SubDirectories.Add(driveInfo.Name.Substring(0, 2).ToUpper(), FileStoreDirectoryModel.FromInfo(driveInfo));
|
||||
}
|
||||
|
||||
return root;
|
||||
}
|
||||
|
||||
internal void ExpandSubDirectories()
|
||||
{
|
||||
if (this.SubDirectories == null)
|
||||
{
|
||||
this.SubDirectories = new Dictionary<string, FileStoreDirectoryModel>();
|
||||
if (!this.IsNew)
|
||||
{
|
||||
var dirInfo = new DirectoryInfo(Path);
|
||||
if (dirInfo.Exists)
|
||||
{
|
||||
foreach (var subDir in dirInfo.EnumerateDirectories())
|
||||
{
|
||||
this.SubDirectories.Add(subDir.Name.ToUpper(), FileStoreDirectoryModel.FromInfo(subDir));
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
this.IsNew = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.ComponentModel.DataAnnotations;
|
||||
using System.Diagnostics;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Security;
|
||||
using System.Security.Permissions;
|
||||
using System.Security.Principal;
|
||||
using System.Web;
|
||||
|
||||
namespace Disco.Web.Models.InitialConfig
|
||||
{
|
||||
public class FileStoreModel
|
||||
{
|
||||
public FileStoreModel()
|
||||
{
|
||||
DirectoryModel = FileStoreModel.FileStoreDirectoryModel.DirectoryRoots();
|
||||
}
|
||||
|
||||
[Required(), CustomValidation(typeof(FileStoreModel), "DirectoryPermissionRequired")]
|
||||
public string FileStoreLocation { get; set; }
|
||||
|
||||
public FileStoreDirectoryModel DirectoryModel { get; set; }
|
||||
|
||||
public void ExpandDirectoryModel()
|
||||
{
|
||||
if (!string.IsNullOrWhiteSpace(FileStoreLocation))
|
||||
{
|
||||
var branches = this.FileStoreLocation.ToUpper().Split(Path.DirectorySeparatorChar);
|
||||
var branchesCase = this.FileStoreLocation.Split(Path.DirectorySeparatorChar);
|
||||
FileStoreDirectoryModel branchModel;
|
||||
FileStoreDirectoryModel branchParent = this.DirectoryModel;
|
||||
for (int i = 0; i < branches.Length; i++)
|
||||
{
|
||||
var branch = branches[i];
|
||||
if (branchParent.SubDirectories.TryGetValue(branch, out branchModel))
|
||||
{
|
||||
branchModel.ExpandSubDirectories();
|
||||
}
|
||||
else
|
||||
{
|
||||
// New
|
||||
branchModel = FileStoreDirectoryModel.FromNew(branchesCase[i], Path.Combine(branchParent.Path, branchesCase[i]));
|
||||
branchParent.SubDirectories.Add(branchModel.Name.ToUpper(), branchModel);
|
||||
}
|
||||
|
||||
branchParent = branchModel;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static ValidationResult DirectoryPermissionRequired(object value, ValidationContext validationContext)
|
||||
{
|
||||
var instance = validationContext.ObjectInstance as FileStoreModel;
|
||||
|
||||
if (instance != null && !string.IsNullOrEmpty(instance.FileStoreLocation))
|
||||
{
|
||||
var stringValue = value as string;
|
||||
|
||||
DirectoryInfo info = new DirectoryInfo(stringValue);
|
||||
|
||||
if (!info.Exists)
|
||||
{
|
||||
// Try and Create
|
||||
try
|
||||
{
|
||||
info.Create();
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
return new ValidationResult(string.Format("Unable to Create Directory '{0}'; [{1}] {2}", info.FullName, ex.GetType().Name, ex.Message));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return ValidationResult.Success;
|
||||
}
|
||||
|
||||
|
||||
public class FileStoreDirectoryModel
|
||||
{
|
||||
public string Name { get; set; }
|
||||
public string Path { get; set; }
|
||||
public bool IsNew { get; set; }
|
||||
public bool Selectable { get; set; }
|
||||
public Dictionary<string, FileStoreDirectoryModel> SubDirectories { get; set; }
|
||||
|
||||
internal static FileStoreDirectoryModel FromInfo(DirectoryInfo info)
|
||||
{
|
||||
return new FileStoreDirectoryModel()
|
||||
{
|
||||
Name = info.Name,
|
||||
Path = info.FullName,
|
||||
IsNew = false,
|
||||
Selectable = (info.Root.Name != info.Name)
|
||||
};
|
||||
}
|
||||
internal static FileStoreDirectoryModel FromNew(string Name, string FullPath)
|
||||
{
|
||||
return new FileStoreDirectoryModel()
|
||||
{
|
||||
Name = Name,
|
||||
Path = FullPath,
|
||||
IsNew = true,
|
||||
Selectable = true,
|
||||
SubDirectories = new Dictionary<string, FileStoreDirectoryModel>()
|
||||
};
|
||||
}
|
||||
internal static FileStoreDirectoryModel FromInfo(DriveInfo info)
|
||||
{
|
||||
return new FileStoreDirectoryModel()
|
||||
{
|
||||
Name = info.Name.Substring(0, 2),
|
||||
Path = info.RootDirectory.Name,
|
||||
IsNew = false,
|
||||
Selectable = false
|
||||
};
|
||||
}
|
||||
internal static FileStoreDirectoryModel FromPath(string DirectoryPath, bool ExpandSubDirectories)
|
||||
{
|
||||
DirectoryInfo info = new DirectoryInfo(DirectoryPath);
|
||||
|
||||
if (info.Exists)
|
||||
{
|
||||
var fsd = FromInfo(info);
|
||||
|
||||
if (ExpandSubDirectories)
|
||||
fsd.ExpandSubDirectories();
|
||||
|
||||
return fsd;
|
||||
}
|
||||
else
|
||||
return null;
|
||||
}
|
||||
|
||||
internal static FileStoreDirectoryModel DirectoryRoots()
|
||||
{
|
||||
var root = new FileStoreDirectoryModel()
|
||||
{
|
||||
Name = "ROOT",
|
||||
Path = null,
|
||||
IsNew = false,
|
||||
Selectable = false,
|
||||
SubDirectories = new Dictionary<string, FileStoreDirectoryModel>()
|
||||
};
|
||||
|
||||
foreach (var driveInfo in DriveInfo.GetDrives())
|
||||
{
|
||||
if (driveInfo.DriveType == DriveType.Fixed)
|
||||
root.SubDirectories.Add(driveInfo.Name.Substring(0, 2).ToUpper(), FileStoreDirectoryModel.FromInfo(driveInfo));
|
||||
}
|
||||
|
||||
return root;
|
||||
}
|
||||
|
||||
internal void ExpandSubDirectories()
|
||||
{
|
||||
if (this.SubDirectories == null)
|
||||
{
|
||||
this.SubDirectories = new Dictionary<string, FileStoreDirectoryModel>();
|
||||
if (!this.IsNew)
|
||||
{
|
||||
var dirInfo = new DirectoryInfo(Path);
|
||||
if (dirInfo.Exists)
|
||||
{
|
||||
foreach (var subDir in dirInfo.EnumerateDirectories())
|
||||
{
|
||||
this.SubDirectories.Add(subDir.Name.ToUpper(), FileStoreDirectoryModel.FromInfo(subDir));
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
this.IsNew = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,154 +1,154 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Web;
|
||||
using Disco.Models;
|
||||
using System.ComponentModel.DataAnnotations;
|
||||
using Disco.Data.Repository;
|
||||
|
||||
namespace Disco.Web.Models.Job
|
||||
{
|
||||
[CustomValidation(typeof(CreateModelValidation), "ValidateCreateModel")]
|
||||
public class CreateModelOld
|
||||
{
|
||||
private Disco.Models.Repository.Device _Device;
|
||||
private Disco.Models.Repository.User _User;
|
||||
|
||||
public Disco.Models.Repository.Device Device
|
||||
{
|
||||
get
|
||||
{
|
||||
return _Device;
|
||||
}
|
||||
set
|
||||
{
|
||||
_Device = value;
|
||||
DeviceSerialNumber = value.SerialNumber;
|
||||
}
|
||||
}
|
||||
public Disco.Models.Repository.User User
|
||||
{
|
||||
get
|
||||
{
|
||||
return _User;
|
||||
}
|
||||
set
|
||||
{
|
||||
_User = value;
|
||||
UserId = value.Id;
|
||||
}
|
||||
}
|
||||
|
||||
public string DeviceSerialNumber { get; set; }
|
||||
public string UserId { get; set; }
|
||||
|
||||
[Required]
|
||||
public string Type { get; set; }
|
||||
[Required]
|
||||
public List<string> SubTypes { get; set; }
|
||||
|
||||
public List<Disco.Models.Repository.JobType> JobTypes { get; set; }
|
||||
public List<Disco.Models.Repository.JobSubType> JobSubTypes { get; set; }
|
||||
|
||||
public Disco.Models.Repository.JobType GetJobType
|
||||
{
|
||||
get
|
||||
{
|
||||
if (!string.IsNullOrEmpty(this.Type))
|
||||
{
|
||||
return this.JobTypes.FirstOrDefault(m => m.Id == this.Type);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
||||
public List<Disco.Models.Repository.JobSubType> GetJobSubTypes
|
||||
{
|
||||
get
|
||||
{
|
||||
if (SubTypes != null)
|
||||
{
|
||||
var subTypes = this.SubTypes;
|
||||
return this.JobSubTypes.Where(m => subTypes.Contains(String.Format("{0}_{1}", m.JobTypeId, m.Id))).ToList();
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
public void UpdateModel(DiscoDataContext dbContext)
|
||||
{
|
||||
if (this.JobTypes == null)
|
||||
JobTypes = dbContext.JobTypes.ToList();
|
||||
if (this.JobSubTypes == null)
|
||||
JobSubTypes = dbContext.JobSubTypes.ToList();
|
||||
|
||||
if (!string.IsNullOrEmpty(DeviceSerialNumber))
|
||||
{
|
||||
this.Device = dbContext.Devices.Include("DeviceModel").Where(d => d.SerialNumber == DeviceSerialNumber).FirstOrDefault();
|
||||
if (this.Device == null)
|
||||
{
|
||||
throw new ArgumentException("Invalid Device Serial Number Specified", "DeviceSerialNumber");
|
||||
}
|
||||
if (string.IsNullOrEmpty(this.UserId) && !string.IsNullOrEmpty(this.Device.AssignedUserId))
|
||||
{
|
||||
this.UserId = this.Device.AssignedUserId;
|
||||
}
|
||||
if (string.IsNullOrEmpty(this.Type))
|
||||
this.Type = this.JobTypes.First(jt => jt.Id == "HWar").Id;
|
||||
}
|
||||
else
|
||||
{
|
||||
// No Device - Remove Hardware Types
|
||||
foreach (var jobType in JobTypes.ToArray())
|
||||
{
|
||||
if (jobType.Id != Disco.Models.Repository.JobType.JobTypeIds.SApp)
|
||||
{
|
||||
JobTypes.Remove(jobType);
|
||||
JobSubTypes.RemoveAll(jst => jst.JobType == jobType);
|
||||
}
|
||||
}
|
||||
}
|
||||
if (!string.IsNullOrEmpty(UserId))
|
||||
{
|
||||
this.User = dbContext.Users.Find(UserId);
|
||||
if (this.User == null)
|
||||
{
|
||||
throw new ArgumentException("Invalid User Id Specified", "UserId");
|
||||
}
|
||||
if (string.IsNullOrEmpty(this.Type))
|
||||
this.Type = Disco.Models.Repository.JobType.JobTypeIds.SApp;
|
||||
}
|
||||
if (this.User == null && this.Device == null)
|
||||
{
|
||||
throw new InvalidOperationException("A Job must reference a Device and/or a User");
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public class CreateModelValidation
|
||||
{
|
||||
|
||||
public static ValidationResult ValidateCreateModel(CreateModelOld model)
|
||||
{
|
||||
|
||||
// Device && User both can't be null
|
||||
if (string.IsNullOrEmpty(model.DeviceSerialNumber) && string.IsNullOrEmpty(model.UserId))
|
||||
return new ValidationResult("A Job must reference a Device and/or a User");
|
||||
|
||||
if (!string.IsNullOrEmpty(model.Type) && model.SubTypes != null)
|
||||
{
|
||||
var typeId = string.Format("{0}_", model.Type);
|
||||
model.SubTypes = model.SubTypes.Where(m => m.StartsWith(typeId)).ToList();
|
||||
if (model.SubTypes.Count == 0)
|
||||
{
|
||||
model.SubTypes = null;
|
||||
return new ValidationResult("At least one Sub Type is required", new string[] { "SubTypes" });
|
||||
}
|
||||
}
|
||||
|
||||
return ValidationResult.Success;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Web;
|
||||
using Disco.Models;
|
||||
using System.ComponentModel.DataAnnotations;
|
||||
using Disco.Data.Repository;
|
||||
|
||||
namespace Disco.Web.Models.Job
|
||||
{
|
||||
[CustomValidation(typeof(CreateModelValidation), "ValidateCreateModel")]
|
||||
public class CreateModelOld
|
||||
{
|
||||
private Disco.Models.Repository.Device _Device;
|
||||
private Disco.Models.Repository.User _User;
|
||||
|
||||
public Disco.Models.Repository.Device Device
|
||||
{
|
||||
get
|
||||
{
|
||||
return _Device;
|
||||
}
|
||||
set
|
||||
{
|
||||
_Device = value;
|
||||
DeviceSerialNumber = value.SerialNumber;
|
||||
}
|
||||
}
|
||||
public Disco.Models.Repository.User User
|
||||
{
|
||||
get
|
||||
{
|
||||
return _User;
|
||||
}
|
||||
set
|
||||
{
|
||||
_User = value;
|
||||
UserId = value.Id;
|
||||
}
|
||||
}
|
||||
|
||||
public string DeviceSerialNumber { get; set; }
|
||||
public string UserId { get; set; }
|
||||
|
||||
[Required]
|
||||
public string Type { get; set; }
|
||||
[Required]
|
||||
public List<string> SubTypes { get; set; }
|
||||
|
||||
public List<Disco.Models.Repository.JobType> JobTypes { get; set; }
|
||||
public List<Disco.Models.Repository.JobSubType> JobSubTypes { get; set; }
|
||||
|
||||
public Disco.Models.Repository.JobType GetJobType
|
||||
{
|
||||
get
|
||||
{
|
||||
if (!string.IsNullOrEmpty(this.Type))
|
||||
{
|
||||
return this.JobTypes.FirstOrDefault(m => m.Id == this.Type);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
||||
public List<Disco.Models.Repository.JobSubType> GetJobSubTypes
|
||||
{
|
||||
get
|
||||
{
|
||||
if (SubTypes != null)
|
||||
{
|
||||
var subTypes = this.SubTypes;
|
||||
return this.JobSubTypes.Where(m => subTypes.Contains(String.Format("{0}_{1}", m.JobTypeId, m.Id))).ToList();
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
public void UpdateModel(DiscoDataContext dbContext)
|
||||
{
|
||||
if (this.JobTypes == null)
|
||||
JobTypes = dbContext.JobTypes.ToList();
|
||||
if (this.JobSubTypes == null)
|
||||
JobSubTypes = dbContext.JobSubTypes.ToList();
|
||||
|
||||
if (!string.IsNullOrEmpty(DeviceSerialNumber))
|
||||
{
|
||||
this.Device = dbContext.Devices.Include("DeviceModel").Where(d => d.SerialNumber == DeviceSerialNumber).FirstOrDefault();
|
||||
if (this.Device == null)
|
||||
{
|
||||
throw new ArgumentException("Invalid Device Serial Number Specified", "DeviceSerialNumber");
|
||||
}
|
||||
if (string.IsNullOrEmpty(this.UserId) && !string.IsNullOrEmpty(this.Device.AssignedUserId))
|
||||
{
|
||||
this.UserId = this.Device.AssignedUserId;
|
||||
}
|
||||
if (string.IsNullOrEmpty(this.Type))
|
||||
this.Type = this.JobTypes.First(jt => jt.Id == "HWar").Id;
|
||||
}
|
||||
else
|
||||
{
|
||||
// No Device - Remove Hardware Types
|
||||
foreach (var jobType in JobTypes.ToArray())
|
||||
{
|
||||
if (jobType.Id != Disco.Models.Repository.JobType.JobTypeIds.SApp)
|
||||
{
|
||||
JobTypes.Remove(jobType);
|
||||
JobSubTypes.RemoveAll(jst => jst.JobType == jobType);
|
||||
}
|
||||
}
|
||||
}
|
||||
if (!string.IsNullOrEmpty(UserId))
|
||||
{
|
||||
this.User = dbContext.Users.Find(UserId);
|
||||
if (this.User == null)
|
||||
{
|
||||
throw new ArgumentException("Invalid User Id Specified", "UserId");
|
||||
}
|
||||
if (string.IsNullOrEmpty(this.Type))
|
||||
this.Type = Disco.Models.Repository.JobType.JobTypeIds.SApp;
|
||||
}
|
||||
if (this.User == null && this.Device == null)
|
||||
{
|
||||
throw new InvalidOperationException("A Job must reference a Device and/or a User");
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public class CreateModelValidation
|
||||
{
|
||||
|
||||
public static ValidationResult ValidateCreateModel(CreateModelOld model)
|
||||
{
|
||||
|
||||
// Device && User both can't be null
|
||||
if (string.IsNullOrEmpty(model.DeviceSerialNumber) && string.IsNullOrEmpty(model.UserId))
|
||||
return new ValidationResult("A Job must reference a Device and/or a User");
|
||||
|
||||
if (!string.IsNullOrEmpty(model.Type) && model.SubTypes != null)
|
||||
{
|
||||
var typeId = string.Format("{0}_", model.Type);
|
||||
model.SubTypes = model.SubTypes.Where(m => m.StartsWith(typeId)).ToList();
|
||||
if (model.SubTypes.Count == 0)
|
||||
{
|
||||
model.SubTypes = null;
|
||||
return new ValidationResult("At least one Sub Type is required", new string[] { "SubTypes" });
|
||||
}
|
||||
}
|
||||
|
||||
return ValidationResult.Success;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,13 +1,13 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Web;
|
||||
using System.Web.Mvc;
|
||||
|
||||
namespace Disco.Web.Models.Job
|
||||
{
|
||||
public class CreateRedirectModel
|
||||
{
|
||||
public string RedirectLink { get; set; }
|
||||
}
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Web;
|
||||
using System.Web.Mvc;
|
||||
|
||||
namespace Disco.Web.Models.Job
|
||||
{
|
||||
public class CreateRedirectModel
|
||||
{
|
||||
public string RedirectLink { get; set; }
|
||||
}
|
||||
}
|
||||
@@ -1,99 +1,99 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Web;
|
||||
using Disco.Data.Repository;
|
||||
using System.ComponentModel.DataAnnotations;
|
||||
using Disco.BI;
|
||||
using System.Web.Script.Serialization;
|
||||
using Disco.Services.Plugins;
|
||||
using Disco.Services.Plugins.Features.WarrantyProvider;
|
||||
|
||||
namespace Disco.Web.Models.Job
|
||||
{
|
||||
public class LogWarrantyModel
|
||||
{
|
||||
public Disco.Models.Repository.Job Job { get; set; }
|
||||
public List<PluginFeatureManifest> WarrantyProviders { get; set; }
|
||||
public PluginFeatureManifest WarrantyProvider { get; set; }
|
||||
public List<Disco.Models.BI.Config.OrganisationAddress> OrganisationAddresses { get; set; }
|
||||
public Disco.Models.BI.Config.OrganisationAddress OrganisationAddress { get; set; }
|
||||
|
||||
public Disco.Models.Repository.User TechUser { get; set; }
|
||||
|
||||
[Required]
|
||||
public int JobId { get; set; }
|
||||
[Required(ErrorMessage = "Please specify a Repair Address")]
|
||||
public Nullable<int> OrganisationAddressId { get; set; }
|
||||
[Required(ErrorMessage = "Please specify a Warranty Provider")]
|
||||
public string WarrantyProviderId { get; set; }
|
||||
[Required(ErrorMessage = "A fault description is required"), DataType(System.ComponentModel.DataAnnotations.DataType.MultilineText)]
|
||||
public string FaultDescription { get; set; }
|
||||
[Required]
|
||||
public string WarrantyAction { get; set; }
|
||||
|
||||
public Type WarrantyProviderSubmitJobViewType { get; set; }
|
||||
public object WarrantyProviderSubmitJobModel { get; set; }
|
||||
public string WarrantyProviderPropertiesJson { get; set; }
|
||||
public Dictionary<string, string> WarrantyProviderProperties()
|
||||
{
|
||||
Dictionary<string, string> p = default(Dictionary<string, string>);
|
||||
if (string.IsNullOrEmpty(this.WarrantyProviderPropertiesJson))
|
||||
{
|
||||
JavaScriptSerializer s = new JavaScriptSerializer();
|
||||
try
|
||||
{
|
||||
p = s.Deserialize<Dictionary<string, string>>(this.WarrantyProviderPropertiesJson);
|
||||
}
|
||||
catch (Exception)
|
||||
{
|
||||
// Ignore Errors
|
||||
}
|
||||
}
|
||||
return p;
|
||||
}
|
||||
|
||||
public Dictionary<string, string> DiscloseProperties { get; set; }
|
||||
|
||||
public Exception Error { get; set; }
|
||||
|
||||
public void UpdateModel(DiscoDataContext dbContext, bool IsPostBack)
|
||||
{
|
||||
dbContext.Configuration.LazyLoadingEnabled = true;
|
||||
if (Job == null)
|
||||
{
|
||||
Job = (from j in dbContext.Jobs.Include("Device.DeviceModel").Include("JobMetaWarranty").Include("JobSubTypes")
|
||||
where (j.Id == JobId)
|
||||
select j).FirstOrDefault();
|
||||
if (Job == null)
|
||||
{
|
||||
throw new ArgumentException("Invalid Job Number Specified", "JobId");
|
||||
}
|
||||
}
|
||||
|
||||
this.TechUser = DiscoApplication.CurrentUser;
|
||||
|
||||
WarrantyProviders = Plugins.GetPluginFeatures(typeof(WarrantyProviderFeature));
|
||||
|
||||
if (!IsPostBack && string.IsNullOrEmpty(WarrantyProviderId))
|
||||
{
|
||||
WarrantyProviderId = Job.Device.DeviceModel.DefaultWarrantyProvider;
|
||||
}
|
||||
|
||||
if (!string.IsNullOrEmpty(WarrantyProviderId))
|
||||
WarrantyProvider = Plugins.GetPluginFeature(WarrantyProviderId, typeof(WarrantyProviderFeature));
|
||||
|
||||
this.OrganisationAddresses = dbContext.DiscoConfiguration.OrganisationAddresses.Addresses;
|
||||
|
||||
if (!IsPostBack && !this.OrganisationAddressId.HasValue)
|
||||
{
|
||||
OrganisationAddressId = Job.Device.DeviceProfile.DefaultOrganisationAddress;
|
||||
}
|
||||
if (this.OrganisationAddressId.HasValue)
|
||||
this.OrganisationAddress = this.OrganisationAddresses.FirstOrDefault(oa => oa.Id == this.OrganisationAddressId.Value);
|
||||
|
||||
if (!string.IsNullOrEmpty(FaultDescription))
|
||||
FaultDescription = FaultDescription.Trim();
|
||||
}
|
||||
}
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Web;
|
||||
using Disco.Data.Repository;
|
||||
using System.ComponentModel.DataAnnotations;
|
||||
using Disco.BI;
|
||||
using System.Web.Script.Serialization;
|
||||
using Disco.Services.Plugins;
|
||||
using Disco.Services.Plugins.Features.WarrantyProvider;
|
||||
|
||||
namespace Disco.Web.Models.Job
|
||||
{
|
||||
public class LogWarrantyModel
|
||||
{
|
||||
public Disco.Models.Repository.Job Job { get; set; }
|
||||
public List<PluginFeatureManifest> WarrantyProviders { get; set; }
|
||||
public PluginFeatureManifest WarrantyProvider { get; set; }
|
||||
public List<Disco.Models.BI.Config.OrganisationAddress> OrganisationAddresses { get; set; }
|
||||
public Disco.Models.BI.Config.OrganisationAddress OrganisationAddress { get; set; }
|
||||
|
||||
public Disco.Models.Repository.User TechUser { get; set; }
|
||||
|
||||
[Required]
|
||||
public int JobId { get; set; }
|
||||
[Required(ErrorMessage = "Please specify a Repair Address")]
|
||||
public Nullable<int> OrganisationAddressId { get; set; }
|
||||
[Required(ErrorMessage = "Please specify a Warranty Provider")]
|
||||
public string WarrantyProviderId { get; set; }
|
||||
[Required(ErrorMessage = "A fault description is required"), DataType(System.ComponentModel.DataAnnotations.DataType.MultilineText)]
|
||||
public string FaultDescription { get; set; }
|
||||
[Required]
|
||||
public string WarrantyAction { get; set; }
|
||||
|
||||
public Type WarrantyProviderSubmitJobViewType { get; set; }
|
||||
public object WarrantyProviderSubmitJobModel { get; set; }
|
||||
public string WarrantyProviderPropertiesJson { get; set; }
|
||||
public Dictionary<string, string> WarrantyProviderProperties()
|
||||
{
|
||||
Dictionary<string, string> p = default(Dictionary<string, string>);
|
||||
if (string.IsNullOrEmpty(this.WarrantyProviderPropertiesJson))
|
||||
{
|
||||
JavaScriptSerializer s = new JavaScriptSerializer();
|
||||
try
|
||||
{
|
||||
p = s.Deserialize<Dictionary<string, string>>(this.WarrantyProviderPropertiesJson);
|
||||
}
|
||||
catch (Exception)
|
||||
{
|
||||
// Ignore Errors
|
||||
}
|
||||
}
|
||||
return p;
|
||||
}
|
||||
|
||||
public Dictionary<string, string> DiscloseProperties { get; set; }
|
||||
|
||||
public Exception Error { get; set; }
|
||||
|
||||
public void UpdateModel(DiscoDataContext dbContext, bool IsPostBack)
|
||||
{
|
||||
dbContext.Configuration.LazyLoadingEnabled = true;
|
||||
if (Job == null)
|
||||
{
|
||||
Job = (from j in dbContext.Jobs.Include("Device.DeviceModel").Include("JobMetaWarranty").Include("JobSubTypes")
|
||||
where (j.Id == JobId)
|
||||
select j).FirstOrDefault();
|
||||
if (Job == null)
|
||||
{
|
||||
throw new ArgumentException("Invalid Job Number Specified", "JobId");
|
||||
}
|
||||
}
|
||||
|
||||
this.TechUser = DiscoApplication.CurrentUser;
|
||||
|
||||
WarrantyProviders = Plugins.GetPluginFeatures(typeof(WarrantyProviderFeature));
|
||||
|
||||
if (!IsPostBack && string.IsNullOrEmpty(WarrantyProviderId))
|
||||
{
|
||||
WarrantyProviderId = Job.Device.DeviceModel.DefaultWarrantyProvider;
|
||||
}
|
||||
|
||||
if (!string.IsNullOrEmpty(WarrantyProviderId))
|
||||
WarrantyProvider = Plugins.GetPluginFeature(WarrantyProviderId, typeof(WarrantyProviderFeature));
|
||||
|
||||
this.OrganisationAddresses = dbContext.DiscoConfiguration.OrganisationAddresses.Addresses;
|
||||
|
||||
if (!IsPostBack && !this.OrganisationAddressId.HasValue)
|
||||
{
|
||||
OrganisationAddressId = Job.Device.DeviceProfile.DefaultOrganisationAddress;
|
||||
}
|
||||
if (this.OrganisationAddressId.HasValue)
|
||||
this.OrganisationAddress = this.OrganisationAddresses.FirstOrDefault(oa => oa.Id == this.OrganisationAddressId.Value);
|
||||
|
||||
if (!string.IsNullOrEmpty(FaultDescription))
|
||||
FaultDescription = FaultDescription.Trim();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,17 +1,17 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Web;
|
||||
|
||||
namespace Disco.Web.Models.Job
|
||||
{
|
||||
public class WarrantyProviderJobDetailsModel
|
||||
{
|
||||
public Type ViewType { get; set; }
|
||||
public object ViewModel { get; set; }
|
||||
|
||||
public Exception JobDetailsException { get; set; }
|
||||
public bool JobDetailsSupported { get; set; }
|
||||
public string JobDetailsNotSupportedMessage { get; set; }
|
||||
}
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Web;
|
||||
|
||||
namespace Disco.Web.Models.Job
|
||||
{
|
||||
public class WarrantyProviderJobDetailsModel
|
||||
{
|
||||
public Type ViewType { get; set; }
|
||||
public object ViewModel { get; set; }
|
||||
|
||||
public Exception JobDetailsException { get; set; }
|
||||
public bool JobDetailsSupported { get; set; }
|
||||
public string JobDetailsNotSupportedMessage { get; set; }
|
||||
}
|
||||
}
|
||||
@@ -1,18 +1,18 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Web;
|
||||
|
||||
namespace Disco.Web.Models.Search
|
||||
{
|
||||
public class QueryModel
|
||||
{
|
||||
public string FriendlyTerm { get; set; }
|
||||
public string Term { get; set; }
|
||||
public bool Success { get; set; }
|
||||
public string ErrorMessage { get; set; }
|
||||
public List<Disco.Models.BI.Search.DeviceSearchResultItem> Devices { get; set; }
|
||||
public Disco.Models.BI.Job.JobTableModel Jobs { get; set; }
|
||||
public List<Disco.Models.BI.Search.UserSearchResultItem> Users { get; set; }
|
||||
}
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Web;
|
||||
|
||||
namespace Disco.Web.Models.Search
|
||||
{
|
||||
public class QueryModel
|
||||
{
|
||||
public string FriendlyTerm { get; set; }
|
||||
public string Term { get; set; }
|
||||
public bool Success { get; set; }
|
||||
public string ErrorMessage { get; set; }
|
||||
public List<Disco.Models.BI.Search.DeviceSearchResultItem> Devices { get; set; }
|
||||
public Disco.Models.BI.Job.JobTableModel Jobs { get; set; }
|
||||
public List<Disco.Models.BI.Search.UserSearchResultItem> Users { get; set; }
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user