示例#1
0
        public PaginatedPagesDTO PaginatedSearchUserList(JQueryBootGridRequestDTO userListSearchRequestDto)
        {
            UserListSearchResponseDTO userListSearchResponseDto = new UserListSearchResponseDTO();
            PaginatedPagesDTO         paginatedPagesDto         = new PaginatedPagesDTO();

            try
            {
                userListSearchResponseDto.simpleReturnDTO = new SimpleReturnDTO();
                paginatedPagesDto.SimpleReturnDTO         = new SimpleReturnDTO();
                string name  = String.IsNullOrWhiteSpace(userListSearchRequestDto.Name) ? "" : userListSearchRequestDto.Name;
                string email = String.IsNullOrWhiteSpace(userListSearchRequestDto.Email) ? "" : userListSearchRequestDto.Email;
                string nif   = String.IsNullOrWhiteSpace(userListSearchRequestDto.NIF) ? "" : userListSearchRequestDto.NIF;

                var users = _repository.GetAll <PayLendUser>(x =>
                                                             (((x.Name == null || x.Name.Trim() == string.Empty) || x.Name.Contains(name))) &&
                                                             ((x.NIF == null || x.NIF.Trim() == string.Empty) || x.NIF.Contains(nif)) &&
                                                             x.Email != null &&
                                                             ((x.Email == null || x.Email.Trim() == string.Empty) || x.Email.Contains(email)) &&
                                                             (userListSearchRequestDto.CountryId == 0 || x.CountryId == userListSearchRequestDto.CountryId) &&
                                                             (userListSearchRequestDto.CreatedDate == DateTime.MinValue || (userListSearchRequestDto.CreatedDate.Day == x.CreatedDate.Day && userListSearchRequestDto.CreatedDate.Month == x.CreatedDate.Month && userListSearchRequestDto.CreatedDate.Year == x.CreatedDate.Year))
                                                             ).ToList();

                users = users.OrderByDescending(x => x.CreatedDate).ToList();

                List <PayLend.Core.Entities.Country> countryList = _repository.GetAll <PayLend.Core.Entities.Country>().ToList();

                if (userListSearchRequestDto.UserType == DiscriminatorEnum.Borrower)
                {
                    users = users.Where(x => x.GetType().BaseType.Name == "Borrower").ToList();
                }
                else if (userListSearchRequestDto.UserType == DiscriminatorEnum.Lender)
                {
                    users = users.Where(x => x.GetType().BaseType.Name == "Lender").ToList();
                }
                else if (userListSearchRequestDto.UserType == DiscriminatorEnum.Admin)
                {
                    users = users.Where(x => x.GetType().BaseType.Name == "Admin").ToList();
                }

                paginatedPagesDto.total = users.Count();

                paginatedPagesDto.current  = userListSearchRequestDto.current;
                paginatedPagesDto.rowCount = userListSearchRequestDto.rowCount;

                paginatedPagesDto.rows = _PaylendUserObjectArray(paginatedPagesDto, users, userListSearchRequestDto.current, userListSearchRequestDto.rowCount);

                return(paginatedPagesDto);
            }
            catch (Exception ex)
            {
                paginatedPagesDto.SimpleReturnDTO.ErrorMessage = ex.Message;
                paginatedPagesDto.SimpleReturnDTO.ErrorType    = ErrorType.Conclusion;
                paginatedPagesDto.SimpleReturnDTO.ErrorKey     = "SearchBox";

                var erroTratado = TreatmentError.SerializedErrorDetail(ex);
                erroTratado.User = ClassName;
                _logManager.SaveError(erroTratado);
                return(paginatedPagesDto);
            }
        }
示例#2
0
 private object[] _PaylendUserObjectArray(PaginatedPagesDTO paginatedPagesDto, List <PayLendUser> users, int page, int rows)
 {
     if (paginatedPagesDto.rowCount > 0)
     {
         return(users.OrderBy(x => x.Id).Skip(((page - 1) * (paginatedPagesDto.rowCount))).Take(rows).ToList().Select(x => new
         {
             id = x.Id,
             x.Email,
             x.Name,
             x.NIF,
             Country = x.CountryId,
             CreatedDate = x.CreatedDate.ToShortDateString(),
             x.Address,
             x.City,
             DiscriminatorType = x.GetType().BaseType.Name,
             securityId = x.SecurityId
         }).ToArray());
     }
     else
     {
         return(users.OrderBy(x => x.Id).ToList().Select(x => new
         {
             id = x.Id,
             x.Email,
             x.Name,
             x.NIF,
             Country = x.CountryId,
             CreatedDate = x.CreatedDate.ToShortDateString(),
             x.Address,
             x.City,
             DiscriminatorType = x.GetType().BaseType.Name
         }).ToArray());
     }
 }