예제 #1
0
        public async Task <List <TransactionResponseViewModel> > GetTransactionsBetween(ReportAuthRequestViewModel reportRequestViewModel)
        {
            var url = $"{_configuration["TransactionAPIUrl"]}/api/Transaction/AllInBetween";

            reportRequestViewModel.InternalName = _routerService.GetInternalName(reportRequestViewModel.UserName, reportRequestViewModel.Password);

            try
            {
                var responseString = await HTTPRequestSender.PostAsync(url, reportRequestViewModel);

                var responseUser = JsonConvert.DeserializeObject <List <TransactionResponseViewModel> >(responseString);

                return(responseUser);
            }
            catch (Exception e)
            {
                var errorResponse = JsonConvert.DeserializeObject <ErrorResponseViewModel>(e.Message);

                if (errorResponse.Id == (int)ErrorResponseIds.UserInvalid)
                {
                    throw new UserNotFoundException();
                }

                throw;
            }
        }
예제 #2
0
        public async Task <bool> AddInvoice(InvoiceAuthRequestViewModel invoice)
        {
            try
            {
                var url = _routerService.GetRedirectUrl(invoice.Username, invoice.Password);

                if (string.IsNullOrEmpty(url))
                {
                    throw new InvalidCredentialException();
                }

                url += "/api/invoice";

                var responseString = await HTTPRequestSender.PostAsync(url, invoice);

                var responseUser = JsonConvert.DeserializeObject <bool>(responseString);

                return(responseUser);
            }
            catch (Exception e)
            {
                var errorResponse = JsonConvert.DeserializeObject <ErrorResponseViewModel>(e.Message);

                if (errorResponse.Id == (int)ErrorResponseIds.InvoiceAlreadyExist)
                {
                    throw new InvoiceAlreadyExistException();
                }

                throw;
            }
        }
예제 #3
0
        public async Task <bool> UserExists(UserRequestViewModel user)
        {
            var url = $"{_configuration["UserServiceAPIUrl"]}/api/User/UserExist";

            try
            {
                var responseString = await HTTPRequestSender.PostAsync(url, user);

                return(false);
            }
            catch (Exception e)
            {
                var errorResponse = JsonConvert.DeserializeObject <ErrorResponseViewModel>(e.Message);

                return(errorResponse.Id == (int)ErrorResponseIds.UserAlreadyExists || true);
            }
        }
예제 #4
0
        public async Task <UserResponseViewModel> GetUserByCNP(string CNP)
        {
            var url = $"{_configuration["UserServiceAPIUrl"]}/api/User/GetUserByCNP/{CNP}";

            try
            {
                var responseString = await HTTPRequestSender.GetAsync(url);

                return(JsonConvert.DeserializeObject <UserResponseViewModel>(responseString));
            }
            catch (Exception e)
            {
                var errorResponse = JsonConvert.DeserializeObject <ErrorResponseViewModel>(e.Message);

                if (errorResponse.Id == (int)ErrorResponseIds.UserInvalid)
                {
                    throw new UserNotFoundException();
                }
                throw new Exception("Unknown Exception");
            }
        }
예제 #5
0
        public async Task <TransactionResponseViewModel> GetTransactionById(string id)
        {
            var url = $"{_configuration["TransactionAPIUrl"]}/api/Transaction/{id}";

            try
            {
                var responseString = await HTTPRequestSender.GetAsync(url);

                return(JsonConvert.DeserializeObject <TransactionResponseViewModel>(responseString));
            }
            catch (Exception e)
            {
                var errorResponse = JsonConvert.DeserializeObject <ErrorResponseViewModel>(e.Message);

                if (errorResponse.Id == (int)ErrorResponseIds.InvalidTransaction)
                {
                    throw new InvalidTransactionException();
                }
                throw new Exception("Unknown Exception");
            }
        }
예제 #6
0
        public async Task <List <InvoiceResponseViewModel> > GetAllEONInvoice(string CNP)
        {
            var url = $"{_configuration["EONGazAPIUrl"]}/api/invoice/UserInvoices/{CNP}";

            try
            {
                var responseString = await HTTPRequestSender.GetAsync(url);

                return(JsonConvert.DeserializeObject <List <InvoiceResponseViewModel> >(responseString));
            }
            catch (Exception e)
            {
                var errorResponse = JsonConvert.DeserializeObject <ErrorResponseViewModel>(e.Message);

                if (errorResponse.Id == (int)ErrorResponseIds.InvoiceNotExist)
                {
                    throw new InvoiceNotExistException();
                }
                throw new Exception("Unknown Exception");
            }
        }
예제 #7
0
        public async Task <UserResponseViewModel> RegisterUser(UserRequestViewModel user)
        {
            var url = $"{_configuration["UserServiceAPIUrl"]}/api/User/Register";

            try
            {
                var responseString = await HTTPRequestSender.PostAsync(url, user);

                var responseUser = JsonConvert.DeserializeObject <UserResponseViewModel>(responseString);

                return(responseUser);
            }
            catch (Exception e)
            {
                var errorResponse = JsonConvert.DeserializeObject <ErrorResponseViewModel>(e.Message);

                if (errorResponse.Id == (int)ErrorResponseIds.UserAlreadyExists)
                {
                    throw new UserAlreadyExistsException();
                }

                throw;
            }
        }
예제 #8
0
        public async Task <bool> AddTransaction(TransactionRequestViewModel transactionRequestViewModel)
        {
            var url = $"{_configuration["TransactionAPIUrl"]}/api/Transaction";

            try
            {
                var responseString = await HTTPRequestSender.PostAsync(url, transactionRequestViewModel);

                var responseUser = JsonConvert.DeserializeObject <bool>(responseString);

                return(responseUser);
            }
            catch (Exception e)
            {
                var errorResponse = JsonConvert.DeserializeObject <ErrorResponseViewModel>(e.Message);

                if (errorResponse.Id == (int)ErrorResponseIds.UserInvalid)
                {
                    throw new UserNotFoundException();
                }

                throw;
            }
        }