コード例 #1
0
        public PagingOutputViewModel <TransactionListViewModel> SearchTransaction(TransactionFilterViewModel filter)
        {
            var output = new PagingOutputViewModel <TransactionListViewModel>
            {
                ItemsPerPage = 15
            };

            var repository = _unitOfWork.TransactionRepository.All().Include(s => s.Receiver).ThenInclude(s => s.Customer);

            if (!string.IsNullOrEmpty(filter.CustomerNo))
            {
                repository.Where(s => s.Receiver.Customer.CustomerCode == filter.CustomerNo);
            }

            if (!string.IsNullOrEmpty(filter.CustomerPhone))
            {
                repository.Where(s => s.Receiver.Customer.Phone == filter.CustomerPhone);
            }

            if (!string.IsNullOrEmpty(filter.TransactionNo))
            {
                repository.Where(s => s.TransactionNo == filter.TransactionNo);
            }

            if (!string.IsNullOrEmpty(filter.CreateDateStart.ToString()))
            {
                repository.Where(s => DateTimeOffset.Compare(s.CreatedOn.Value, filter.CreateDateStart.Value) >= 0);
            }

            if (!string.IsNullOrEmpty(filter.CreateDateEnd.ToString()))
            {
                repository.Where(s => DateTimeOffset.Compare(s.CreatedOn.Value, filter.CreateDateEnd.Value) <= 0);
            }

            var data = repository.Select(trans => new TransactionListViewModel
            {
                TransactionId = trans.TransactionId,
                TransactionNo = trans.TransactionNo,
                CustomerCode  = trans.Receiver.Customer.CustomerCode,
                CustomerName  = trans.Receiver.Customer.FullName,
                ReceiverName  = trans.Receiver.ReceiverName,
                CurrencyName  = ((Currency)trans.CurrencyId).ToString(),
                Amount        = trans.Amount,
                CreatedOn     = trans.CreatedOn
            });


            data = data.Take(output.ItemsPerPage);

            // Enumerate the data
            output.TotalItems = repository.Count();
            output.Data       = data.ToList();

            return(output);
        }
コード例 #2
0
        public PagingOutputViewModel <UserBasicInfoViewModel> GetAll(PagingInputViewModel param)
        {
            var output = new PagingOutputViewModel <UserBasicInfoViewModel>
            {
                ItemsPerPage = param.ItemsPerPage
            };

            var repository = _unitOfWork.UserRepository.All();

            if (!string.IsNullOrEmpty(param.Keyword))
            {
                repository = repository
                             .Where(user => user.FirstName.Contains(param.Keyword) ||
                                    user.LastName.Contains(param.Keyword) ||
                                    user.Email.Contains(param.Keyword) ||
                                    user.PhoneNumber.Contains(param.Keyword) ||
                                    user.UserRoles.Any(role => role.Role.Name.Contains(param.Keyword)));
            }

            var data = repository.Select(user => new UserBasicInfoViewModel
            {
                UserId       = user.Id,
                FirstName    = user.FirstName,
                LastName     = user.LastName,
                Email        = user.Email,
                Phone        = user.PhoneNumber,
                Roles        = user.UserRoles.Select(ur => ur.Role.Name).ToList(),
                IsActive     = user.LockoutEnd == null || user.LockoutEnd < DateTimeOffset.Now,
                LockedOutEnd = user.LockoutEnd < DateTimeOffset.Now ? null : user.LockoutEnd
            });

            if (!string.IsNullOrEmpty(param.OrderBy))
            {
                data = data.OrderByProperty(param.OrderBy, param.IsDesc);
            }

            data = data.Skip((param.PageNumber - 1) * param.ItemsPerPage).Take(param.ItemsPerPage);

            // Enumerate the data
            output.TotalItems = repository.Count();
            output.Data       = data.ToList();

            return(output);
        }
コード例 #3
0
        public PagingOutputViewModel <CustomerInfoViewModel> GetAllCustomer(PagingInputViewModel param)
        {
            var output = new PagingOutputViewModel <CustomerInfoViewModel>
            {
                ItemsPerPage = param.ItemsPerPage
            };

            var repository = _unitOfWork.CustomerRepository.All();

            if (!string.IsNullOrEmpty(param.Keyword))
            {
                repository = repository
                             .Where(cus => cus.FullName.Contains(param.Keyword) ||
                                    cus.CustomerCode.Contains(param.Keyword) ||
                                    cus.Phone.Contains(param.Keyword));
            }

            var data = repository.Select(customer => new CustomerInfoViewModel
            {
                CustomerId         = customer.CustomerId,
                FullName           = customer.FullName,
                CustomerCode       = customer.CustomerCode,
                Email              = customer.Email,
                PhoneNumber        = customer.Phone,
                Address            = customer.Address,
                SelectedReceiverId = customer.SelectedReceiverId
            });

            if (!string.IsNullOrEmpty(param.OrderBy))
            {
                data = data.OrderByProperty(param.OrderBy, param.IsDesc);
            }

            data = data.Skip((param.PageNumber - 1) * param.ItemsPerPage).Take(param.ItemsPerPage);

            // Enumerate the data
            output.TotalItems = repository.Count();
            output.Data       = data.ToList();

            return(output);
        }