JobScopeLookups.cs 2.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  1. using System.Linq;
  2. using InABox.Core;
  3. namespace Comal.Classes
  4. {
  5. public class JobScopeLookups : EntityLookup<JobScope>, ILookupDefinition<JobScope, InvoiceLine>, ILookupDefinition<JobScope, Job>
  6. , ILookupDefinition<JobScope, Assignment>
  7. {
  8. #region Invoice Lines
  9. public Filter<JobScope> DefineFilter(InvoiceLine[] items)
  10. {
  11. if (items == null)
  12. return new Filter<JobScope>(x => x.ID).IsEqualTo(CoreUtils.FullGuid);
  13. var jobid = CoreUtils.FullGuid;
  14. foreach (var item in items)
  15. {
  16. if (jobid == CoreUtils.FullGuid)
  17. jobid = item.InvoiceLink.JobLink.ID;
  18. if (item.InvoiceLink.JobLink.ID != jobid)
  19. return new Filter<JobScope>(x => x.ID).IsEqualTo(CoreUtils.FullGuid);
  20. }
  21. return new Filter<JobScope>(x => x.Job.ID).IsEqualTo(jobid).And(x => x.Status.Approved).IsEqualTo(true);
  22. }
  23. Columns<InvoiceLine> ILookupDefinition<JobScope, InvoiceLine>.DefineFilterColumns()
  24. => new Columns<InvoiceLine>(x => x.InvoiceLink.JobLink.ID);
  25. #endregion
  26. #region Assignments
  27. public Filter<JobScope> DefineFilter(Assignment[] items)
  28. {
  29. var item = items?.Length == 1 ? items[0] : null;
  30. if (item != null)
  31. return new Filter<JobScope>(x => x.Job.ID).IsEqualTo(item.JobLink.ID).And(x => x.Status.Approved).IsEqualTo(true);
  32. return new Filter<JobScope>(x => x.ID).None();
  33. }
  34. Columns<Assignment> ILookupDefinition<JobScope, Assignment>.DefineFilterColumns()
  35. => new Columns<Assignment>(x=>x.JobLink.ID);
  36. #endregion
  37. #region Jobs (Default Scope)
  38. public Filter<JobScope> DefineFilter(Job[] items)
  39. {
  40. var item = items?.Length == 1 ? items[0] : null;
  41. if (item != null)
  42. return new Filter<JobScope>(x => x.Job.ID).IsEqualTo(item.ID).And(x => x.Status.Approved).IsEqualTo(true);
  43. return new Filter<JobScope>(x => x.ID).None();
  44. }
  45. Columns<Job> ILookupDefinition<JobScope, Job>.DefineFilterColumns()
  46. => new Columns<Job>(x=>x.ID);
  47. #endregion
  48. public override Columns<JobScope> DefineColumns()
  49. {
  50. return new Columns<JobScope>().Default();
  51. }
  52. public override Filter<JobScope> DefineFilter()
  53. {
  54. return new Filter<JobScope>(x => x.ID).IsEqualTo(CoreUtils.FullGuid);
  55. }
  56. public override SortOrder<JobScope> DefineSortOrder()
  57. {
  58. return new SortOrder<JobScope>(x => x.Number);
  59. }
  60. }
  61. }