Beispiel #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);
            }
        }
Beispiel #2
0
        public UserDetailResponseDTO EditSave(EditUserRequestDTO model, HttpPostedFileBase filedata)
        {
            UserDetailResponseDTO result = new UserDetailResponseDTO();

            result.simpleReturnDTO = new SimpleReturnDTO();
            try
            {
                var users  = _repository.GetAll <PayLendUser>();
                var user   = users.FirstOrDefault(x => x.Id == model.Id);
                var bouser = users.FirstOrDefault(x => x.Email == model.BoUserEmail);
                var bank   = _bankManager.GetAll().FirstOrDefault(x => x.SwiftCode.Equals(model.SWIFT));

                if (user == null)
                {
                    result.simpleReturnDTO.ErrorKey     = "User";
                    result.simpleReturnDTO.ErrorMessage = "User Not Registered";
                    result.simpleReturnDTO.ErrorType    = ErrorType.Conclusion;
                    return(result);
                }

                user.Name                    = model.Name;
                user.MobilePhone             = model.MobilePhone;
                user.Email                   = model.Email;
                user.NIF                     = model.NIF;
                user.Address                 = model.Address;
                user.City                    = model.City;
                user.PostalCode              = model.PostalCode;
                user.MobilePhone             = model.MobilePhone;
                user.BirthdayDate            = model.BirthdayDate;
                user.PhonePrefixID           = model.PhonePrefixID;
                user.DocumentValidDate       = model.DocumentValidDate == DateTime.MinValue ? null : model.DocumentValidDate;
                user.Nationality             = model.Nationality;
                user.IdentificationDocNumber = model.IdentificationDocNumber;

                var userBank = _repository.GetAll <PayLend.Core.Entities.BankUser>(x => x.UserId == user.Id).ToList();
                if (userBank.Any())
                {
                    user.Banks.FirstOrDefault().IBAN   = model.IBAN;
                    user.Banks.FirstOrDefault().NIB    = model.IBAN;
                    user.Banks.FirstOrDefault().BankId = bank.Id;
                }
                else
                {
                    var bankUser = new PayLend.Core.Entities.BankUser
                    {
                        UserId  = user.Id,
                        BankId  = bank.Id,
                        IBAN    = model.IBAN,
                        NIB     = model.IBAN,
                        Default = true,
                    };
                    _bankUserManager.Create(bankUser);
                }

                if (user.BorrowerCompanyData != null)
                {
                    user.BorrowerCompanyData = model.borrowerCompanyData;
                }

                //Caso exista alteração de saldo
                if (filedata != null)
                {
                    var    url = "";
                    var    containerUrlCpcv = _payLendConfigManager.GetConfigValue("BlobContainerTopUpReceipt");
                    string extension        = Path.GetExtension(filedata.FileName);
                    if (filedata.FileName != null)
                    {
                        String filenameCpcv = Guid.NewGuid().ToString() + "_" + filedata.FileName.Replace(" ", "");
                        _azureStorageManager.uploadFile(filedata.InputStream, filenameCpcv, filedata.ContentLength, FileType.PaymentReceipt);
                        url = containerUrlCpcv + filenameCpcv;
                    }

                    //Criar o pedido de carregamento de saldo que tem que ter aprovação
                    var topUp = new PayLend.Core.Entities.BackOfficeTopUp
                    {
                        UserId            = user.Id,
                        Ammount           = model.TopUpValue,
                        BoUserIdRequest   = bouser.Id,
                        PaymentReceiptUrl = url,
                        Status            = TopUpStatusEnum.Pendente,
                    };

                    _backOfficeTopUpManager.Create(topUp);
                    //Enviar email a informar que foi feito um pedido de aumento de saldo
                    _emailLogManager.SendRequestToTopUp(bouser.Id, user);
                }

                _repository.Update(user);
                // _repository.SaveChanges(true);

                return(result);
            }
            catch (Exception ex)
            {
                result.simpleReturnDTO.ErrorKey     = "Error";
                result.simpleReturnDTO.ErrorMessage = ex.Message;
                result.simpleReturnDTO.ErrorType    = ErrorType.Form;

                var erroTratado = TreatmentError.SerializedErrorDetail(ex);
                erroTratado.User = ClassName;
                _logManager.SaveError(erroTratado);
                return(result);
            }
        }