Пример #1
0
        public dynamic GetList([FromQuery] OperatorCriteriaModel criteria, [FromQuery] IDataTablesRequest request)
        {
            try
            {
                //var query = _accountService.GetByCriteria(criteria);
                var query = _accountService.GetAll();

                if (criteria.AccountTypeId.HasValue)
                {
                    query = query.Where(x => x.AccountTypeId == criteria.AccountTypeId.Value);
                }
                else
                {
                    // Quan ly nguo dung
                    query = query.Where(x => x.AccountTypeId == AccountTypeEnum.Suppervisor || x.AccountTypeId == AccountTypeEnum.Saler);
                }

                var operators =
                    query
                    .Select(x => new OperatorRequestModel
                {
                    Id                = x.AccountId,
                    Username          = x.Username,
                    Fullname          = x.FullName,
                    Address           = x.Address,
                    Email             = x.Email,
                    Password          = x.Password,
                    Phone             = x.Phone,
                    AccountStatusId   = x.AccountStatusId,
                    AccountTypeId     = x.AccountTypeId,
                    BranchId          = x.BranchId,
                    AccountTypeName   = x.AccountType.AccountTypeName,
                    AccountStatusName = x.AccountStatus.AccountStatusName,
                    BranchName        = x.Branch.BranchName,
                })
                    .ToList()
                    .AsQueryable();

                var filteredData = operators;

                return(ToDataTableResponse <OperatorRequestModel>(filteredData, request));
            }
            catch (Exception ex)
            {
                _logger.LogError(ex, this.GetType().Name);
                return(ToDataTableResponse <OperatorRequestModel>());
            }
        }
        public dynamic Search([FromQuery] OperatorCriteriaModel criteria, [FromQuery] IDataTablesRequest request)
        {
            try
            {
                var query     = _accountService.GetAll();
                var operators =
                    query
                    .Select(x => _mapper.Map <OperatorItemModel>(x))
                    .ToList()
                    .AsQueryable();

                var filteredData = operators;

                return(ToDataTableResponse <OperatorItemModel>(filteredData, request));
            }
            catch (Exception ex)
            {
                _logger.LogError(ex, this.GetType().Name);
                return(ToDataTableResponse <OperatorItemModel>());
            }
        }
        public IQueryable <Account> GetByCriteria(OperatorCriteriaModel criteria)
        {
            var query =
                context.Accounts
                .Include(x => x.AccountType)
                .Include(x => x.AccountStatus)
                .Include(x => x.Branch)
                .AsQueryable();

            if (criteria.Username != null)
            {
                query = query.Where(x => x.Username.Contains(criteria.Username));
            }

            if (criteria.Name != null)
            {
                query = query.Where(x => x.FullName.Contains(criteria.Name));
            }


            return(query);
        }