public async Task <ActionResult <ViewPagingDataResult <UserDataViewModel> > > GetData
            (UserDataRequestDto userDataRequest)
        {
            var data =
                await _userService.GetDataAsync(userDataRequest);

            var result = new ViewPagingDataResult <UserDataViewModel>
            {
                PageIndex  = data.PageIndex,
                PageSize   = data.PageSize,
                TotalCount = data.TotalCount,
                Result     = data.Result.Select(c => new UserDataViewModel
                {
                    Id              = c.Id,
                    IsActive        = c.IsActive,
                    BirthDate       = c.BirthDate,
                    EmailAddress    = c.EmailAddress,
                    FullName        = c.FullName,
                    NationalCode    = c.NationalCode,
                    CellPhoneNumber = c.CellPhoneNumber,
                    UserType        = (ViewModels.Enums.UserType)c.UserType,
                }).ToList(),
            };

            return(result);
        }
Esempio n. 2
0
        public async Task <DataResult <UserDto> > GetDataAsync
            (UserDataRequestDto userDataRequest)
        {
            var predicate = PredicateBuilder.True <User>();

            if (userDataRequest.IsActive.HasValue)
            {
                predicate = predicate.And(c => c.IsActive == userDataRequest.IsActive.Value);
            }

            if (!string.IsNullOrWhiteSpace(userDataRequest.FullName))
            {
                predicate = predicate.And(c => c.FirstName.Contains(userDataRequest.FullName) ||
                                          c.LastName.Contains(userDataRequest.FullName));
            }

            if (!string.IsNullOrWhiteSpace(userDataRequest.EmailAddress))
            {
                predicate = predicate.And(c => c.EmailAddress.ToLower() == userDataRequest.EmailAddress.ToLower());
            }

            if (!string.IsNullOrWhiteSpace(userDataRequest.NationalCode))
            {
                predicate = predicate.And(c => c.NationalCode == userDataRequest.NationalCode);
            }

            if (userDataRequest.UserType.HasValue)
            {
                predicate = predicate.And(c => c.UserType == userDataRequest.UserType.Value);
            }

            var data =
                await _unitOfWork.UserRepository.GetWithRequestAsync(userDataRequest, predicate);

            var result = new DataResult <UserDto>
            {
                PageIndex  = data.PageIndex,
                PageSize   = data.PageSize,
                TotalCount = data.TotalCount,
                Result     = data.Result.Select(c => new UserDto
                {
                    Id              = c.Id,
                    IsActive        = c.IsActive,
                    FirstName       = c.FirstName,
                    LastName        = c.LastName,
                    NationalCode    = c.NationalCode,
                    BirthDate       = c.BirthDate,
                    CellPhoneNumber = c.CellPhoneNumber,
                    UserType        = c.UserType,
                    EmailAddress    = c.EmailAddress,
                }).ToList(),
            };

            return(result);
        }