Files
Disco/Disco.Web/Areas/Config/Controllers/DeviceModelController.cs
T
Gary Sharp 19503366c4 Update: Device Count Details
More information about device membership in Batches, Profiles and
Models.
2013-07-25 17:47:40 +10:00

77 lines
3.1 KiB
C#

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using Disco.Services.Plugins.Features.WarrantyProvider;
using Disco.Services.Plugins;
using Disco.BI.Extensions;
using Disco.Services.Plugins.Features.UIExtension;
using Disco.Models.UI.Config.DeviceModel;
namespace Disco.Web.Areas.Config.Controllers
{
public partial class DeviceModelController : dbAdminController
{
public virtual ActionResult Index(int? id)
{
if (id.HasValue)
{
var m = dbContext.DeviceModels.Include("DeviceComponents").Where(dm => dm.Id == id.Value).Select(dm => new Models.DeviceModel.ShowModel()
{
DeviceModel = dm,
DeviceCount = dm.Devices.Count(),
DeviceDecommissionedCount = dm.Devices.Where(d => d.DecommissionedDate.HasValue).Count()
}).FirstOrDefault();
if (m == null || m.DeviceModel == null)
throw new ArgumentException("Invalid Device Model Id", "id");
m.WarrantyProviders = Plugins.GetPluginFeatures(typeof(WarrantyProviderFeature));
m.DeviceComponentsModel = new Models.DeviceModel.ComponentsModel()
{
DeviceModelId = m.DeviceModel.Id,
DeviceComponents = dbContext.DeviceComponents.Include("JobSubTypes").Where(dc => dc.DeviceModelId == m.DeviceModel.Id).ToList(),
JobSubTypes = dbContext.JobSubTypes.Where(jst => jst.JobTypeId == Disco.Models.Repository.JobType.JobTypeIds.HNWar).ToList()
};
m.CanDelete = m.DeviceModel.CanDelete(dbContext);
//m.Devices = BI.DeviceBI.SelectDeviceSearchResultItem(dbContext.Devices.Where(d => d.DeviceModelId == m.DeviceModel.Id));
//m.Devices = dbContext.Devices.Include("DeviceModel").Include("DeviceProfile").Include("AssignedUser")
// .Where(d => d.DeviceModelId == m.DeviceModel.Id).ToList();
// UI Extensions
UIExtensions.ExecuteExtensions<ConfigDeviceModelShowModel>(this.ControllerContext, m);
return View(MVC.Config.DeviceModel.Views.Show, m);
}
else
{
var m = Models.DeviceModel.IndexModel.Build(dbContext);
// UI Extensions
UIExtensions.ExecuteExtensions<ConfigDeviceModelIndexModel>(this.ControllerContext, m);
return View(m);
}
}
public virtual ActionResult GenericComponents()
{
var m = new Models.DeviceModel.ComponentsModel()
{
DeviceComponents = dbContext.DeviceComponents.Include("JobSubTypes").Where(dc => !dc.DeviceModelId.HasValue).ToList(),
JobSubTypes = dbContext.JobSubTypes.Where(jst => jst.JobTypeId == Disco.Models.Repository.JobType.JobTypeIds.HNWar).ToList()
};
// UI Extensions
UIExtensions.ExecuteExtensions<ConfigDeviceModelComponentsModel>(this.ControllerContext, m);
return View(m);
}
}
}