public static APIThingEnd fromThingEnd(ThingEnd sourceThingEnd, bool loadParents, bool loadChilds) { APIThingEnd result = new APIThingEnd(); result.ID = sourceThingEnd.ID; result.LastIOID = sourceThingEnd.LastIOID; result.LastIOTimeStamp = sourceThingEnd.LastIOTimeStamp; result.LastIOTimeStampUTC = sourceThingEnd.LastIOTimeStampUTC; result.LastIOValue = sourceThingEnd.LastIOValue; #region Load MasterTypes result.EndPointType = APIEndPointTypeAdapter.fromEndPointType(sourceThingEnd.EndPointType); #endregion #region Load Parents if (loadParents) { result.Thing = TypesMapper.APIThingAdapter.fromThing(sourceThingEnd.Thing, false, false); result.LastIOEndPoint = TypesMapper.APIEndPointAdapter.fromEndpoint(sourceThingEnd.EndPointIO.Endpoint, false, false); } #endregion #region Load Childs #endregion return(result); }
/// <summary> /// Get List of ThingEnds. /// </summary> /// <param name="pageNumber">Page Number.</param> /// <param name="pageSize">Items count per page.</param> /// <param name="loadParents">Enable or Disable loading the Parents objects.</param> /// <param name="loadChilds">Enable or Disable loading the Childs objects.</param> /// <param name="searchFor">Search text as per the 'Title' field.</param> /// <param name="locationID">Filter by Location ID. You can keep it null or empty to ignore this filter.</param> /// <param name="thingID">Filter by Thing ID. You can keep it null or empty to ignore this filter.</param> /// <param name="thingCategoryID">Filter by ThingCategory ID. You can keep it null or empty to ignore this filter.</param> /// <param name="endpointTypeID">Filter by EndPointType ID. You can keep it null or empty to ignore this filter.</param> /// <returns></returns> public APIThingEndResponseModels.GetThingEndsList GetThingEndsList(string searchFor, long?locationID, long?thingID, long?thingCategoryID, long?endpointTypeID, bool loadThing, bool loadEndpoint, int pageNumber, int pageSize) { APIThingEndResponseModels.GetThingEndsList result = new APIThingEndResponseModels.GetThingEndsList(); IPagedList <ThingEnd> thingEndsPL = uof_Repositories.repoThingEnds.GetPagedList(searchFor, locationID, thingID, thingCategoryID, endpointTypeID, endpointTypeID, pageNumber, pageSize); List <ThingEnd> thingEnds = thingEndsPL.ToList(); List <APIThingEnd> listAPIThingEnds = new List <APIThingEnd>(); foreach (ThingEnd te in thingEnds) { APIThingEnd apiThingEnd = TypesMapper.APIThingEndAdapter.fromThingEnd(te, loadThing, loadThing); listAPIThingEnds.Add(apiThingEnd); } result.ThingEnds = listAPIThingEnds; PagingInfoResponseModel pagingInfo = new PagingInfoResponseModel(); pagingInfo.CurrentPage = thingEndsPL.PageNumber; pagingInfo.ItemsPerPage = thingEndsPL.PageSize; pagingInfo.ItemsCount = thingEndsPL.TotalItemCount; pagingInfo.PagesCount = thingEndsPL.PageCount; result.PagingInfo = pagingInfo; return(result); }
public static APIThingEnd fromThingEnd(ThingEnd sourceThingEnd) { APIThingEnd result = new APIThingEnd(); result.ID = sourceThingEnd.ID; result.Thing = TypesMapper.APIThingAdapter.fromThing(sourceThingEnd.Thing); result.EndPointType = TypesMapper.APIEndPointTypeAdapter.fromEndPointType(sourceThingEnd.EndPointType); result.LastIOID = sourceThingEnd.LastIOID; result.LastIOTimeStamp = sourceThingEnd.LastIOTimeStamp; result.LastIOTimeStampUTC = sourceThingEnd.LastIOTimeStampUTC; result.LastIOValue = sourceThingEnd.LastIOValue; return(result); }
/// <summary> /// Get List of ThingEnds. /// </summary> /// <param name="pageNumber">Page Number.</param> /// <param name="pageSize">Items count per page.</param> /// <param name="loadParents">Enable or Disable loading the Parents objects.</param> /// <param name="loadChilds">Enable or Disable loading the Childs objects.</param> /// <param name="searchFor">Search text as per the 'Title' field.</param> /// <param name="locationID">Filter by Location ID. You can keep it null or empty to ignore this filter.</param> /// <param name="thingID">Filter by Thing ID. You can keep it null or empty to ignore this filter.</param> /// <param name="thingCategoryID">Filter by ThingCategory ID. You can keep it null or empty to ignore this filter.</param> /// <param name="endpointTypeID">Filter by EndPointType ID. You can keep it null or empty to ignore this filter.</param> /// <returns></returns> public List <APIThingEnd> GetThingEnds(int pageNumber, int pageSize, bool loadParents, bool loadChilds, string searchFor, long locationID, long thingID, long thingCategoryID, long endpointTypeID) { List <APIThingEnd> result = new List <APIThingEnd>(); List <ThingEnd> thingEnds = db.ThingEnds.Where(e => ((e.Thing.Title.Contains(searchFor) || (searchFor == null || searchFor == "")) && ((e.ThingID == thingID) || (thingID == null || thingID == 0)) && ((e.EndPointTypeID == endpointTypeID) || (endpointTypeID == null || endpointTypeID == 0)) && ((e.Thing.CategoryID == thingCategoryID) || (thingCategoryID == null || thingCategoryID == 0)) && ((e.Thing.LinkThingsLocations.Any(l => l.LocationID == locationID)) || (locationID == null || locationID == 0)) )).OrderBy(o => o.ThingID).ThenBy(o => o.EndPointTypeID) .Skip(pageSize * (pageNumber - 1)).Take(pageSize).ToList(); foreach (ThingEnd te in thingEnds) { APIThingEnd apiThingEnd = new APIThingEnd(); apiThingEnd = TypesMapper.APIThingEndAdapter.fromThingEnd(te, loadParents, loadChilds); result.Add(apiThingEnd); } return(result); }
public static APIThing fromThing(Thing sourceThing, bool loadParents, bool loadChilds) { APIThing result = new APIThing(); result.ID = sourceThing.ID; result.Title = sourceThing.Title; result.UTC_Diff = sourceThing.UTC_Diff; #region Load Master Types result.ThingsType = TypesMapper.APIThingsTypeAdapter.fromThingsType(sourceThing.ThingCategory); #endregion #region Parents if (loadParents) { #region Locations List <APILocation> apiLocations = new List <APILocation>(); List <Location> locations = db.Locations.Where(l => l.LinkThingsLocations.Any(ll => ll.LocationID == l.ID)).ToList(); foreach (Location location in locations) { APILocation apiLocation = TypesMapper.APILocationAdapter.fromLocation(location, false, false); apiLocations.Add(apiLocation); } result.Locations = apiLocations; #endregion } #endregion #region Load Childs if (loadChilds) { #region EndPoints List <APIEndPoint> apiEndPoints = new List <APIEndPoint>(); foreach (Endpoint endpoint in sourceThing.Endpoints) { APIEndPoint apiEndpoint = TypesMapper.APIEndPointAdapter.fromEndpoint(endpoint, false, false); apiEndPoints.Add(apiEndpoint); } result.EndPoints = apiEndPoints; #endregion #region ThingEnds List <APIThingEnd> apiThingEnds = new List <APIThingEnd>(); foreach (ThingEnd thingEnd in sourceThing.ThingEnds) { APIThingEnd apiThingEnd = TypesMapper.APIThingEndAdapter.fromThingEnd(thingEnd, false, false); apiThingEnds.Add(apiThingEnd); } result.ThingEnds = apiThingEnds; #endregion #region APIThingExtensionValues List <APIThingExtensionValue> apiThingExtensionValues = new List <APIThingExtensionValue>(); foreach (ThingExtensionValue thingExtensionValue in sourceThing.ThingExtensionValues) { APIThingExtensionValue apiThingExtensionValue = TypesMapper.APIThingExtensionValueAdapter.fromThingExtensionValue(thingExtensionValue, true, false); apiThingExtensionValues.Add(apiThingExtensionValue); } result.APIThingExtensionValues = apiThingExtensionValues; #endregion } result.ThingEndsCount = sourceThing.ThingEnds.Count; #endregion List <APIEndPoint> apiEnds = new List <APIEndPoint>(); //foreach(Endpoint end in sourceThing.Endpoints) //{ // APIEndPoint apiEnd = new APIEndPoint(); // apiEnd = TypesMapper.APIEndPointAdapter.fromEndpoint(end); // apiEnds.Add(apiEnd); //} //result.EndPoints = apiEnds; return(result); }