initial source commit
This commit is contained in:
@@ -0,0 +1,114 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Web;
|
||||
using System.Web.Mvc;
|
||||
using Disco.BI;
|
||||
using Disco.BI.Extensions;
|
||||
using Disco.Data.Repository;
|
||||
using Disco.Models.Repository;
|
||||
using System.Data.Objects.SqlClient;
|
||||
using Disco.Web.Extensions;
|
||||
|
||||
|
||||
namespace Disco.Web.Controllers
|
||||
{
|
||||
public partial class DeviceController : dbAdminController
|
||||
{
|
||||
#region Index
|
||||
public virtual ActionResult Index()
|
||||
{
|
||||
return View();
|
||||
}
|
||||
#endregion
|
||||
|
||||
#region Add Offline
|
||||
public virtual ActionResult AddOffline()
|
||||
{
|
||||
var m = new Models.Device.AddOfflineModel()
|
||||
{
|
||||
DefaultDeviceProfileId = dbContext.DiscoConfiguration.DeviceProfiles.DefaultAddDeviceOfflineDeviceProfileId
|
||||
};
|
||||
m.DeviceBatches = dbContext.DeviceBatches.ToSelectListItems();
|
||||
m.DeviceProfiles = dbContext.DeviceProfiles.ToList();
|
||||
if (m.DefaultDeviceProfileId == 0)
|
||||
{
|
||||
m.DeviceProfiles.Insert(0, new DeviceProfile() { Id = 0, Name = "Select a Device Profile" });
|
||||
}
|
||||
|
||||
return View(m);
|
||||
}
|
||||
[HttpPost]
|
||||
public virtual ActionResult AddOffline(Models.Device.AddOfflineModel m)
|
||||
{
|
||||
// Trim Serial Number & Error Check
|
||||
m.Device.SerialNumber = m.Device.SerialNumber.Trim();
|
||||
if (string.IsNullOrEmpty(m.Device.SerialNumber))
|
||||
{
|
||||
ModelState.AddModelError("Device.SerialNumber", "The Serial Number is Required");
|
||||
}
|
||||
else
|
||||
{
|
||||
// Ensure Existing Device Doesn't Exist
|
||||
if (!string.IsNullOrEmpty(m.Device.SerialNumber) && dbContext.Devices.Count(d => d.SerialNumber == m.Device.SerialNumber) > 0)
|
||||
ModelState.AddModelError("Device.SerialNumber", "A Device what this Serial Number already exists");
|
||||
}
|
||||
|
||||
|
||||
if (ModelState.IsValid)
|
||||
{
|
||||
var d = m.Device.AddOffline(dbContext);
|
||||
dbContext.SaveChanges();
|
||||
return RedirectToAction(MVC.Device.Show(d.SerialNumber));
|
||||
}
|
||||
return AddOffline();
|
||||
}
|
||||
#endregion
|
||||
|
||||
#region Show
|
||||
public virtual ActionResult Show(string id)
|
||||
{
|
||||
var m = new Models.Device.ShowModel();
|
||||
|
||||
dbContext.Configuration.LazyLoadingEnabled = true;
|
||||
|
||||
m.Device = dbContext.Devices
|
||||
.Where(d => d.SerialNumber == id)
|
||||
.FirstOrDefault();
|
||||
|
||||
if (m.Device == null)
|
||||
throw new ArgumentException(string.Format("Unknown Device: [{0}]", id), "id");
|
||||
|
||||
// Removed 2012-07-03 G#
|
||||
// Deferred to Ajax call - improve load performance
|
||||
// Update Device LastNetworkLogonDate
|
||||
//if (m.Device.UpdateLastNetworkLogonDate())
|
||||
// dbContext.SaveChanges();
|
||||
|
||||
// No Necessary - Yet...
|
||||
//if (!string.IsNullOrWhiteSpace(m.Device.ComputerName))
|
||||
//{
|
||||
// var adMachineAccount = BI.Interop.ActiveDirectory.ActiveDirectory.GetMachineAccount(m.Device.ComputerName);
|
||||
// if (adMachineAccount != null)
|
||||
// {
|
||||
// m.OrganisationUnit = adMachineAccount.ParentDistinguishedName;
|
||||
// }
|
||||
//}
|
||||
|
||||
m.DeviceProfiles = dbContext.DeviceProfiles.ToList();
|
||||
|
||||
m.DeviceBatches = dbContext.DeviceBatches.ToSelectListItems(m.Device.DeviceBatchId);
|
||||
|
||||
m.Jobs = new Disco.Models.BI.Job.JobTableModel() { ShowStatus = true, ShowDevice = false, IsSmallTable = true, HideClosedJobs = true };
|
||||
m.Jobs.Fill(dbContext, BI.JobBI.Searching.BuildJobTableModel(dbContext).Where(j => j.DeviceSerialNumber == m.Device.SerialNumber));
|
||||
|
||||
m.Certificates = dbContext.DeviceCertificates.Where(c => c.DeviceSerialNumber == m.Device.SerialNumber).ToList();
|
||||
|
||||
//m.AttachmentTypes = dbContext.AttachmentTypes.Where(at => at.Scope == AttachmentType.AttachmentTypeScopes.Device).ToList();
|
||||
m.DocumentTemplates = m.Device.AvailableDocumentTemplates(dbContext, DiscoApplication.CurrentUser, DateTime.Now);
|
||||
|
||||
return View(m);
|
||||
}
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,306 @@
|
||||
using System;
|
||||
using System.Data.SqlClient;
|
||||
using System.Threading;
|
||||
using System.Web.Mvc;
|
||||
using Disco.Web.Models.InitialConfig;
|
||||
using Disco.Data.Repository;
|
||||
using System.Linq;
|
||||
using System.IO;
|
||||
using System.Text.RegularExpressions;
|
||||
using System.IO.Compression;
|
||||
using System.Management;
|
||||
|
||||
namespace Disco.Web.Controllers
|
||||
{
|
||||
[OutputCache(Duration = 0, Location = System.Web.UI.OutputCacheLocation.None)]
|
||||
public partial class InitialConfigController : Controller
|
||||
{
|
||||
|
||||
#region Determine Server Is Core SKU
|
||||
// Added 2012-11-01 G#
|
||||
// http://www.discoict.com.au/forum/support/2012/10/install-on-server-core.aspx
|
||||
private static Lazy<bool> ServerIsCoreSKU = new Lazy<bool>(() =>
|
||||
{
|
||||
try
|
||||
{
|
||||
uint osSKU = 0;
|
||||
using (var mSearcher = new ManagementObjectSearcher("SELECT OperatingSystemSKU FROM Win32_OperatingSystem"))
|
||||
{
|
||||
using (var mResults = mSearcher.Get())
|
||||
{
|
||||
foreach (ManagementObject mResult in mResults)
|
||||
{
|
||||
osSKU = (uint)mResult.Properties["OperatingSystemSKU"].Value;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
switch (osSKU)
|
||||
{
|
||||
case 12: // Datacenter Server Core Edition
|
||||
case 13: // Standard Server Core Edition
|
||||
case 14: // Enterprise Server Core Edition
|
||||
return true;
|
||||
default:
|
||||
return false;
|
||||
}
|
||||
}
|
||||
catch (Exception)
|
||||
{
|
||||
// Ignore Exceptions
|
||||
}
|
||||
|
||||
// Default to "Not Core"
|
||||
return false;
|
||||
});
|
||||
// End Added 2012-11-01 G#
|
||||
#endregion
|
||||
|
||||
protected override void OnActionExecuting(ActionExecutingContext filterContext)
|
||||
{
|
||||
// Updated 2012-11-01 G# - Consider ServerIsCoreSKU
|
||||
if (!Request.IsLocal && !ServerIsCoreSKU.Value)
|
||||
{
|
||||
filterContext.Result = new HttpStatusCodeResult(System.Net.HttpStatusCode.ServiceUnavailable, "Initial Configuration of Disco is only allowed via a local connection");
|
||||
}
|
||||
base.OnActionExecuting(filterContext);
|
||||
}
|
||||
|
||||
//
|
||||
// GET: /Install/
|
||||
|
||||
public virtual ActionResult Index()
|
||||
{
|
||||
return RedirectToAction(MVC.InitialConfig.Welcome());
|
||||
}
|
||||
|
||||
#region Welcome
|
||||
public virtual ActionResult Welcome()
|
||||
{
|
||||
var m = new WelcomeModel();
|
||||
|
||||
m.AutodetectOrganisation();
|
||||
|
||||
return View(m);
|
||||
}
|
||||
[HttpPost]
|
||||
public virtual ActionResult Welcome(WelcomeModel model)
|
||||
{
|
||||
if (ModelState.IsValid)
|
||||
{
|
||||
DiscoApplication.OrganisationName = model.OrganisationName;
|
||||
|
||||
return RedirectToAction(MVC.InitialConfig.Database());
|
||||
}
|
||||
|
||||
return View(model);
|
||||
}
|
||||
#endregion
|
||||
|
||||
#region Database
|
||||
public virtual ActionResult Database()
|
||||
{
|
||||
var cs = Disco.Data.Repository.DiscoDatabaseConnectionFactory.DiscoDataContextConnectionString;
|
||||
|
||||
DatabaseModel m;
|
||||
|
||||
if (cs == null)
|
||||
m = new DatabaseModel(); // Just use Defaults
|
||||
else
|
||||
m = DatabaseModel.FromConnectionString(cs); // Import from existing Connection String
|
||||
|
||||
return View(m);
|
||||
}
|
||||
[HttpPost]
|
||||
public virtual ActionResult Database(DatabaseModel model)
|
||||
{
|
||||
if (ModelState.IsValid)
|
||||
{
|
||||
// Continue with Configuration
|
||||
var connectionString = model.ToConnectionString();
|
||||
|
||||
// Try Creating/Migrating
|
||||
connectionString.ConnectTimeout = 5;
|
||||
Disco.Data.Repository.DiscoDatabaseConnectionFactory.SetDiscoDataContextConnectionString(connectionString.ToString(), false);
|
||||
|
||||
try
|
||||
{
|
||||
Disco.Data.Migrations.DiscoDataMigrator.MigrateLatest(true);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
// Find inner exception
|
||||
SqlException sqlException = null;
|
||||
Exception innermostException = ex;
|
||||
do
|
||||
{
|
||||
if (sqlException == null)
|
||||
sqlException = innermostException as SqlException;
|
||||
if (innermostException.InnerException != null)
|
||||
innermostException = innermostException.InnerException;
|
||||
else
|
||||
break;
|
||||
} while (true);
|
||||
|
||||
if (sqlException != null)
|
||||
{
|
||||
ModelState.AddModelError(string.Empty, string.Format("Unable to create or migrate the database to the latest version: [{0}] {1}", sqlException.GetType().Name, sqlException.Message));
|
||||
}
|
||||
else
|
||||
{
|
||||
ModelState.AddModelError(string.Empty, string.Format("Unable to create or migrate the database to the latest version: [{0}] {1}", innermostException.GetType().Name, innermostException.Message));
|
||||
}
|
||||
}
|
||||
|
||||
if (ModelState.IsValid)
|
||||
{
|
||||
// Save Connection String
|
||||
//Disco.Data.Repository.DiscoDatabaseConnectionFactory.SetDiscoDataContextConnectionString(model.ToConnectionString().ToString(), true);
|
||||
// Write Organisation Name into DB
|
||||
using (DiscoDataContext db = new DiscoDataContext())
|
||||
{
|
||||
db.DiscoConfiguration.OrganisationName = DiscoApplication.OrganisationName;
|
||||
db.SaveChanges();
|
||||
}
|
||||
|
||||
return RedirectToAction(MVC.InitialConfig.FileStore());
|
||||
}
|
||||
}
|
||||
|
||||
return View(model);
|
||||
}
|
||||
#endregion
|
||||
|
||||
#region FileStore
|
||||
public virtual ActionResult FileStore()
|
||||
{
|
||||
// Try and retrieve FileStore path from DB
|
||||
string FileStoreLocation = null;
|
||||
try
|
||||
{
|
||||
using (DiscoDataContext db = new DiscoDataContext())
|
||||
FileStoreLocation = db.ConfigurationItems.Where(ci => ci.Scope == "System" && ci.Key == "DataStoreLocation").Select(ci => ci.Value).FirstOrDefault();
|
||||
}
|
||||
catch (Exception) { } // Ignore All Errors
|
||||
|
||||
FileStoreModel m = new FileStoreModel();
|
||||
|
||||
// Test for valid Format
|
||||
if (!string.IsNullOrEmpty(FileStoreLocation))
|
||||
if (!Regex.IsMatch(FileStoreLocation, @"^[A-z]:(\\[^\\/:*?""<>|0x0-0x1F]+)+(\\)?$", RegexOptions.Singleline))
|
||||
FileStoreLocation = null;
|
||||
m.FileStoreLocation = FileStoreLocation;
|
||||
if (m.FileStoreLocation != null && m.FileStoreLocation.EndsWith(@"\"))
|
||||
m.FileStoreLocation = m.FileStoreLocation.TrimEnd('\\');
|
||||
|
||||
m.ExpandDirectoryModel();
|
||||
|
||||
return View(m);
|
||||
}
|
||||
[HttpPost]
|
||||
public virtual ActionResult FileStore(FileStoreModel m)
|
||||
{
|
||||
if (ModelState.IsValid)
|
||||
{
|
||||
// Ensure Path Exists
|
||||
using (DiscoDataContext db = new DiscoDataContext())
|
||||
{
|
||||
var configItem = db.ConfigurationItems.Where(ci => ci.Scope == "System" && ci.Key == "DataStoreLocation").FirstOrDefault();
|
||||
if (configItem == null)
|
||||
{ // Create Config
|
||||
db.ConfigurationItems.Add(new Disco.Models.Repository.ConfigurationItem()
|
||||
{
|
||||
Scope = "System",
|
||||
Key = "DataStoreLocation",
|
||||
Value = m.FileStoreLocation
|
||||
});
|
||||
}
|
||||
else
|
||||
{ // Update Config
|
||||
configItem.Value = m.FileStoreLocation;
|
||||
}
|
||||
db.SaveChanges();
|
||||
}
|
||||
|
||||
// Extract DataStore Template into FileStore
|
||||
var templatePath = Server.MapPath("~/ClientBin/DataStoreTemplate.zip");
|
||||
if (System.IO.File.Exists(templatePath))
|
||||
{
|
||||
try
|
||||
{
|
||||
using (ZipArchive templateArchive = ZipFile.Open(templatePath, ZipArchiveMode.Read))
|
||||
{
|
||||
foreach (var entry in templateArchive.Entries)
|
||||
{
|
||||
var entryDestinationPath = Path.Combine(m.FileStoreLocation, entry.FullName);
|
||||
if (System.IO.File.Exists(entryDestinationPath))
|
||||
System.IO.File.Delete(entryDestinationPath);
|
||||
}
|
||||
templateArchive.ExtractToDirectory(m.FileStoreLocation);
|
||||
}
|
||||
return RedirectToAction(MVC.InitialConfig.Complete());
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
ModelState.AddModelError(string.Empty, string.Format("Unable to extract File Store template: [{0}] {1}", ex.GetType().Name, ex.Message));
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
return RedirectToAction(MVC.InitialConfig.Complete());
|
||||
}
|
||||
}
|
||||
|
||||
m.ExpandDirectoryModel();
|
||||
|
||||
return View(m);
|
||||
}
|
||||
public virtual ActionResult FileStoreBranch(string Path)
|
||||
{
|
||||
return Json(FileStoreModel.FileStoreDirectoryModel.FromPath(Path, true), JsonRequestBehavior.AllowGet);
|
||||
}
|
||||
#endregion
|
||||
|
||||
#region Complete
|
||||
public virtual ActionResult Complete()
|
||||
{
|
||||
var m = new CompleteModel();
|
||||
|
||||
m.PerformTests();
|
||||
|
||||
return View(m);
|
||||
}
|
||||
#endregion
|
||||
|
||||
#region Restart WebApp
|
||||
|
||||
public virtual ActionResult RestartWebApp()
|
||||
{
|
||||
RestartWebApp(1500);
|
||||
return View();
|
||||
}
|
||||
|
||||
|
||||
private static object _restartTimerLock = new object();
|
||||
private static Timer _restartTimer;
|
||||
private void RestartWebApp(int DelayMilliseconds)
|
||||
{
|
||||
lock (_restartTimerLock)
|
||||
{
|
||||
if (_restartTimer != null)
|
||||
{
|
||||
_restartTimer.Dispose();
|
||||
}
|
||||
|
||||
_restartTimer = new Timer((state) =>
|
||||
{
|
||||
AppDomain.Unload(AppDomain.CurrentDomain);
|
||||
}, null, DelayMilliseconds, Timeout.Infinite);
|
||||
}
|
||||
}
|
||||
#endregion
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,468 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Web;
|
||||
using System.Web.Mvc;
|
||||
using Disco.Data.Repository;
|
||||
using Disco.BI;
|
||||
using Disco.BI.Extensions;
|
||||
using Disco.Models.Repository;
|
||||
using System.Web.Script.Serialization;
|
||||
using Disco.Services.Plugins.Features.WarrantyProvider;
|
||||
using Disco.Services.Plugins;
|
||||
|
||||
namespace Disco.Web.Controllers
|
||||
{
|
||||
public partial class JobController : dbAdminController
|
||||
{
|
||||
|
||||
#region Index
|
||||
public virtual ActionResult Index()
|
||||
{
|
||||
var m = new Models.Job.IndexModel();
|
||||
|
||||
//m.MyJobs = JobBI.SelectJobSearchResultItem((from j in dbContext.Jobs
|
||||
// where j.OpenedTechUserId == DiscoApplication.CurrentUser.Id && j.ClosedDate == null && (j.DeviceHeld == null || j.DeviceReturnedDate != null || j.DeviceReadyForReturn == null)
|
||||
// select j));
|
||||
//m.OpenJobs = JobBI.SelectJobSearchResultItem((from j in dbContext.Jobs
|
||||
// where j.OpenedTechUserId != DiscoApplication.CurrentUser.Id && j.ClosedDate == null && (j.DeviceHeld == null || j.DeviceReturnedDate != null || j.DeviceReadyForReturn == null)
|
||||
// select j));
|
||||
|
||||
dbContext.Configuration.LazyLoadingEnabled = true;
|
||||
|
||||
m.OpenJobs = new Disco.Models.BI.Job.JobTableModel() { ShowStatus = true };
|
||||
m.OpenJobs.Fill(dbContext, BI.JobBI.Searching.BuildJobTableModel(dbContext).Where(j => j.ClosedDate == null
|
||||
&& !j.WaitingForUserAction.HasValue
|
||||
&& !(j.JobTypeId == JobType.JobTypeIds.HNWar && (j.JobMetaNonWarranty.RepairerLoggedDate.HasValue && j.JobMetaNonWarranty.IsInsuranceClaim && !j.JobMetaInsurance.ClaimFormSentDate.HasValue))
|
||||
&& !(j.JobTypeId == JobType.JobTypeIds.HNWar && (j.JobMetaNonWarranty.RepairerLoggedDate.HasValue && !j.JobMetaNonWarranty.RepairerCompletedDate.HasValue))
|
||||
&& !(j.JobTypeId == JobType.JobTypeIds.HNWar && (j.JobMetaNonWarranty.AccountingChargeAddedDate.HasValue && !j.JobMetaNonWarranty.AccountingChargePaidDate.HasValue))
|
||||
&& !(j.JobTypeId == JobType.JobTypeIds.HWar && (j.JobMetaWarranty.ExternalLoggedDate.HasValue && !j.JobMetaWarranty.ExternalCompletedDate.HasValue))
|
||||
&& (j.DeviceHeld == null || j.DeviceReturnedDate != null || j.DeviceReadyForReturn == null)).OrderBy(j => j.Id));
|
||||
|
||||
var longRunningThreshold = DateTime.Now.AddDays(-7);
|
||||
m.LongRunningJobs = new Disco.Models.BI.Job.JobTableModel() { ShowStatus = true };
|
||||
m.LongRunningJobs.Fill(dbContext, BI.JobBI.Searching.BuildJobTableModel(dbContext).Where(j => j.ClosedDate == null
|
||||
&& j.OpenedDate < longRunningThreshold).OrderBy(j => j.Id));
|
||||
|
||||
//m.WaitingForUserActionJobs = new Disco.Models.BI.Job.JobTableModel();
|
||||
//m.WaitingForUserActionJobs.Fill(Disco.BI.JobTableModelBI.BuildQuery(dbContext).Where(j => j.WaitingForUserAction.HasValue
|
||||
// && j.ClosedDate == null));
|
||||
|
||||
//m.ReadyForReturnJobs = new Disco.Models.BI.Job.JobTableModel();
|
||||
//m.ReadyForReturnJobs.Fill(BI.JobTableModelBI.BuildQuery(dbContext).Where(j => !j.WaitingForUserAction.HasValue
|
||||
// && j.DeviceHeld != null && j.DeviceReturnedDate == null && j.DeviceReadyForReturn != null
|
||||
// && j.ClosedDate == null));
|
||||
|
||||
//// 2 Days ago - Ignore Weekend
|
||||
//var dateTimeNow = DateTime.Now;
|
||||
//var closedThreshold = dateTimeNow.AddDays(-2);
|
||||
//if (dateTimeNow.DayOfWeek == DayOfWeek.Monday)
|
||||
// closedThreshold = closedThreshold.AddDays(-2);
|
||||
//if (dateTimeNow.DayOfWeek == DayOfWeek.Tuesday)
|
||||
// closedThreshold = closedThreshold.AddDays(-1);
|
||||
//m.RecentlyClosedJobs = new Disco.Models.BI.Job.JobTableModel();
|
||||
//m.RecentlyClosedJobs.Fill(BI.JobTableModelBI.BuildQuery(dbContext).Where(j => j.ClosedDate > closedThreshold));
|
||||
return View(m);
|
||||
}
|
||||
#endregion
|
||||
|
||||
#region Lists
|
||||
public virtual ActionResult AllOpen()
|
||||
{
|
||||
dbContext.Configuration.LazyLoadingEnabled = true;
|
||||
var m = new Models.Job.ListModel() { Title = "All Open Jobs" };
|
||||
m.JobTable = new Disco.Models.BI.Job.JobTableModel() { ShowStatus = true };
|
||||
m.JobTable.Fill(dbContext, BI.JobBI.Searching.BuildJobTableModel(dbContext).Where(j => j.ClosedDate == null).OrderBy(j => j.Id));
|
||||
return View(Views.List, m);
|
||||
}
|
||||
public virtual ActionResult DevicesReadyForReturn()
|
||||
{
|
||||
dbContext.Configuration.LazyLoadingEnabled = true;
|
||||
var m = new Models.Job.ListModel() { Title = "Jobs with Devices Ready for Return" };
|
||||
m.JobTable = new Disco.Models.BI.Job.JobTableModel() { ShowStatus = true };
|
||||
m.JobTable.Fill(dbContext, BI.JobBI.Searching.BuildJobTableModel(dbContext).Where(j => !j.WaitingForUserAction.HasValue
|
||||
&& j.DeviceHeld != null && j.DeviceReturnedDate == null && j.DeviceReadyForReturn != null &&
|
||||
((!j.JobMetaNonWarranty.AccountingChargeRequiredDate.HasValue && !j.JobMetaNonWarranty.AccountingChargeAddedDate.HasValue) || j.JobMetaNonWarranty.AccountingChargePaidDate.HasValue)
|
||||
&& j.ClosedDate == null).OrderBy(j => j.Id));
|
||||
return View(Views.List, m);
|
||||
}
|
||||
public virtual ActionResult DevicesAwaitingRepair()
|
||||
{
|
||||
dbContext.Configuration.LazyLoadingEnabled = true;
|
||||
var m = new Models.Job.ListModel() { Title = "Jobs with Devices Awaiting Repair" };
|
||||
m.JobTable = new Disco.Models.BI.Job.JobTableModel() { ShowStatus = true };
|
||||
m.JobTable.Fill(dbContext, BI.JobBI.Searching.BuildJobTableModel(dbContext).Where(j => j.ClosedDate == null &&
|
||||
(
|
||||
(j.JobMetaNonWarranty.RepairerLoggedDate != null && j.JobMetaNonWarranty.RepairerCompletedDate == null) ||
|
||||
(j.JobMetaWarranty.ExternalLoggedDate != null && j.JobMetaWarranty.ExternalCompletedDate == null)
|
||||
)).OrderBy(j => j.Id));
|
||||
return View(Views.List, m);
|
||||
}
|
||||
|
||||
#region "Finance Lists"
|
||||
public virtual ActionResult AwaitingFinance()
|
||||
{
|
||||
dbContext.Configuration.LazyLoadingEnabled = true;
|
||||
var m = new Models.Job.ListModel() { Title = "Jobs Awaiting Finance" };
|
||||
m.JobTable = new Disco.Models.BI.Job.JobTableModel() { ShowStatus = true };
|
||||
m.JobTable.Fill(dbContext, BI.JobBI.Searching.BuildJobTableModel(dbContext).Where(j => j.ClosedDate == null &&
|
||||
(
|
||||
(j.JobTypeId == JobType.JobTypeIds.HNWar && (j.JobMetaNonWarranty.IsInsuranceClaim && !j.JobMetaInsurance.ClaimFormSentDate.HasValue)) ||
|
||||
(j.JobTypeId == JobType.JobTypeIds.HNWar && (j.JobMetaNonWarranty.AccountingChargeRequiredDate.HasValue && (!j.JobMetaNonWarranty.AccountingChargeAddedDate.HasValue && !j.JobMetaNonWarranty.AccountingChargePaidDate.HasValue))) ||
|
||||
(j.JobTypeId == JobType.JobTypeIds.HNWar && (!j.JobMetaNonWarranty.AccountingChargeAddedDate.HasValue || !j.JobMetaNonWarranty.AccountingChargePaidDate.HasValue)) ||
|
||||
(j.JobTypeId == JobType.JobTypeIds.UMgmt && (long)Job.UserManagementFlags.Infringement_BreachFinancialAgreement == (j.Flags & (long)Job.UserManagementFlags.Infringement_BreachFinancialAgreement))
|
||||
)));
|
||||
return View(Views.List, m);
|
||||
}
|
||||
|
||||
public virtual ActionResult AwaitingFinanceCharge()
|
||||
{
|
||||
dbContext.Configuration.LazyLoadingEnabled = true;
|
||||
var m = new Models.Job.ListModel() { Title = "Jobs Awaiting Finance - Accounting Charge" };
|
||||
m.JobTable = new Disco.Models.BI.Job.JobTableModel() { ShowStatus = true };
|
||||
m.JobTable.Fill(dbContext, BI.JobBI.Searching.BuildJobTableModel(dbContext).Where(j => j.ClosedDate == null &&
|
||||
(j.JobTypeId == JobType.JobTypeIds.HNWar && (j.JobMetaNonWarranty.AccountingChargeRequiredDate.HasValue && (!j.JobMetaNonWarranty.AccountingChargeAddedDate.HasValue && !j.JobMetaNonWarranty.AccountingChargePaidDate.HasValue)))
|
||||
).OrderBy(j => j.Id));
|
||||
|
||||
return View(Views.List, m);
|
||||
}
|
||||
public virtual ActionResult AwaitingFinancePayment()
|
||||
{
|
||||
dbContext.Configuration.LazyLoadingEnabled = true;
|
||||
var m = new Models.Job.ListModel() { Title = "Jobs Awaiting Finance - Accounting Payment" };
|
||||
m.JobTable = new Disco.Models.BI.Job.JobTableModel() { ShowStatus = true };
|
||||
m.JobTable.Fill(dbContext, BI.JobBI.Searching.BuildJobTableModel(dbContext).Where(j => j.ClosedDate == null &&
|
||||
(j.JobTypeId == JobType.JobTypeIds.HNWar && (!j.JobMetaNonWarranty.AccountingChargeAddedDate.HasValue || !j.JobMetaNonWarranty.AccountingChargePaidDate.HasValue))
|
||||
).OrderBy(j => j.Id));
|
||||
return View(Views.List, m);
|
||||
}
|
||||
public virtual ActionResult AwaitingFinanceInsuranceProcessing()
|
||||
{
|
||||
dbContext.Configuration.LazyLoadingEnabled = true;
|
||||
var m = new Models.Job.ListModel() { Title = "Jobs Awaiting Finance - Insurance Processing" };
|
||||
m.JobTable = new Disco.Models.BI.Job.JobTableModel() { ShowStatus = true };
|
||||
m.JobTable.Fill(dbContext, BI.JobBI.Searching.BuildJobTableModel(dbContext).Where(j => j.ClosedDate == null &&
|
||||
(j.JobTypeId == JobType.JobTypeIds.HNWar && (j.JobMetaNonWarranty.IsInsuranceClaim && !j.JobMetaInsurance.ClaimFormSentDate.HasValue))
|
||||
).OrderBy(j => j.Id));
|
||||
return View(Views.List, m);
|
||||
}
|
||||
public virtual ActionResult AwaitingFinanceAgreementBreach()
|
||||
{
|
||||
dbContext.Configuration.LazyLoadingEnabled = true;
|
||||
var m = new Models.Job.ListModel() { Title = "Jobs Awaiting Finance - Agreement Breach" };
|
||||
m.JobTable = new Disco.Models.BI.Job.JobTableModel() { ShowStatus = true };
|
||||
m.JobTable.Fill(dbContext, BI.JobBI.Searching.BuildJobTableModel(dbContext).Where(j => j.ClosedDate == null &&
|
||||
(j.JobTypeId == JobType.JobTypeIds.UMgmt && (long)Job.UserManagementFlags.Infringement_BreachFinancialAgreement == (j.Flags & (long)Job.UserManagementFlags.Infringement_BreachFinancialAgreement))
|
||||
).OrderBy(j => j.Id));
|
||||
return View(Views.List, m);
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
public virtual ActionResult AwaitingUserAction()
|
||||
{
|
||||
dbContext.Configuration.LazyLoadingEnabled = true;
|
||||
var m = new Models.Job.ListModel() { Title = "Jobs Awaiting User Action" };
|
||||
m.JobTable = new Disco.Models.BI.Job.JobTableModel() { ShowStatus = true };
|
||||
m.JobTable.Fill(dbContext, BI.JobBI.Searching.BuildJobTableModel(dbContext).Where(j => (j.WaitingForUserAction.HasValue || (j.JobMetaNonWarranty.AccountingChargeAddedDate != null && j.JobMetaNonWarranty.AccountingChargePaidDate == null))
|
||||
&& j.ClosedDate == null).OrderBy(j => j.Id));
|
||||
return View(Views.List, m);
|
||||
}
|
||||
public virtual ActionResult RecentlyClosed()
|
||||
{
|
||||
dbContext.Configuration.LazyLoadingEnabled = true;
|
||||
var m = new Models.Job.ListModel() { Title = "Recently Closed Jobs" };
|
||||
m.JobTable = new Disco.Models.BI.Job.JobTableModel() { ShowStatus = true };
|
||||
|
||||
var dateTimeNow = DateTime.Now;
|
||||
var closedThreshold = dateTimeNow.AddDays(-2);
|
||||
if (dateTimeNow.DayOfWeek == DayOfWeek.Monday)
|
||||
closedThreshold = closedThreshold.AddDays(-2);
|
||||
if (dateTimeNow.DayOfWeek == DayOfWeek.Tuesday)
|
||||
closedThreshold = closedThreshold.AddDays(-1);
|
||||
m.JobTable.Fill(dbContext, BI.JobBI.Searching.BuildJobTableModel(dbContext).Where(j => j.ClosedDate > closedThreshold).OrderBy(j => j.Id));
|
||||
return View(Views.List, m);
|
||||
}
|
||||
public virtual ActionResult Locations()
|
||||
{
|
||||
dbContext.Configuration.LazyLoadingEnabled = true;
|
||||
var m = new Models.Job.ListModel() { Title = "Held Device Locations" };
|
||||
m.JobTable = new Disco.Models.BI.Job.JobTableModel() { ShowStatus = true, ShowLocation = true, ShowTechnician = false, ShowType = false };
|
||||
m.JobTable.Fill(dbContext, BI.JobBI.Searching.BuildJobTableModel(dbContext).Where(j => j.ClosedDate == null && j.DeviceHeld.HasValue && !j.DeviceReturnedDate.HasValue).OrderBy(j => j.DeviceHeldLocation));
|
||||
return View(Views.List, m);
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region Show
|
||||
public virtual ActionResult Show(int? id)
|
||||
{
|
||||
if (!id.HasValue)
|
||||
return RedirectToAction(MVC.Job.Index());
|
||||
|
||||
dbContext.Configuration.LazyLoadingEnabled = true;
|
||||
|
||||
var m = new Models.Job.ShowModel();
|
||||
|
||||
m.Job = (from j in dbContext.Jobs.Include("Device.DeviceModel").Include("Device.DeviceBatch").Include("DeviceHeldTechUser").Include("DeviceReadyForReturnTechUser").Include("DeviceReturnedTechUser")
|
||||
.Include("OpenedTechUser").Include("ClosedTechUser").Include("JobType").Include("JobSubTypes").Include("User").Include("JobLogs.TechUser")
|
||||
where (j.Id == id.Value)
|
||||
select j).FirstOrDefault();
|
||||
|
||||
m.UpdatableJobSubTypes = m.Job.JobType.JobSubTypes.OrderBy(jst => jst.Description).ToList();
|
||||
|
||||
m.DocumentTemplates = m.Job.AvailableDocumentTemplates(dbContext, DiscoApplication.CurrentUser, DateTime.Now);
|
||||
|
||||
return View(m);
|
||||
}
|
||||
#endregion
|
||||
|
||||
#region Create
|
||||
public virtual ActionResult Create(string DeviceSerialNumber, string UserId)
|
||||
{
|
||||
var m = new Models.Job.CreateModel()
|
||||
{
|
||||
DeviceSerialNumber = DeviceSerialNumber,
|
||||
UserId = UserId
|
||||
};
|
||||
m.UpdateModel(dbContext);
|
||||
|
||||
return View(m);
|
||||
}
|
||||
[HttpPost]
|
||||
public virtual ActionResult Create(Models.Job.CreateModel m)
|
||||
{
|
||||
m.UpdateModel(dbContext);
|
||||
|
||||
if (!ModelState.IsValid)
|
||||
{
|
||||
return View(m);
|
||||
}
|
||||
else
|
||||
{
|
||||
// Create New Job
|
||||
var currentUser = dbContext.Users.Find(DiscoApplication.CurrentUser.Id);
|
||||
var j = BI.JobBI.Utilities.Create(dbContext, m.Device, m.User, m.GetJobType, m.GetJobSubTypes, currentUser);
|
||||
|
||||
if (m.DeviceHeld.Value)
|
||||
{
|
||||
j.OnDeviceHeld(currentUser);
|
||||
m.QuickLog = false;
|
||||
}
|
||||
else
|
||||
{
|
||||
if (m.QuickLog.HasValue && m.QuickLog.Value && m.QuickLogTaskTimeMinutes.HasValue && m.QuickLogTaskTimeMinutes.Value > 0)
|
||||
{
|
||||
// Quick Log
|
||||
// Set Opened Date in the past
|
||||
j.OpenedDate = DateTime.Now.AddMinutes(-1 * m.QuickLogTaskTimeMinutes.Value);
|
||||
// Close Job
|
||||
j.OnClose(currentUser);
|
||||
}
|
||||
else
|
||||
{
|
||||
m.QuickLog = false;
|
||||
}
|
||||
}
|
||||
|
||||
// Add Comments
|
||||
if (!string.IsNullOrWhiteSpace(m.Comments))
|
||||
{
|
||||
var jl = new Disco.Models.Repository.JobLog()
|
||||
{
|
||||
Job = j,
|
||||
TechUser = currentUser,
|
||||
Timestamp = DateTime.Now,
|
||||
Comments = m.Comments
|
||||
};
|
||||
dbContext.JobLogs.Add(jl);
|
||||
}
|
||||
|
||||
dbContext.SaveChanges();
|
||||
|
||||
// Return Dialog Redirect
|
||||
var redirectModel = new Models.Job.CreateRedirectModel();
|
||||
if (m.QuickLog.HasValue && m.QuickLog.Value && !string.IsNullOrWhiteSpace(m.QuickLogDestinationUrl))
|
||||
redirectModel.RedirectLink = m.QuickLogDestinationUrl;
|
||||
else
|
||||
redirectModel.RedirectLink = Url.Action(MVC.Job.Show(j.Id));
|
||||
|
||||
return View(Views.Create_Redirect, redirectModel);
|
||||
}
|
||||
}
|
||||
#endregion
|
||||
|
||||
// Decommissioned 2012-11-28 G# - Moved to new infrastructure
|
||||
#region Create - Old
|
||||
//public virtual ActionResult Create(string DeviceSerialNumber, string UserId)
|
||||
//{
|
||||
// var m = new Models.Job.CreateModel()
|
||||
// {
|
||||
// DeviceSerialNumber = DeviceSerialNumber,
|
||||
// UserId = UserId
|
||||
// };
|
||||
// m.UpdateModel(dbContext);
|
||||
|
||||
// return View(m);
|
||||
//}
|
||||
//[HttpPost]
|
||||
//public virtual ActionResult Create(Models.Job.CreateModel m)
|
||||
//{
|
||||
// m.UpdateModel(dbContext);
|
||||
|
||||
// if (!ModelState.IsValid)
|
||||
// {
|
||||
// return View(m);
|
||||
// }
|
||||
// else
|
||||
// {
|
||||
// // Create New Job
|
||||
// var currentUser = dbContext.Users.Find(DiscoApplication.CurrentUser.Id);
|
||||
// var j = BI.JobBI.Utilities.Create(dbContext, m.Device, m.User, m.GetJobType, m.GetJobSubTypes, currentUser);
|
||||
// dbContext.SaveChanges();
|
||||
// return RedirectToAction(MVC.Job.Show(j.Id));
|
||||
// }
|
||||
//}
|
||||
#endregion
|
||||
// End Decommissioned 2012-11-28 G#
|
||||
|
||||
#region Log Warranty
|
||||
public virtual ActionResult LogWarranty(int id, string WarrantyProviderId, int? OrganisationAddressId)
|
||||
{
|
||||
var m = new Models.Job.LogWarrantyModel() { JobId = id, WarrantyProviderId = WarrantyProviderId, OrganisationAddressId = OrganisationAddressId };
|
||||
m.UpdateModel(dbContext, false);
|
||||
m.FaultDescription = m.Job.GenerateFaultDescription(dbContext);
|
||||
|
||||
if (m.WarrantyProvider != null)
|
||||
{
|
||||
using (var wp = m.WarrantyProvider.CreateInstance<WarrantyProviderFeature>())
|
||||
{
|
||||
if (wp.SubmitJobViewType != null)
|
||||
{
|
||||
m.WarrantyProviderSubmitJobViewType = wp.SubmitJobViewType;
|
||||
m.WarrantyProviderSubmitJobModel = wp.SubmitJobViewModel(dbContext, this, m.Job, m.OrganisationAddress, m.TechUser);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return View(m);
|
||||
}
|
||||
[HttpPost]
|
||||
public virtual ActionResult LogWarranty(Models.Job.LogWarrantyModel m, FormCollection form)
|
||||
{
|
||||
m.UpdateModel(dbContext, true);
|
||||
|
||||
if (ModelState.IsValid)
|
||||
{
|
||||
switch (m.WarrantyAction)
|
||||
{
|
||||
case "Disclose":
|
||||
using (var p = m.WarrantyProvider.CreateInstance<WarrantyProviderFeature>())
|
||||
{
|
||||
Dictionary<string, string> warrantyProviderProperties;
|
||||
try
|
||||
{
|
||||
warrantyProviderProperties = p.SubmitJobParseProperties(dbContext, form, this, m.Job, m.OrganisationAddress, m.TechUser, m.FaultDescription);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
m.Error = ex;
|
||||
return View(Views.LogWarrantyError, m);
|
||||
}
|
||||
if (!ModelState.IsValid)
|
||||
return View(Views.LogWarranty, m);
|
||||
|
||||
if (warrantyProviderProperties != null)
|
||||
{
|
||||
JavaScriptSerializer j = new JavaScriptSerializer();
|
||||
m.WarrantyProviderPropertiesJson = j.Serialize(warrantyProviderProperties);
|
||||
}
|
||||
m.DiscloseProperties = p.SubmitJobDiscloseInfo(dbContext, m.Job, m.OrganisationAddress, m.TechUser, m.FaultDescription, warrantyProviderProperties);
|
||||
return View(Views.LogWarrantyDisclose, m);
|
||||
}
|
||||
case "Submit":
|
||||
try
|
||||
{
|
||||
m.Job.OnLogWarranty(dbContext, m.FaultDescription, m.WarrantyProvider, m.OrganisationAddress, m.TechUser, m.WarrantyProviderProperties());
|
||||
dbContext.SaveChanges();
|
||||
return RedirectToAction(MVC.Job.Show(m.JobId));
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
m.Error = ex;
|
||||
return View(Views.LogWarrantyError, m);
|
||||
throw;
|
||||
}
|
||||
default:
|
||||
return RedirectToAction(MVC.Job.Show(m.JobId));
|
||||
}
|
||||
|
||||
}
|
||||
else
|
||||
{
|
||||
return View(Views.LogWarranty, m);
|
||||
}
|
||||
}
|
||||
|
||||
public virtual ActionResult WarrantyProviderJobDetails(int id)
|
||||
{
|
||||
Models.Job.WarrantyProviderJobDetailsModel model = new Models.Job.WarrantyProviderJobDetailsModel();
|
||||
|
||||
Job job = dbContext.Jobs.Include("Device.DeviceModel").Include("JobMetaWarranty").Include("JobSubTypes").Where(j => j.Id == id).FirstOrDefault();
|
||||
if (job != null)
|
||||
{
|
||||
if (job.JobMetaWarranty != null && !string.IsNullOrEmpty(job.JobMetaWarranty.ExternalName))
|
||||
{
|
||||
var providerDef = WarrantyProviderFeature.FindPluginFeature(job.JobMetaWarranty.ExternalName);
|
||||
|
||||
if (providerDef != null)
|
||||
{
|
||||
using (WarrantyProviderFeature providerInstance = providerDef.CreateInstance<WarrantyProviderFeature>())
|
||||
{
|
||||
if (providerInstance.JobDetailsSupported)
|
||||
{
|
||||
try
|
||||
{
|
||||
object providerModel = providerInstance.JobDetailsViewModel(dbContext, this, job);
|
||||
|
||||
model.JobDetailsSupported = true;
|
||||
model.ViewType = providerInstance.JobDetailsViewType;
|
||||
model.ViewModel = providerModel;
|
||||
return View(model);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
model.JobDetailsSupported = false;
|
||||
model.JobDetailsException = ex;
|
||||
return View(model);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
model.JobDetailsSupported = false;
|
||||
model.JobDetailsNotSupportedMessage = string.Format("Plugin '{0} ({1})' (Warranty Provider for '{2}') doesn't support Job Details", providerInstance.Manifest.Name, providerInstance.Manifest.Id, providerInstance.WarrantyProviderId);
|
||||
return View(model);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
model.JobDetailsSupported = false;
|
||||
model.JobDetailsNotSupportedMessage = string.Format("Warranty Provider '{0}' is not integrated with Disco", job.JobMetaWarranty.ExternalName);
|
||||
return View(model);
|
||||
}
|
||||
else
|
||||
{
|
||||
model.JobDetailsSupported = false;
|
||||
model.JobDetailsNotSupportedMessage = "Job not in the correct state";
|
||||
return View(model);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
return HttpNotFound("Invalid Job Id");
|
||||
}
|
||||
}
|
||||
#endregion
|
||||
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,54 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Web;
|
||||
using System.Web.Mvc;
|
||||
using Disco.Services.Plugins;
|
||||
|
||||
namespace Disco.Web.Controllers
|
||||
{
|
||||
public partial class PluginWebHandlerController : Controller
|
||||
{
|
||||
[Authorize(Roles = "Admin")]
|
||||
[OutputCache(Duration = 0, Location = System.Web.UI.OutputCacheLocation.None)]
|
||||
public virtual ActionResult Index(string PluginId, string PluginAction)
|
||||
{
|
||||
var manifest = Plugins.GetPlugin(PluginId);
|
||||
|
||||
if (manifest.HasWebHandler)
|
||||
{
|
||||
using (var pluginWebHandler = manifest.CreateWebHandler(this))
|
||||
{
|
||||
return pluginWebHandler.ExecuteAction(PluginAction);
|
||||
}
|
||||
}
|
||||
return HttpNotFound("Plugin has no Web Handler");
|
||||
}
|
||||
|
||||
[OutputCache(Duration = 2592000, Location = System.Web.UI.OutputCacheLocation.Any, VaryByParam = "*")]
|
||||
public virtual ActionResult Resource(string PluginId, string res, bool? Download)
|
||||
{
|
||||
var manifest = Plugins.GetPlugin(PluginId);
|
||||
|
||||
Tuple<string, string> pluginResource;
|
||||
|
||||
try
|
||||
{
|
||||
pluginResource = manifest.WebResourcePath(res);
|
||||
}
|
||||
catch (FileNotFoundException)
|
||||
{
|
||||
return HttpNotFound("Plugin Resource Not Found");
|
||||
}
|
||||
|
||||
var pluginResourcePath = pluginResource.Item1;
|
||||
|
||||
var mimeType = Disco.BI.Interop.MimeTypes.ResolveMimeType(pluginResourcePath);
|
||||
if (Download.HasValue && Download.Value)
|
||||
return File(pluginResourcePath, mimeType, Path.GetFileName(pluginResourcePath));
|
||||
else
|
||||
return File(pluginResourcePath, mimeType);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,149 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Web;
|
||||
using System.Web.Mvc;
|
||||
using Disco.BI;
|
||||
using Disco.Data.Repository;
|
||||
using Disco.Models.Repository;
|
||||
|
||||
namespace Disco.Web.Controllers
|
||||
{
|
||||
public partial class SearchController : dbAdminController
|
||||
{
|
||||
#region Query
|
||||
public virtual ActionResult Query(string term, string limit = null, bool searchDetails = false)
|
||||
{
|
||||
term = term.Trim();
|
||||
int termInt;
|
||||
if (!int.TryParse(term, out termInt))
|
||||
termInt = -1;
|
||||
|
||||
var m = new Models.Search.QueryModel() { Term = term };
|
||||
|
||||
if (string.IsNullOrEmpty(term))
|
||||
{
|
||||
m.Success = false;
|
||||
m.ErrorMessage = "A search term is required";
|
||||
return View(m);
|
||||
}
|
||||
|
||||
m.Success = true;
|
||||
using (dbContext = new DiscoDataContext())
|
||||
{
|
||||
if (limit == null)
|
||||
{
|
||||
if (term.Length < 2 && termInt < 0) // < 2 Characters && Not a Number
|
||||
{
|
||||
m.Success = false;
|
||||
m.ErrorMessage = "A search term of at least two characters is required";
|
||||
return View(m);
|
||||
}
|
||||
m.Devices = BI.DeviceBI.Searching.Search(dbContext, term);
|
||||
m.Jobs = BI.JobBI.Searching.Search(dbContext, term, null, true, searchDetails);
|
||||
m.Users = BI.UserBI.Searching.Search(dbContext, term);
|
||||
}
|
||||
else
|
||||
{
|
||||
switch (limit.ToLower())
|
||||
{
|
||||
case "devicemodel":
|
||||
int deviceModelId;
|
||||
if (int.TryParse(term, out deviceModelId))
|
||||
{
|
||||
var vm = dbContext.DeviceModels.Find(deviceModelId);
|
||||
if (vm != null)
|
||||
{
|
||||
m.FriendlyTerm = string.Format("Device Model: {0}", vm.ToString());
|
||||
m.Devices = BI.DeviceBI.Searching.SearchDeviceModel(dbContext, vm.Id);
|
||||
break;
|
||||
}
|
||||
}
|
||||
m.FriendlyTerm = string.Format("Device Model: {0}", term);
|
||||
m.Success = false;
|
||||
m.ErrorMessage = "Invalid Device Model Id";
|
||||
break;
|
||||
case "deviceprofile":
|
||||
int deviceProfileId;
|
||||
if (int.TryParse(term, out deviceProfileId))
|
||||
{
|
||||
var dp = dbContext.DeviceProfiles.Find(deviceProfileId);
|
||||
if (dp != null)
|
||||
{
|
||||
m.FriendlyTerm = string.Format("Device Profile: {0}", dp.ToString());
|
||||
m.Devices = BI.DeviceBI.Searching.SearchDeviceProfile(dbContext, dp.Id);
|
||||
break;
|
||||
}
|
||||
}
|
||||
m.FriendlyTerm = string.Format("Device Profile: {0}", term);
|
||||
m.Success = false;
|
||||
m.ErrorMessage = "Invalid Device Profile Id";
|
||||
break;
|
||||
case "devicebatch":
|
||||
int deviceBatchId;
|
||||
if (int.TryParse(term, out deviceBatchId))
|
||||
{
|
||||
var db = dbContext.DeviceBatches.Find(deviceBatchId);
|
||||
if (db != null)
|
||||
{
|
||||
m.FriendlyTerm = string.Format("Device Batch: {0}", db.ToString());
|
||||
m.Devices = BI.DeviceBI.Searching.SearchDeviceBatch(dbContext, db.Id);
|
||||
break;
|
||||
}
|
||||
}
|
||||
m.FriendlyTerm = string.Format("Device Batch: {0}", term);
|
||||
m.Success = false;
|
||||
m.ErrorMessage = "Invalid Device Batch Id";
|
||||
break;
|
||||
case "devices":
|
||||
if (term.Length < 2)
|
||||
{
|
||||
m.Success = false;
|
||||
m.ErrorMessage = "A search term of at least two characters is required";
|
||||
return View(m);
|
||||
}
|
||||
m.Devices = BI.DeviceBI.Searching.Search(dbContext, term);
|
||||
if (m.Devices.Count == 1)
|
||||
{
|
||||
return RedirectToAction(MVC.Device.Show(m.Devices[0].SerialNumber));
|
||||
}
|
||||
break;
|
||||
case "jobs":
|
||||
if (term.Length < 2 && termInt < 0)
|
||||
{
|
||||
m.Success = false;
|
||||
m.ErrorMessage = "A search term of at least two characters is required";
|
||||
return View(m);
|
||||
}
|
||||
if (termInt >= 0)
|
||||
{ // Term is a Number - Check for JobId
|
||||
if (dbContext.Jobs.Count(j => j.Id == termInt) == 1)
|
||||
{
|
||||
return RedirectToAction(MVC.Job.Show(termInt));
|
||||
}
|
||||
}
|
||||
m.Jobs = BI.JobBI.Searching.Search(dbContext, term, null, true, searchDetails);
|
||||
break;
|
||||
case "users":
|
||||
if (term.Length < 2)
|
||||
{
|
||||
m.Success = false;
|
||||
m.ErrorMessage = "A search term of at least two characters is required";
|
||||
return View(m);
|
||||
}
|
||||
m.Users = BI.UserBI.Searching.Search(dbContext, term);
|
||||
if (m.Users.Count == 1)
|
||||
{
|
||||
return RedirectToAction(MVC.User.Show(m.Users[0].Id));
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return View(m);
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,51 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Web;
|
||||
using System.Web.Mvc;
|
||||
using Disco.Models.Repository;
|
||||
using Disco.BI.Extensions;
|
||||
|
||||
namespace Disco.Web.Controllers
|
||||
{
|
||||
public partial class UserController : dbAdminController
|
||||
{
|
||||
#region Index
|
||||
public virtual ActionResult Index()
|
||||
{
|
||||
return View();
|
||||
}
|
||||
#endregion
|
||||
|
||||
#region Show
|
||||
public virtual ActionResult Show(string id)
|
||||
{
|
||||
var m = new Models.User.ShowModel();
|
||||
|
||||
dbContext.Configuration.LazyLoadingEnabled = true;
|
||||
|
||||
// Update User Cache
|
||||
// Do this first so the Database is updated if necessary
|
||||
try
|
||||
{
|
||||
Disco.BI.UserBI.UserCache.GetUser(id, dbContext, true);
|
||||
}
|
||||
catch (ArgumentException)
|
||||
{
|
||||
// Ignore if User not in Active Directory anymore
|
||||
}
|
||||
|
||||
|
||||
m.User = dbContext.Users.Where(um => um.Id == id).FirstOrDefault();
|
||||
|
||||
m.Jobs = new Disco.Models.BI.Job.JobTableModel() { ShowStatus = true, ShowDevice = true, ShowUser = false, IsSmallTable = true, HideClosedJobs = true };
|
||||
m.Jobs.Fill(dbContext, BI.JobBI.Searching.BuildJobTableModel(dbContext).Where(j => j.UserId == id));
|
||||
|
||||
m.DocumentTemplates = m.User.AvailableDocumentTemplates(dbContext, DiscoApplication.CurrentUser, DateTime.Now);
|
||||
|
||||
return View(m);
|
||||
}
|
||||
#endregion
|
||||
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user