qol: inline variable declaration

This commit is contained in:
Gary Sharp
2025-07-20 15:12:33 +10:00
parent 5792771ea1
commit 1add4ee0f5
89 changed files with 1229 additions and 1512 deletions
@@ -295,8 +295,7 @@ namespace Disco.Web.Areas.API.Controllers
throw new ArgumentNullException("PurchaseDate", "A Device Batch Purchase Date is required");
else
{
DateTime ecd;
if (DateTime.TryParse(PurchaseDate, out ecd))
if (DateTime.TryParse(PurchaseDate, out var ecd))
{
deviceBatch.PurchaseDate = ecd.Date;
}
@@ -329,8 +328,7 @@ namespace Disco.Web.Areas.API.Controllers
deviceBatch.UnitCost = null;
else
{
decimal unitCost;
if (decimal.TryParse(UnitCost, out unitCost))
if (decimal.TryParse(UnitCost, out var unitCost))
{
deviceBatch.UnitCost = unitCost;
}
@@ -347,8 +345,7 @@ namespace Disco.Web.Areas.API.Controllers
deviceBatch.UnitQuantity = null;
else
{
int unitQuantity;
if (int.TryParse(UnitQuantity, out unitQuantity))
if (int.TryParse(UnitQuantity, out var unitQuantity))
{
deviceBatch.UnitQuantity = unitQuantity;
}
@@ -363,8 +360,7 @@ namespace Disco.Web.Areas.API.Controllers
{
if (!string.IsNullOrEmpty(DefaultDeviceModelId))
{
int bId;
if (int.TryParse(DefaultDeviceModelId, out bId))
if (int.TryParse(DefaultDeviceModelId, out var bId))
{
var dm = Database.DeviceModels.Find(bId);
if (dm != null)
@@ -394,8 +390,7 @@ namespace Disco.Web.Areas.API.Controllers
deviceBatch.WarrantyValidUntil = null;
else
{
DateTime ecd;
if (DateTime.TryParse(WarrantyValidUntil, out ecd))
if (DateTime.TryParse(WarrantyValidUntil, out var ecd))
{
deviceBatch.WarrantyValidUntil = ecd.Date;
}
@@ -420,8 +415,7 @@ namespace Disco.Web.Areas.API.Controllers
deviceBatch.InsuredDate = null;
else
{
DateTime ecd;
if (DateTime.TryParse(InsuredDate, out ecd))
if (DateTime.TryParse(InsuredDate, out var ecd))
{
deviceBatch.InsuredDate = ecd.Date;
}
@@ -446,8 +440,7 @@ namespace Disco.Web.Areas.API.Controllers
deviceBatch.InsuredUntil = null;
else
{
DateTime ecd;
if (DateTime.TryParse(InsuredUntil, out ecd))
if (DateTime.TryParse(InsuredUntil, out var ecd))
{
deviceBatch.InsuredUntil = ecd.Date;
}
@@ -220,8 +220,7 @@ namespace Disco.Web.Areas.API.Controllers
{
if (!string.IsNullOrEmpty(DeviceProfileId))
{
int pId;
if (int.TryParse(DeviceProfileId, out pId))
if (int.TryParse(DeviceProfileId, out var pId))
{
var p = Database.DeviceProfiles.Find(pId);
if (p != null)
@@ -248,8 +247,7 @@ namespace Disco.Web.Areas.API.Controllers
{
if (!string.IsNullOrEmpty(DeviceBatchId))
{
int bId;
if (int.TryParse(DeviceBatchId, out bId))
if (int.TryParse(DeviceBatchId, out var bId))
{
var b = Database.DeviceBatches.Find(bId);
if (b != null)
@@ -306,8 +304,7 @@ namespace Disco.Web.Areas.API.Controllers
}
private void UpdateAllowUnauthenticatedEnrol(Device device, string AllowUnauthenticatedEnrol)
{
bool bAllowUnauthenticatedEnrol;
if (string.IsNullOrEmpty(AllowUnauthenticatedEnrol) || !bool.TryParse(AllowUnauthenticatedEnrol, out bAllowUnauthenticatedEnrol))
if (string.IsNullOrEmpty(AllowUnauthenticatedEnrol) || !bool.TryParse(AllowUnauthenticatedEnrol, out var bAllowUnauthenticatedEnrol))
{
throw new Exception("Invalid AllowUnauthenticatedEnrol Value");
}
@@ -158,8 +158,7 @@ namespace Disco.Web.Areas.API.Controllers
}
else
{
DateTime d;
if (DateTime.TryParse(DefaultPurchaseDate, out d))
if (DateTime.TryParse(DefaultPurchaseDate, out var d))
{
deviceModel.DefaultPurchaseDate = d;
}
@@ -327,12 +326,11 @@ namespace Disco.Web.Areas.API.Controllers
}
}
decimal cost = 0;
if (string.IsNullOrEmpty(Description))
Description = "?";
if (!string.IsNullOrEmpty(Cost) && Cost.Contains("$"))
Cost = Cost.Substring(Cost.IndexOf("$") + 1);
decimal.TryParse(Cost, out cost);
decimal.TryParse(Cost, out var cost);
var dc = new DeviceComponent()
{
@@ -381,13 +379,12 @@ namespace Disco.Web.Areas.API.Controllers
var dc = Database.DeviceComponents.Include("JobSubTypes").Where(i => i.Id == id).FirstOrDefault();
if (dc != null)
{
decimal cost = 0;
if (string.IsNullOrEmpty(Description))
Description = "?";
if (!string.IsNullOrEmpty(Cost) && Cost.Contains("$"))
Cost = Cost.Substring(Cost.IndexOf("$") + 1);
decimal.TryParse(Cost, out cost);
decimal.TryParse(Cost, out var cost);
dc.Description = Description;
dc.Cost = cost;
@@ -442,8 +442,7 @@ namespace Disco.Web.Areas.API.Controllers
private void UpdateDistributionType(DeviceProfile deviceProfile, string DistributionType)
{
int iDt;
if (int.TryParse(DistributionType, out iDt))
if (int.TryParse(DistributionType, out var iDt))
{
deviceProfile.DistributionType = (DeviceProfile.DistributionTypes)iDt;
Database.SaveChanges();
@@ -581,8 +580,7 @@ namespace Disco.Web.Areas.API.Controllers
else
{
// Validate
int daoId;
if (int.TryParse(DefaultOrganisationAddress, out daoId))
if (int.TryParse(DefaultOrganisationAddress, out var daoId))
{
var oa = Database.DiscoConfiguration.OrganisationAddresses.GetAddress(daoId);
if (oa != null)
@@ -606,8 +604,7 @@ namespace Disco.Web.Areas.API.Controllers
private void UpdateEnforceComputerNameConvention(DeviceProfile deviceProfile, string EnforceComputerNameConvention)
{
bool bValue;
if (bool.TryParse(EnforceComputerNameConvention, out bValue))
if (bool.TryParse(EnforceComputerNameConvention, out var bValue))
{
deviceProfile.EnforceComputerNameConvention = bValue;
@@ -619,8 +616,7 @@ namespace Disco.Web.Areas.API.Controllers
private void UpdateEnforceOrganisationalUnit(DeviceProfile deviceProfile, string EnforceOrganisationalUnit)
{
bool bValue;
if (bool.TryParse(EnforceOrganisationalUnit, out bValue))
if (bool.TryParse(EnforceOrganisationalUnit, out var bValue))
{
deviceProfile.EnforceOrganisationalUnit = bValue;
@@ -632,8 +628,7 @@ namespace Disco.Web.Areas.API.Controllers
private void UpdateProvisionADAccount(DeviceProfile deviceProfile, string ProvisionADAccount)
{
bool bValue;
if (bool.TryParse(ProvisionADAccount, out bValue))
if (bool.TryParse(ProvisionADAccount, out var bValue))
{
deviceProfile.ProvisionADAccount = bValue;
@@ -645,8 +640,7 @@ namespace Disco.Web.Areas.API.Controllers
private void UpdateAssignedUserLocalAdmin(DeviceProfile deviceProfile, string AssignedUserLocalAdmin)
{
bool bValue;
if (bool.TryParse(AssignedUserLocalAdmin, out bValue))
if (bool.TryParse(AssignedUserLocalAdmin, out var bValue))
{
deviceProfile.AssignedUserLocalAdmin = bValue;
@@ -658,8 +652,7 @@ namespace Disco.Web.Areas.API.Controllers
private void UpdateAllowUntrustedReimageJobEnrolment(DeviceProfile deviceProfile, string AllowUntrustedReimageJobEnrolment)
{
bool bValue;
if (bool.TryParse(AllowUntrustedReimageJobEnrolment, out bValue))
if (bool.TryParse(AllowUntrustedReimageJobEnrolment, out var bValue))
{
deviceProfile.AllowUntrustedReimageJobEnrolment = bValue;
@@ -404,8 +404,7 @@ namespace Disco.Web.Areas.API.Controllers
}
else
{
bool ff = default(bool);
if (bool.TryParse(FlattenForm, out ff))
if (bool.TryParse(FlattenForm, out var ff))
documentTemplate.FlattenForm = ff;
else
throw new Exception("Invalid Boolean Format");
@@ -421,8 +420,7 @@ namespace Disco.Web.Areas.API.Controllers
}
else
{
bool value = default(bool);
if (bool.TryParse(IsHidden, out value))
if (bool.TryParse(IsHidden, out var value))
documentTemplate.IsHidden = value;
else
throw new Exception("Invalid Boolean Format");
@@ -235,8 +235,7 @@ namespace Disco.Web.Areas.API.Controllers
}
private void UpdateScope(DocumentTemplatePackage Package, string Scope)
{
AttachmentTypes scope;
if (!Enum.TryParse(Scope, true, out scope))
if (!Enum.TryParse<AttachmentTypes>(Scope, true, out var scope))
throw new ArgumentException("Invalid Scope", nameof(Scope));
if (Package.Scope != scope)
@@ -514,8 +514,7 @@ namespace Disco.Web.Areas.API.Controllers
{
if (!string.IsNullOrEmpty(ExpectedClosedDate))
{
DateTime ecd;
if (DateTime.TryParse(ExpectedClosedDate, out ecd))
if (DateTime.TryParse(ExpectedClosedDate, out var ecd))
{
ecd = job.ValidateDateAfterOpened(ecd);
job.ExpectedClosedDate = ecd;
@@ -574,8 +573,7 @@ namespace Disco.Web.Areas.API.Controllers
flags = 0;
foreach (var fs in Flags.Split(','))
{
long fi;
if (!long.TryParse(fs, out fi))
if (!long.TryParse(fs, out var fi))
throw new Exception("Invalid Int64 Format");
else
flags = flags | fi;
@@ -614,8 +612,7 @@ namespace Disco.Web.Areas.API.Controllers
{
throw new Exception("This property can only be set for Hardware NonWarranty Jobs");
}
bool bIsInsuranceClaim;
if (string.IsNullOrEmpty(IsInsuranceClaim) || !bool.TryParse(IsInsuranceClaim, out bIsInsuranceClaim))
if (string.IsNullOrEmpty(IsInsuranceClaim) || !bool.TryParse(IsInsuranceClaim, out var bIsInsuranceClaim))
{
throw new Exception("Invalid IsInsuranceClaim Value");
}
@@ -660,8 +657,7 @@ namespace Disco.Web.Areas.API.Controllers
}
else
{
DateTime d;
if (DateTime.TryParse(AccountingChargeRequiredDate, out d))
if (DateTime.TryParse(AccountingChargeRequiredDate, out var d))
{
d = job.ValidateDateAfterOpened(d);
job.JobMetaNonWarranty.AccountingChargeRequiredDate = d;
@@ -694,8 +690,7 @@ namespace Disco.Web.Areas.API.Controllers
}
else
{
DateTime d;
if (DateTime.TryParse(AccountingChargeAddedDate, out d))
if (DateTime.TryParse(AccountingChargeAddedDate, out var d))
{
d = job.ValidateDateAfterOpened(d);
job.JobMetaNonWarranty.AccountingChargeAddedDate = d;
@@ -728,8 +723,7 @@ namespace Disco.Web.Areas.API.Controllers
}
else
{
DateTime d;
if (DateTime.TryParse(AccountingChargePaidDate, out d))
if (DateTime.TryParse(AccountingChargePaidDate, out var d))
{
d = job.ValidateDateAfterOpened(d);
job.JobMetaNonWarranty.AccountingChargePaidDate = d;
@@ -762,8 +756,7 @@ namespace Disco.Web.Areas.API.Controllers
}
else
{
DateTime d;
if (DateTime.TryParse(PurchaseOrderRaisedDate, out d))
if (DateTime.TryParse(PurchaseOrderRaisedDate, out var d))
{
d = job.ValidateDateAfterOpened(d);
job.JobMetaNonWarranty.PurchaseOrderRaisedDate = d;
@@ -805,8 +798,7 @@ namespace Disco.Web.Areas.API.Controllers
}
else
{
DateTime d;
if (DateTime.TryParse(PurchaseOrderSentDate, out d))
if (DateTime.TryParse(PurchaseOrderSentDate, out var d))
{
d = job.ValidateDateAfterOpened(d);
job.JobMetaNonWarranty.PurchaseOrderSentDate = d;
@@ -839,8 +831,7 @@ namespace Disco.Web.Areas.API.Controllers
}
else
{
DateTime d;
if (DateTime.TryParse(InvoiceReceivedDate, out d))
if (DateTime.TryParse(InvoiceReceivedDate, out var d))
{
d = job.ValidateDateAfterOpened(d);
job.JobMetaNonWarranty.InvoiceReceivedDate = d;
@@ -898,8 +889,7 @@ namespace Disco.Web.Areas.API.Controllers
}
else
{
DateTime d;
if (DateTime.TryParse(RepairerLoggedDate, out d))
if (DateTime.TryParse(RepairerLoggedDate, out var d))
{
job.JobMetaNonWarranty.RepairerLoggedDate = d;
}
@@ -949,8 +939,7 @@ namespace Disco.Web.Areas.API.Controllers
}
else
{
DateTime d;
if (DateTime.TryParse(RepairerCompletedDate, out d))
if (DateTime.TryParse(RepairerCompletedDate, out var d))
{
job.JobMetaNonWarranty.RepairerCompletedDate = d;
}
@@ -987,8 +976,7 @@ namespace Disco.Web.Areas.API.Controllers
}
else
{
DateTime d;
if (DateTime.TryParse(ClaimFormSentDate, out d))
if (DateTime.TryParse(ClaimFormSentDate, out var d))
{
d = job.ValidateDateAfterOpened(d);
job.JobMetaInsurance.ClaimFormSentDate = d;
@@ -1023,8 +1011,7 @@ namespace Disco.Web.Areas.API.Controllers
}
else
{
DateTime dt;
if (!DateTime.TryParse(DateOfPurchase, out dt))
if (!DateTime.TryParse(DateOfPurchase, out var dt))
{
throw new Exception("Invalid DateTime Value");
}
@@ -1104,8 +1091,7 @@ namespace Disco.Web.Areas.API.Controllers
}
else
{
DateTime dt;
if (!DateTime.TryParse(PoliceNotifiedDate, out dt))
if (!DateTime.TryParse(PoliceNotifiedDate, out var dt))
{
throw new Exception("Invalid DateTime Value");
}
@@ -1141,8 +1127,7 @@ namespace Disco.Web.Areas.API.Controllers
throw new Exception("This property can only be set for Hardware NonWarranty Jobs");
}
bool b;
if (string.IsNullOrEmpty(PoliceNotified) || !bool.TryParse(PoliceNotified, out b))
if (string.IsNullOrEmpty(PoliceNotified) || !bool.TryParse(PoliceNotified, out var b))
{
throw new Exception("Invalid Boolean Value");
}
@@ -1165,8 +1150,7 @@ namespace Disco.Web.Areas.API.Controllers
}
else
{
DateTime d;
if (DateTime.TryParse(PropertyLastSeenDate, out d))
if (DateTime.TryParse(PropertyLastSeenDate, out var d))
{
job.JobMetaInsurance.PropertyLastSeenDate = d;
}
@@ -1262,8 +1246,7 @@ namespace Disco.Web.Areas.API.Controllers
throw new Exception("This property can only be set for Hardware NonWarranty Jobs");
}
bool b;
if (string.IsNullOrEmpty(ThirdPartyCaused) || !bool.TryParse(ThirdPartyCaused, out b))
if (string.IsNullOrEmpty(ThirdPartyCaused) || !bool.TryParse(ThirdPartyCaused, out var b))
{
throw new Exception("Invalid Boolean Value");
}
@@ -1324,8 +1307,7 @@ namespace Disco.Web.Areas.API.Controllers
}
else
{
DateTime d;
if (DateTime.TryParse(LossOrDamageDate, out d))
if (DateTime.TryParse(LossOrDamageDate, out var d))
{
job.JobMetaInsurance.LossOrDamageDate = d;
}
@@ -1372,8 +1354,7 @@ namespace Disco.Web.Areas.API.Controllers
}
else
{
DateTime d;
if (DateTime.TryParse(ExternalLoggedDate, out d))
if (DateTime.TryParse(ExternalLoggedDate, out var d))
{
job.JobMetaWarranty.ExternalLoggedDate = d;
}
@@ -1424,8 +1405,7 @@ namespace Disco.Web.Areas.API.Controllers
}
else
{
DateTime d;
if (DateTime.TryParse(ExternalCompletedDate, out d))
if (DateTime.TryParse(ExternalCompletedDate, out var d))
{
job.JobMetaWarranty.ExternalCompletedDate = d;
}
@@ -1495,8 +1475,7 @@ namespace Disco.Web.Areas.API.Controllers
var flag = Flag.Value;
var validFlags = job.ValidFlags();
Tuple<string, bool> flagStatus;
if (validFlags.TryGetValue((flag < 0 ? flag * -1 : flag), out flagStatus))
if (validFlags.TryGetValue(flag < 0 ? flag * -1 : flag, out var flagStatus))
{
if (flag < 0)
{ // Remove Flag
@@ -2067,12 +2046,11 @@ namespace Disco.Web.Areas.API.Controllers
var j = Database.Jobs.Find(id);
if (j != null)
{
decimal cost = 0;
if (string.IsNullOrEmpty(Description))
Description = "?";
if (!string.IsNullOrEmpty(Cost) && Cost.Contains("$"))
Cost = Cost.Substring(Cost.IndexOf("$") + 1);
decimal.TryParse(Cost, out cost);
decimal.TryParse(Cost, out var cost);
var jc = new JobComponent()
{
@@ -2095,13 +2073,12 @@ namespace Disco.Web.Areas.API.Controllers
var jc = Database.JobComponents.Find(id);
if (jc != null)
{
decimal cost = 0;
if (string.IsNullOrEmpty(Description))
Description = "?";
if (!string.IsNullOrEmpty(Cost) && Cost.Contains("$"))
Cost = Cost.Substring(Cost.IndexOf("$") + 1);
decimal.TryParse(Cost, out cost);
decimal.TryParse(Cost, out var cost);
jc.Description = Description;
jc.Cost = cost;
@@ -247,9 +247,8 @@ namespace Disco.Web.Areas.API.Controllers
private void UpdatePriority(JobQueue jobQueue, string Priority)
{
JobQueuePriority priority;
if (!Enum.TryParse(Priority, out priority))
if (!Enum.TryParse<JobQueuePriority>(Priority, out var priority))
throw new ArgumentException("Invalid Priority Value", "Priority");
jobQueue.Priority = priority;
@@ -262,9 +261,8 @@ namespace Disco.Web.Areas.API.Controllers
if (!string.IsNullOrEmpty(DefaultSLAExpiry))
{
int intValue;
if (!int.TryParse(DefaultSLAExpiry, out intValue))
if (!int.TryParse(DefaultSLAExpiry, out var intValue))
throw new ArgumentException("Invalid Default SLA Expiry Value", "DefaultSLAPriority");
if (intValue < 0)
@@ -142,8 +142,7 @@ namespace Disco.Web.Areas.API.Controllers
if (!string.IsNullOrEmpty(Sla))
{
DateTime SLADate;
if (DateTime.TryParse(Sla, out SLADate))
if (DateTime.TryParse(Sla, out var SLADate))
{
jobQueueJob.OnEditSla(SLADate);
Database.SaveChanges();
@@ -164,9 +163,8 @@ namespace Disco.Web.Areas.API.Controllers
if (!jobQueueJob.CanEditPriority())
throw new InvalidOperationException("Editing Priority for job queue job is Denied");
JobQueuePriority priority;
if (!Enum.TryParse(Priority, out priority))
if (!Enum.TryParse<JobQueuePriority>(Priority, out var priority))
throw new ArgumentException("Invalid Priority Value", "Priority");
jobQueueJob.OnEditPriority(priority);
@@ -344,9 +344,8 @@ namespace Disco.Web.Areas.API.Controllers
[DiscoAuthorizeAny(Claims.Config.UserFlag.Configure)]
public virtual ActionResult SyncActiveDirectoryManagedGroup(string id, string redirectUrl = null)
{
ADManagedGroup managedGroup;
if (!ActiveDirectory.Context.ManagedGroups.TryGetValue(id, out managedGroup))
if (!ActiveDirectory.Context.ManagedGroups.TryGetValue(id, out var managedGroup))
throw new ArgumentException("Unknown Managed Group Key");
var taskStatus = ADManagedGroupsSyncTask.ScheduleSync(managedGroup);
@@ -313,8 +313,7 @@ namespace Disco.Web.Areas.API.Controllers
if (UserFlag.UsersLinkedGroup != null)
{
// Sync Group
UserFlagUsersManagedGroup managedGroup;
if (UserFlagUsersManagedGroup.TryGetManagedGroup(UserFlag, out managedGroup))
if (UserFlagUsersManagedGroup.TryGetManagedGroup(UserFlag, out var managedGroup))
{
return ADManagedGroupsSyncTask.ScheduleSync(managedGroup);
}
@@ -335,8 +334,7 @@ namespace Disco.Web.Areas.API.Controllers
if (UserFlag.UserDevicesLinkedGroup != null)
{
// Sync Group
UserFlagUserDevicesManagedGroup managedGroup;
if (UserFlagUserDevicesManagedGroup.TryGetManagedGroup(UserFlag, out managedGroup))
if (UserFlagUserDevicesManagedGroup.TryGetManagedGroup(UserFlag, out var managedGroup))
{
return ADManagedGroupsSyncTask.ScheduleSync(managedGroup);
}
@@ -41,11 +41,9 @@ namespace Disco.Web.Areas.Config.Controllers
DeviceDecommissionedCount = dG.Count(d => d.DecommissionedDate.HasValue)
}).ToArray().Cast<ConfigDeviceBatchShowModelMembership>().ToList();
DeviceBatchAssignedUsersManagedGroup assignedUsersManagedGroup;
if (DeviceBatchAssignedUsersManagedGroup.TryGetManagedGroup(m.DeviceBatch, out assignedUsersManagedGroup))
if (DeviceBatchAssignedUsersManagedGroup.TryGetManagedGroup(m.DeviceBatch, out var assignedUsersManagedGroup))
m.AssignedUsersLinkedGroup = assignedUsersManagedGroup;
DeviceBatchDevicesManagedGroup devicesManagedGroup;
if (DeviceBatchDevicesManagedGroup.TryGetManagedGroup(m.DeviceBatch, out devicesManagedGroup))
if (DeviceBatchDevicesManagedGroup.TryGetManagedGroup(m.DeviceBatch, out var devicesManagedGroup))
m.DevicesLinkedGroup = devicesManagedGroup;
m.CanDelete = m.DeviceBatch.CanDelete(Database);
@@ -39,11 +39,9 @@ namespace Disco.Web.Areas.Config.Controllers
if (m.DeviceProfile.DefaultOrganisationAddress.HasValue)
m.DefaultOrganisationAddress = Database.DiscoConfiguration.OrganisationAddresses.GetAddress(m.DeviceProfile.DefaultOrganisationAddress.Value);
DeviceProfileAssignedUsersManagedGroup assignedUsersManagedGroup;
if (DeviceProfileAssignedUsersManagedGroup.TryGetManagedGroup(m.DeviceProfile, out assignedUsersManagedGroup))
if (DeviceProfileAssignedUsersManagedGroup.TryGetManagedGroup(m.DeviceProfile, out var assignedUsersManagedGroup))
m.AssignedUsersLinkedGroup = assignedUsersManagedGroup;
DeviceProfileDevicesManagedGroup devicesManagedGroup;
if (DeviceProfileDevicesManagedGroup.TryGetManagedGroup(m.DeviceProfile, out devicesManagedGroup))
if (DeviceProfileDevicesManagedGroup.TryGetManagedGroup(m.DeviceProfile, out var devicesManagedGroup))
m.DevicesLinkedGroup = devicesManagedGroup;
// Ensure Specified OU Exists
@@ -61,11 +61,9 @@ namespace Disco.Web.Areas.Config.Controllers
m.TemplateExpressions = m.DocumentTemplate.ExtractPdfExpressions(Database);
m.UpdateModel(Database);
DocumentTemplateDevicesManagedGroup devicesManagedGroup;
if (DocumentTemplateDevicesManagedGroup.TryGetManagedGroup(m.DocumentTemplate, out devicesManagedGroup))
if (DocumentTemplateDevicesManagedGroup.TryGetManagedGroup(m.DocumentTemplate, out var devicesManagedGroup))
m.DevicesLinkedGroup = devicesManagedGroup;
DocumentTemplateUsersManagedGroup usersManagedGroup;
if (DocumentTemplateUsersManagedGroup.TryGetManagedGroup(m.DocumentTemplate, out usersManagedGroup))
if (DocumentTemplateUsersManagedGroup.TryGetManagedGroup(m.DocumentTemplate, out var usersManagedGroup))
m.UsersLinkedGroup = usersManagedGroup;
m.BulkGenerateDownloadId = bulkGenerateId;
@@ -36,11 +36,9 @@ namespace Disco.Web.Areas.Config.Controllers
if (m == null)
throw new ArgumentException("Invalid User Flag Id");
UserFlagUsersManagedGroup assignedUsersManagedGroup;
if (UserFlagUsersManagedGroup.TryGetManagedGroup(m.UserFlag, out assignedUsersManagedGroup))
if (UserFlagUsersManagedGroup.TryGetManagedGroup(m.UserFlag, out var assignedUsersManagedGroup))
m.UsersLinkedGroup = assignedUsersManagedGroup;
UserFlagUserDevicesManagedGroup assignedUserDevicesManagedGroup;
if (UserFlagUserDevicesManagedGroup.TryGetManagedGroup(m.UserFlag, out assignedUserDevicesManagedGroup))
if (UserFlagUserDevicesManagedGroup.TryGetManagedGroup(m.UserFlag, out var assignedUserDevicesManagedGroup))
m.UserDevicesLinkedGroup = assignedUserDevicesManagedGroup;
if (Authorization.Has(Claims.Config.UserFlag.Configure))
@@ -37,8 +37,7 @@ namespace Disco.Web.Areas.Services.Controllers
// Ensure supported version
if (Request.UserAgent.StartsWith(@"Disco-Client/", StringComparison.OrdinalIgnoreCase))
{
Version clientVersion;
if (Version.TryParse(Request.UserAgent.Substring(13), out clientVersion))
if (Version.TryParse(Request.UserAgent.Substring(13), out var clientVersion))
{
if (clientVersion < new Version(2, 2))
{
@@ -110,8 +109,7 @@ namespace Disco.Web.Areas.Services.Controllers
// Ensure supported version
if (Request.UserAgent.StartsWith(@"Disco-Client/", StringComparison.OrdinalIgnoreCase))
{
Version clientVersion;
if (Version.TryParse(Request.UserAgent.Substring(13), out clientVersion))
if (Version.TryParse(Request.UserAgent.Substring(13), out var clientVersion))
{
if (clientVersion < new Version(2, 2))
{
+6 -12
View File
@@ -17,8 +17,7 @@ namespace Disco.Web.Controllers
public virtual ActionResult Query(string term, string limit = null, bool searchDetails = false, bool includeDecommissioned = false)
{
term = term.Trim();
int termInt;
if (!int.TryParse(term, out termInt))
if (!int.TryParse(term, out var termInt))
termInt = -1;
var m = new Models.Search.QueryModel() { Term = term };
@@ -77,8 +76,7 @@ namespace Disco.Web.Controllers
{
case "devicemodel":
Authorization.Require(Claims.Device.Search);
int deviceModelId;
if (int.TryParse(term, out deviceModelId))
if (int.TryParse(term, out var deviceModelId))
{
var vm = Database.DeviceModels.Find(deviceModelId);
if (vm != null)
@@ -94,8 +92,7 @@ namespace Disco.Web.Controllers
break;
case "deviceprofile":
Authorization.Require(Claims.Device.Search);
int deviceProfileId;
if (int.TryParse(term, out deviceProfileId))
if (int.TryParse(term, out var deviceProfileId))
{
var dp = Database.DeviceProfiles.Find(deviceProfileId);
if (dp != null)
@@ -111,8 +108,7 @@ namespace Disco.Web.Controllers
break;
case "devicebatch":
Authorization.Require(Claims.Device.Search);
int deviceBatchId;
if (int.TryParse(term, out deviceBatchId))
if (int.TryParse(term, out var deviceBatchId))
{
var db = Database.DeviceBatches.Find(deviceBatchId);
if (db != null)
@@ -233,8 +229,7 @@ namespace Disco.Web.Controllers
}
case "userflag":
Authorization.RequireAll(Claims.User.Search, Claims.User.ShowFlagAssignments);
int userFlagId;
if (int.TryParse(term, out userFlagId))
if (int.TryParse(term, out var userFlagId))
{
var flag = Database.UserFlags.Find(userFlagId);
if (flag != null)
@@ -250,8 +245,7 @@ namespace Disco.Web.Controllers
break;
case "deviceflag":
Authorization.RequireAll(Claims.Device.Search, Claims.Device.ShowFlagAssignments);
int deviceFlagId;
if (int.TryParse(term, out deviceFlagId))
if (int.TryParse(term, out var deviceFlagId))
{
var flag = Database.DeviceFlags.Find(deviceFlagId);
if (flag != null)
+1 -2
View File
@@ -124,8 +124,7 @@ namespace Disco.Web
// Job Matches
markdown = htmlCommentJobRegex.Value.Replace(markdown, match =>
{
int jobId;
if (int.TryParse(match.Groups[2].Value, out jobId))
if (int.TryParse(match.Groups[2].Value, out var jobId))
return $"<a href=\"{urlHelper.Action(MVC.Job.Show(jobId))}\" title=\"Job {jobId}\">{match.Value}</a>";
else
return match.Value;
@@ -23,12 +23,11 @@ namespace Disco.Web.Models.InitialConfig
{
var branches = FileStoreLocation.ToUpper().Split(Path.DirectorySeparatorChar);
var branchesCase = FileStoreLocation.Split(Path.DirectorySeparatorChar);
FileStoreDirectoryModel branchModel;
FileStoreDirectoryModel branchParent = DirectoryModel;
for (int i = 0; i < branches.Length; i++)
{
var branch = branches[i];
if (branchParent.SubDirectories.TryGetValue(branch, out branchModel))
if (branchParent.SubDirectories.TryGetValue(branch, out var branchModel))
{
branchModel.ExpandSubDirectories();
}