/// <summary>
        /// Get List of EndPoint Commands.
        /// </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="EndPointID">Filter by EndPoint ID. You can keep it null or empty to ignore this filter.</param>
        /// <returns></returns>
        public APIEndpointCommandResponseModels.GetEndpointCommandsList GetEndpointCommands(string searchFor, long EndPointID, long ThingID, long locationID, bool loadEndpoint, int pageNumber, int pageSize)
        {
            APIEndpointCommandResponseModels.GetEndpointCommandsList result = new APIEndpointCommandResponseModels.GetEndpointCommandsList();

            IPagedList <EndPointCommand> endpointCommandsPL = uow_Repositories.repoEndPointCommands.GetPagedList(searchFor, EndPointID, ThingID, locationID, pageNumber, pageSize);
            List <EndPointCommand>       endpointCommands   = endpointCommandsPL.ToList();

            List <APIEndPointCommand> listAPIEndpointCommands = new List <APIEndPointCommand>();

            foreach (EndPointCommand cmd in endpointCommands)
            {
                APIEndPointCommand apiCMD = TypesMapper.APIEndPointCommandAdapter.fromEndpointCommand(cmd, loadEndpoint);
                listAPIEndpointCommands.Add(apiCMD);
            }
            result.EndpointCommands = listAPIEndpointCommands;


            PagingInfoResponseModel pagingInfo = new PagingInfoResponseModel();

            pagingInfo.CurrentPage  = endpointCommandsPL.PageNumber;
            pagingInfo.ItemsPerPage = endpointCommandsPL.PageSize;
            pagingInfo.ItemsCount   = endpointCommandsPL.TotalItemCount;
            pagingInfo.PagesCount   = endpointCommandsPL.PageCount;
            result.PagingInfo       = pagingInfo;
            return(result);
        }
        public static APIEndPointCommand fromEndpointCommand(EndPointCommand sourceEndpointCommand)
        {
            APIEndPointCommand result = new APIEndPointCommand();

            result.ID          = sourceEndpointCommand.ID;
            result.Title       = sourceEndpointCommand.Title;
            result.Description = sourceEndpointCommand.Description;
            result.CommandCode = sourceEndpointCommand.CommandCode;
            result.EndPointID  = sourceEndpointCommand.EndPointID;

            return(result);
        }
        public static APIEndPointCommand fromEndpointCommand(EndPointCommand sourceEndpointCommand, bool loadEndpoint)
        {
            APIEndPointCommand result = new APIEndPointCommand();

            result.ID          = sourceEndpointCommand.ID;
            result.Title       = sourceEndpointCommand.Title;
            result.Description = sourceEndpointCommand.Description;
            result.CommandCode = sourceEndpointCommand.CommandCode;

            #region Load Parents
            if (loadEndpoint)
            {
                #region EndPoint
                result.EndPoint = TypesMapper.APIEndPointAdapter.fromEndpoint(sourceEndpointCommand.Endpoint, false, false);

                #endregion
            }
            #endregion

            return(result);
        }
Example #4
0
        /// <summary>
        /// Get List of EndPoint Commands.
        /// </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="EndPointID">Filter by EndPoint ID. You can keep it null or empty to ignore this filter.</param>
        /// <returns></returns>
        public List <APIEndPointCommand> GetEndpointCommands(int pageNumber, int pageSize, bool loadParents, bool loadChilds, string searchFor, long locationID, long ThingID, long EndPointID)
        {
            List <APIEndPointCommand> result = new List <APIEndPointCommand>();
            List <EndPointCommand>    cmds   = db.EndPointCommands
                                               .Where(e =>
                                                      (e.Title.Contains(searchFor) || (searchFor == null || searchFor == "")) &&//Filter by Search "Title"
                                                      ((e.Endpoint.Thing.LinkThingsLocations.Any(l => l.LocationID == locationID)) || (locationID == null || locationID == 0)) &&//Filter by locationID
                                                      ((e.Endpoint.ThingID == ThingID) || (ThingID == null || ThingID == 0)) //Filter by ThingID
                                                      ).OrderBy(e => e.Title)
                                               .Skip(pageSize * (pageNumber - 1))
                                               .Take(pageSize)
                                               .ToList();

            foreach (EndPointCommand cmd in cmds)
            {
                APIEndPointCommand apiCmd = new APIEndPointCommand();
                apiCmd = TypesMapper.APIEndPointCommandAdapter.fromEndpointCommand(cmd, loadParents, loadChilds);
                result.Add(apiCmd);
            }
            return(result);
        }