using System; using System.Linq; using InABox.Core; namespace Comal.Classes { public enum GPSLocationType { Office, Job, Supplier, Employee } public interface IGeoFence { Guid ID { get; set; } String Code { get; set; } string Name { get; set; } string Street { get; set; } string City { get; set; } string State { get; set; } string Country { get; set; } string PostCode { get; set; } double Latitude { get; set; } double Longitude { get; set; } string Geofence { get; set; } GPSLocationType Type { get; set; } } public class GeoFenceUnionGenerator : AutoEntityUnionGenerator { protected override void Configure() { AddTable() .WithFilter(new Filter(x=>x.DeliveryAddress.Geofence).IsNotEqualTo("")) .AddConstant(x => x.Code, "OFFICE") .AliasField(x => x.Name, x => x.CompanyName) .AliasField(x => x.Street, x => x.DeliveryAddress.Street) .AliasField(x => x.City, x => x.DeliveryAddress.City) .AliasField(x => x.State, x => x.DeliveryAddress.State) .AliasField(x => x.PostCode, x => x.DeliveryAddress.PostCode) .AliasField(x => x.Latitude, x => x.DeliveryAddress.Location.Latitude) .AliasField(x => x.Longitude, x => x.DeliveryAddress.Location.Longitude) .AliasField(x => x.Geofence, x => x.DeliveryAddress.Geofence) .AddConstant(x=>x.Type,GPSLocationType.Office); AddTable() .WithFilter(new Filter(x=>x.SiteAddress.Geofence).IsNotEqualTo("").And(X=>X.JobStatus.Active).IsEqualTo(true)) .AliasField(x => x.Code, x => x.JobNumber) .AliasField(x => x.Name, x => x.Name) .AliasField(x => x.Street, x => x.SiteAddress.Street) .AliasField(x => x.City, x => x.SiteAddress.City) .AliasField(x => x.State, x => x.SiteAddress.State) .AliasField(x => x.PostCode, x => x.SiteAddress.PostCode) .AliasField(x => x.Latitude, x => x.SiteAddress.Location.Latitude) .AliasField(x => x.Longitude, x => x.SiteAddress.Location.Longitude) .AliasField(x => x.Geofence, x => x.SiteAddress.Geofence) .AddConstant(x=>x.Type,GPSLocationType.Job); AddTable() .WithFilter(new Filter(x=>x.Delivery.Geofence).IsNotEqualTo("")) .AliasField(x => x.Code, x => x.Code) .AliasField(x => x.Name, x => x.Name) .AliasField(x => x.Street, x => x.Delivery.Street) .AliasField(x => x.City, x => x.Delivery.City) .AliasField(x => x.State, x => x.Delivery.State) .AliasField(x => x.PostCode, x => x.Delivery.PostCode) .AliasField(x => x.Latitude, x => x.Delivery.Location.Latitude) .AliasField(x => x.Longitude, x => x.Delivery.Location.Longitude) .AliasField(x => x.Geofence, x => x.Delivery.Geofence) .AddConstant(x=>x.Type,GPSLocationType.Supplier); AddTable() .WithFilter(new Filter(x=>x.Address.Geofence).IsNotEqualTo("")) .AliasField(x => x.Code, x => x.Code) .AliasField(x => x.Name, x => x.Name) .AliasField(x => x.Street, x => x.Address.Street) .AliasField(x => x.City, x => x.Address.City) .AliasField(x => x.State, x => x.Address.State) .AliasField(x => x.PostCode, x => x.Address.PostCode) .AliasField(x => x.Latitude, x => x.Address.Location.Latitude) .AliasField(x => x.Longitude, x => x.Address.Location.Longitude) .AliasField(x => x.Geofence, x => x.Address.Geofence) .AddConstant(x=>x.Type,GPSLocationType.Employee); } public override bool Distinct => true; public override Column[] IDColumns => new Column[] { new Column(x=>x.ID) }; } [UserTracking(typeof(GPSTrackerLocation))] [AutoEntity(typeof(GeoFenceUnionGenerator))] public class GeoFence : Entity, IRemotable, IPersistent, IGeoFence, ILicense { public string Code { get; set; } public string Name { get; set; } public string Street { get; set; } public string City { get; set; } public string State { get; set; } public string Country { get; set; } public string PostCode { get; set; } public double Latitude { get; set; } public double Longitude { get; set; } public string Geofence { get; set; } public GPSLocationType Type { get; set; } } }