Beispiel #1
0
        public IList <CoinTransactionViewModel> SearchTransactionHistoryFunc(DataTableAjaxPostModel model, out int filteredResultsCount, out int totalResultsCount, int?sysUserId, int?currencyId)
        {
            var user     = _sysUserService.Queryable().FirstOrDefault(x => x.Id == (sysUserId ?? HttpContext.Session.GetObjectFromJson <SysUserViewModel>("CurrentUser").Id));
            var searchBy = (model.search != null) ? model.search.value?.ToLower() : null;
            var take     = model.length;
            var skip     = model.start;

            string sortBy  = "";
            bool   sortDir = true;

            if (model.order != null)
            {
                // in this example we just default sort on the 1st column
                sortBy  = model.columns[model.order[0].column].data;
                sortDir = model.order[0].dir.ToLower() == "desc";
            }

            // NULLABLE INT CANNOT BE USED IN LINQ, SO VALUE CAST IS A MUST
            var _currencyId = 0;

            if (currencyId.HasValue)
            {
                _currencyId = currencyId.Value;
            }

            totalResultsCount = _coinTransactionService
                                .Queryable()
                                .Where(x => x.SysUserId == user.Id && (_currencyId == 0 ? true : x.CurrencyId == _currencyId))
                                .Count();

            // search the dbase taking into consideration table sorting and paging
            var transactionHistory = _coinTransactionService
                                     .Query()
                                     .Include(x => x.Currency)
                                     .Where(x => x.SysUserId == user.Id && (_currencyId == 0 ? true : x.CurrencyId == _currencyId))
                                     .Select(x => Mapper.Map <CoinTransactionViewModel>(x));

            if (string.IsNullOrEmpty(searchBy))
            {
                filteredResultsCount = totalResultsCount;
            }
            else
            {
                transactionHistory = transactionHistory
                                     .Where(x => x.CreatedDateInString.ToLower().Contains(searchBy) ||
                                            x.ToWalletAddress.ToLower().Contains(searchBy) ||
                                            x.CoinAmountInString.ToLower().Contains(searchBy) ||
                                            x.TypeInString.ToLower().Contains(searchBy) ||
                                            x.CurrencyInString.ToLower().Contains(searchBy) ||
                                            x.StatusInEnum.ToString().ToLower().Contains(searchBy));

                filteredResultsCount = transactionHistory.Count();
            }

            return(transactionHistory.AsQueryable().OrderBy(sortBy, sortDir).Skip(skip).Take(take).ToList());
        }