public static TMessage GetCollectionMessage <TMessage, TCollection, TItem>(IQueryable <TItem> _Query, int currentIndex, int pageSize, string logMessage) where TMessage : Framework.Models.DataAccessLayerMessageBase <TCollection>, new() where TCollection : List <TItem>, new() { //log.Info(string.Format("{0}: {1}", Framework.Models.LoggingOptions.Data_Access_Layer_Process_Started.ToString(), logMessage)); TMessage _retMessage = new TMessage(); try { bool _Exists = IQueryableHelper.Any( _Query , currentIndex , pageSize ); if (_Exists) { IEnumerable <TItem> _retval; if (currentIndex == -1 || pageSize == -1) { _retval = _Query; } else { _retval = _Query.Skip(currentIndex).Take(pageSize); } _retMessage.QueryPagingResult = new Framework.Queries.QueryPagingResult(); _retMessage.QueryPagingResult.PageSize = pageSize; _retMessage.QueryPagingResult.RecordCountOfCurrentPage = _retval.Count(); _retMessage.DataAccessLayerMessageStatus = _retMessage.QueryPagingResult.RecordCountOfCurrentPage == 0 ? Framework.Models.DataAccessLayerMessageStatus.SuccessButNoResult : Framework.Models.DataAccessLayerMessageStatus.Success; _retMessage.QueryPagingResult.CurrentIndexOfStartRecord = currentIndex; _retMessage.QueryPagingResult.CountOfRecords = _Query.Count(); _retMessage.Result = new TCollection(); _retMessage.Result.AddRange(_retval); } else { _retMessage.DataAccessLayerMessageStatus = Framework.Models.DataAccessLayerMessageStatus.SuccessButNoResult; _retMessage.Result = null; } } catch (Exception ex) { _retMessage.DataAccessLayerMessageStatus = Framework.Models.DataAccessLayerMessageStatus.Fail; _retMessage.Result = null; _retMessage.Message = ex.Message; //log.Error(string.Format("{0}: {1}", Framework.Models.LoggingOptions.Data_Access_Layer_Process_Failed.ToString(), logMessage), ex); } //log.Info(string.Format("{0}: {1}", Framework.Models.LoggingOptions.Data_Access_Layer_Process_Ended.ToString(), logMessage)); return(_retMessage); }
public static Framework.Models.DataAccessLayerMessageOfBoolean GetExistsMessage <T>(IQueryable <T> _Query, int currentIndex, int pageSize, string logMessage) { //log.Info(string.Format("{0}: {1}", Framework.Models.LoggingOptions.Data_Access_Layer_Process_Started.ToString(), logMessage)); Framework.Models.DataAccessLayerMessageOfBoolean _retMessage = new Framework.Models.DataAccessLayerMessageOfBoolean(); try { bool _retval = IQueryableHelper.Any( _Query , currentIndex , pageSize ); _retMessage.DataAccessLayerMessageStatus = Framework.Models.DataAccessLayerMessageStatus.Success; _retMessage.Result = _retval; } catch (Exception ex) { _retMessage.DataAccessLayerMessageStatus = Framework.Models.DataAccessLayerMessageStatus.Fail; _retMessage.Result = false; _retMessage.Message = ex.Message; //log.Error(string.Format("{0}: {1}", Framework.Models.LoggingOptions.Data_Access_Layer_Process_Failed.ToString(), logMessage), ex); } //log.Info(string.Format("{0}: {1}", Framework.Models.LoggingOptions.Data_Access_Layer_Process_Ended.ToString(), logMessage)); return(_retMessage); }