Feature: Held Devices Noticeboard
Provides a noticeboard for all devices, not just those assigned to users.
This commit is contained in:
@@ -5,90 +5,65 @@ using System.Web;
|
||||
using System.Web.Mvc;
|
||||
using Disco.BI;
|
||||
using Disco.BI.Extensions;
|
||||
using Disco.Models.Repository;
|
||||
|
||||
namespace Disco.Web.Areas.Public.Controllers
|
||||
{
|
||||
public partial class UserHeldDevicesController : dbController
|
||||
{
|
||||
private List<Models.UserHeldDevices.UserHeldDeviceModel> GetUserHeldDevices()
|
||||
#region Helpers
|
||||
|
||||
private List<Models.UserHeldDevices.UserHeldDeviceModel> GetUserHeldDevices(IQueryable<Job> query)
|
||||
{
|
||||
var usersJobs = dbContext.Jobs.Where(j =>
|
||||
!j.ClosedDate.HasValue && j.UserId != null &&
|
||||
var jobs = query.Where(j =>
|
||||
!j.ClosedDate.HasValue && j.Device.AssignedUserId != null &&
|
||||
j.DeviceSerialNumber != null &&
|
||||
((j.DeviceHeld.HasValue && !j.DeviceReturnedDate.HasValue) || j.WaitingForUserAction.HasValue)
|
||||
).Select(j => new Models.UserHeldDevices.HeldJobDeviceModel
|
||||
{
|
||||
JobId = j.Id,
|
||||
WaitingForUserAction = j.WaitingForUserAction.HasValue || ((j.JobMetaNonWarranty.AccountingChargeRequiredDate.HasValue || j.JobMetaNonWarranty.AccountingChargeAddedDate.HasValue) && !j.JobMetaNonWarranty.AccountingChargePaidDate.HasValue),
|
||||
WaitingForUserActionSince = j.WaitingForUserAction.HasValue ? j.WaitingForUserAction : (j.JobMetaNonWarranty.AccountingChargeRequiredDate.HasValue ? j.JobMetaNonWarranty.AccountingChargeRequiredDate : j.JobMetaNonWarranty.AccountingChargeAddedDate),
|
||||
ReadyForReturn = j.DeviceReadyForReturn.HasValue,
|
||||
EstimatedReturnTime = j.ExpectedClosedDate,
|
||||
ReadyForReturnSince = j.DeviceReadyForReturn,
|
||||
UserDisplayName = j.User.DisplayName,
|
||||
UserId = j.UserId,
|
||||
DeviceProfileId = j.Device.DeviceProfileId,
|
||||
DeviceAddressId = j.Device.DeviceProfile.DefaultOrganisationAddress
|
||||
}).GroupBy(j => j.UserId);
|
||||
{
|
||||
JobId = j.Id,
|
||||
WaitingForUserAction = j.WaitingForUserAction.HasValue || ((j.JobMetaNonWarranty.AccountingChargeRequiredDate.HasValue || j.JobMetaNonWarranty.AccountingChargeAddedDate.HasValue) && !j.JobMetaNonWarranty.AccountingChargePaidDate.HasValue),
|
||||
WaitingForUserActionSince = j.WaitingForUserAction.HasValue ? j.WaitingForUserAction : (j.JobMetaNonWarranty.AccountingChargeRequiredDate.HasValue ? j.JobMetaNonWarranty.AccountingChargeRequiredDate : j.JobMetaNonWarranty.AccountingChargeAddedDate),
|
||||
ReadyForReturn = j.DeviceReadyForReturn.HasValue,
|
||||
EstimatedReturnTime = j.ExpectedClosedDate,
|
||||
ReadyForReturnSince = j.DeviceReadyForReturn,
|
||||
UserId = j.Device.AssignedUserId,
|
||||
UserDisplayName = j.Device.AssignedUser.DisplayName,
|
||||
DeviceProfileId = j.Device.DeviceProfileId,
|
||||
DeviceAddressId = j.Device.DeviceProfile.DefaultOrganisationAddress
|
||||
}).GroupBy(j => j.UserId);
|
||||
|
||||
var thd = new List<Models.UserHeldDevices.UserHeldDeviceModel>();
|
||||
foreach (var userJobs in usersJobs)
|
||||
foreach (var job in jobs)
|
||||
{
|
||||
if (userJobs.Any(j => j.WaitingForUserAction))
|
||||
if (job.Any(j => j.WaitingForUserAction))
|
||||
{
|
||||
thd.Add(userJobs.Where(j => j.WaitingForUserAction).OrderBy(j => j.WaitingForUserActionSince).FirstOrDefault().ToUserHeldDeviceModel(dbContext));
|
||||
thd.Add(job.Where(j => j.WaitingForUserAction).OrderBy(j => j.WaitingForUserActionSince).FirstOrDefault().ToUserHeldDeviceModel(dbContext));
|
||||
}
|
||||
else
|
||||
{
|
||||
if (userJobs.All(j => j.ReadyForReturn))
|
||||
if (job.All(j => j.ReadyForReturn))
|
||||
{
|
||||
thd.Add(userJobs.FirstOrDefault().ToUserHeldDeviceModel(dbContext));
|
||||
thd.Add(job.FirstOrDefault().ToUserHeldDeviceModel(dbContext));
|
||||
}
|
||||
else
|
||||
{
|
||||
thd.Add(userJobs.Where(j => !j.ReadyForReturn).OrderByDescending(j => j.EstimatedReturnTime).FirstOrDefault().ToUserHeldDeviceModel(dbContext));
|
||||
thd.Add(job.Where(j => !j.ReadyForReturn).OrderByDescending(j => j.EstimatedReturnTime).FirstOrDefault().ToUserHeldDeviceModel(dbContext));
|
||||
}
|
||||
}
|
||||
}
|
||||
return thd;
|
||||
}
|
||||
private Models.UserHeldDevices.UserHeldDeviceModel GetUserHeldDevice(string userId)
|
||||
{
|
||||
var userJobs = dbContext.Jobs.Where(j => !j.ClosedDate.HasValue && j.UserId == userId && j.DeviceSerialNumber != null && ((j.DeviceHeld.HasValue && !j.DeviceReturnedDate.HasValue) || j.WaitingForUserAction.HasValue)).Select(j => new Models.UserHeldDevices.HeldJobDeviceModel
|
||||
{
|
||||
JobId = j.Id,
|
||||
WaitingForUserAction = j.WaitingForUserAction.HasValue,
|
||||
WaitingForUserActionSince = j.WaitingForUserAction,
|
||||
ReadyForReturn = j.DeviceReadyForReturn.HasValue,
|
||||
EstimatedReturnTime = j.ExpectedClosedDate,
|
||||
ReadyForReturnSince = j.DeviceReadyForReturn,
|
||||
UserDisplayName = j.User.DisplayName,
|
||||
UserId = j.UserId,
|
||||
DeviceProfileId = j.Device.DeviceProfileId,
|
||||
DeviceAddressId = j.Device.DeviceProfile.DefaultOrganisationAddress
|
||||
}).ToList();
|
||||
|
||||
if (userJobs == null || userJobs.Count == 0)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
else
|
||||
{
|
||||
if (userJobs.Any(j => j.WaitingForUserAction))
|
||||
{
|
||||
return userJobs.Where(j => j.WaitingForUserAction).OrderBy(j => j.WaitingForUserActionSince).FirstOrDefault().ToUserHeldDeviceModel(dbContext);
|
||||
}
|
||||
else
|
||||
{
|
||||
if (userJobs.All(j => j.ReadyForReturn))
|
||||
{
|
||||
return userJobs.FirstOrDefault().ToUserHeldDeviceModel(dbContext);
|
||||
}
|
||||
else
|
||||
{
|
||||
return userJobs.Where(j => !j.ReadyForReturn).OrderByDescending(j => j.EstimatedReturnTime).FirstOrDefault().ToUserHeldDeviceModel(dbContext);
|
||||
}
|
||||
}
|
||||
}
|
||||
#endregion
|
||||
|
||||
private List<Models.UserHeldDevices.UserHeldDeviceModel> GetUserHeldDevices()
|
||||
{
|
||||
return GetUserHeldDevices(dbContext.Jobs);
|
||||
}
|
||||
private Models.UserHeldDevices.UserHeldDeviceModel GetUserHeldDevice(string UserId)
|
||||
{
|
||||
return GetUserHeldDevices(dbContext.Jobs.Where(j => j.Device.AssignedUserId == UserId)).FirstOrDefault();
|
||||
}
|
||||
|
||||
public virtual ActionResult Index()
|
||||
|
||||
Reference in New Issue
Block a user