Esempio n. 1
0
        public static async Task <Framework.Models.DataAccessLayerMessageOfBoolean> GetExistsMessageAsync <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 = await IQueryableHelper.AnyAsync(
                    _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);
        }
Esempio n. 2
0
        public static async Task <TMessage> GetCollectionMessageAsync <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 = await IQueryableHelper.AnyAsync(
                    _Query
                    , currentIndex
                    , pageSize
                    );

                if (_Exists)
                {
                    IEnumerable <TItem> _retval;

                    if (currentIndex == -1 || pageSize == -1)
                    {
                        _retval = await _Query.ToListAsync();
                    }
                    else
                    {
                        _retval = await _Query.Skip(currentIndex).Take(pageSize).ToListAsync();
                    }
                    _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);
        }