コード例 #1
0
        private async Task <Result <int> > Save(Expense expense)
        {
            string resourceUri = _config.GetSection("api:expense").GetSection("postExpenses").Value;
            string url         = $"{ _config.GetSection("api:expense").GetSection("baseUrl").Value}{resourceUri}";

            using (var client = new HttpClient())
                using (var request = new HttpRequestMessage(HttpMethod.Post, url))
                    using (var httpContent = new UtilHttpContent().CreateHttpContent(expense))
                    {
                        request.Content = httpContent;
                        using (var response = await client
                                              .SendAsync(request, HttpCompletionOption.ResponseHeadersRead))
                        {
                            if (response.StatusCode == System.Net.HttpStatusCode.OK || response.StatusCode == System.Net.HttpStatusCode.Created)
                            {
                                Result <int> result = await response.Content.ReadAsAsync <Result <int> >();

                                return(result);
                            }
                            else
                            {
                                var content = await response.Content.ReadAsStringAsync();

                                Result <int> result = new Result <int>();
                                result.Error = content;
                                return(result);
                            }
                        }
                    }
        }
コード例 #2
0
        private async void SendEmail(User user, int expenseId)
        {
            // Fire and forget
            try
            {
                string           resourceUri  = _config.GetSection("api:expense").GetSection("postSendEmail").Value;
                string           url          = $"{ _config.GetSection("api:expense").GetSection("baseUrl").Value}{resourceUri}";
                RequestSendEmail reqSendEmail = new RequestSendEmail()
                {
                    user = user, expenseId = expenseId
                };

                using (var client = new HttpClient())
                    using (var request = new HttpRequestMessage(HttpMethod.Post, url))
                        using (var httpContent = new UtilHttpContent().CreateHttpContent(reqSendEmail))
                        {
                            request.Content = httpContent;
                            using (var response = await client
                                                  .SendAsync(request, HttpCompletionOption.ResponseHeadersRead))
                            {
                                if (response.StatusCode == System.Net.HttpStatusCode.OK)
                                {
                                    // var content = await response.Content.ReadAsStringAsync();
                                    // return StatusCode((int)response.StatusCode, content);
                                    // LOG Success
                                }
                            }
                        }
            }
            catch (Exception ex)
            {
                string msg = ex.Message;
                // LOG ERROR
            }
        }
コード例 #3
0
        private async void UpdateTransactions(int expenseId, Expense expense)
        {
            // Fire and forget
            // Create expense items to reflect payload to be sent..
            List <TransactionStatus> list = new List <TransactionStatus>();

            foreach (ExpenseItem item in expense.ExpenseItems)
            {
                if (item.TransType != "OOP")
                {
                    list.Add(new TransactionStatus()
                    {
                        Id = item.Id, Status = "Processed"
                    });
                }
            }

            try
            {
                string resourceUri = _config.GetSection("api:transaction").GetSection("postUpdateTransactionStatus").Value;
                string url         = $"{ _config.GetSection("api:transaction").GetSection("baseUrl").Value}{resourceUri}";
                using (var client = new HttpClient())
                    using (var request = new HttpRequestMessage(HttpMethod.Post, url))
                        using (var httpContent = new UtilHttpContent().CreateHttpContent(list.ToArray()))
                        {
                            request.Content = httpContent;
                            using (var response = await client
                                                  .SendAsync(request, HttpCompletionOption.ResponseHeadersRead))
                            {
                                if (response.StatusCode == System.Net.HttpStatusCode.OK)
                                {
                                    // var content = await response.Content.ReadAsStringAsync();
                                    // return StatusCode((int)response.StatusCode, content);
                                    // LOG Success
                                }
                            }
                        }
            }
            catch (Exception ex)
            {
                string msg = ex.Message;
                // LOG ERROR
            }
        }
コード例 #4
0
        public async Task <ActionResult <Result <string> > > Post([FromBody] AutoloadDto autoloadDto)
        {
            try
            {
                string resourceUri = _config.GetSection("api:transaction").GetSection("postAutoloadTransactions").Value;
                string url         = $"{ _config.GetSection("api:transaction").GetSection("baseUrl").Value}{resourceUri}";
                using (var client = new HttpClient())
                    using (var request = new HttpRequestMessage(HttpMethod.Post, url))
                        using (var httpContent = new UtilHttpContent().CreateHttpContent(autoloadDto))
                        {
                            request.Content = httpContent;
                            using (var response = await client
                                                  .SendAsync(request, HttpCompletionOption.ResponseHeadersRead))
                            {
                                if (response.StatusCode == System.Net.HttpStatusCode.OK || response.StatusCode == System.Net.HttpStatusCode.Created)
                                {
                                    Result <string> result = await response.Content.ReadAsAsync <Result <string> >();

                                    return(result);
                                }
                                else
                                {
                                    var content = await response.Content.ReadAsStringAsync();

                                    Result <string> result = new Result <string>();
                                    result.Error = content;
                                    return(result);
                                }
                            }
                        }
            }
            catch (Exception ex)
            {
                Result <string> response = new Result <string>();
                response.Error = ex.Message;
                return(response);
            }
        }
コード例 #5
0
        public async Task <ActionResult <Result> > Post(UserCredential userCredential)
        {
            try
            {
                string resourceUri = _config.GetSection("api:userProfile").GetSection("postAuthentication").Value;
                string url         = $"{ _config.GetSection("api:userProfile").GetSection("baseUrl").Value}{resourceUri}";
                using (var client = new HttpClient())
                    using (var request = new HttpRequestMessage(HttpMethod.Post, url))
                        using (var httpContent = new UtilHttpContent().CreateHttpContent(userCredential))
                        {
                            request.Content = httpContent;
                            using (var response = await client
                                                  .SendAsync(request, HttpCompletionOption.ResponseHeadersRead))
                            {
                                if (response.StatusCode == System.Net.HttpStatusCode.OK)
                                {
                                    Result <bool> body = await response.Content.ReadAsAsync <Result <bool> >();

                                    return(body);
                                }
                                else
                                {
                                    var content = await response.Content.ReadAsStringAsync();

                                    Result <bool> result = new Result <bool>();
                                    result.Entity = false;
                                    result.Error  = content;
                                    return(result);
                                }
                            }
                        }
            }
            catch (Exception ex)
            {
                throw new Exception("Error posting UserCredentials. " + ex.Message);
            }
        }
コード例 #6
0
        public async Task <ActionResult <Result <string> > > Post(AddUserDto user)
        {
            try
            {
                string resourseUri = string.Format(_config.GetSection("api:userProfile").GetSection("postUser").Value);
                string url         = $"{ _config.GetSection("api:userProfile").GetSection("baseUrl").Value}{resourseUri}";
                using (var client = new HttpClient())
                    using (var request = new HttpRequestMessage(HttpMethod.Post, url))
                        using (var httpContent = new UtilHttpContent().CreateHttpContent(user))
                        {
                            request.Content = httpContent;
                            using (var response = await client
                                                  .SendAsync(request, HttpCompletionOption.ResponseHeadersRead))
                            {
                                if (response.StatusCode == System.Net.HttpStatusCode.OK ||
                                    response.StatusCode == System.Net.HttpStatusCode.Created)
                                {
                                    Result <string> result = await response.Content.ReadAsAsync <Result <string> >();

                                    return(result);
                                }
                                else
                                {
                                    var content = await response.Content.ReadAsStringAsync();

                                    Result <string> result = new Result <string>();
                                    result.Error = content;
                                    return(result);
                                }
                            }
                        }
            }
            catch (Exception ex)
            {
                throw new Exception("Error fetching user " + ex.Message);
            }
        }
コード例 #7
0
        // public async void Post([FromBody] RequestSendEmail requestSendEmail)
        public async Task <ActionResult <string> > Post([FromBody] RequestSendEmail requestSendEmail)
        {
            // Fire and forget

            /** iwr -Method POST -Uri https://ms-expense-react-func-app.azurewebsites.net/api/onExpSubmittedAddToQueToCreatePdfAndSendMail?code=<<...get..from...azure...fn..>>
             *      -Headers @{ "content-type"="application/json" }
             *      -Body `{user: {userId: 'user1'}, expenseId: 2}`
             */
            try
            {
                string url = _configuration.GetSection("Api").GetSection("SendGridEmail").Value;
                using (var client = new HttpClient())
                    using (var request = new HttpRequestMessage(HttpMethod.Post, url))
                        using (var httpContent = new UtilHttpContent().CreateHttpContent(requestSendEmail))
                        {
                            request.Content = httpContent;
                            using (var response = await client
                                                  .SendAsync(request, HttpCompletionOption.ResponseHeadersRead))
                            {
                                if (response.StatusCode == System.Net.HttpStatusCode.OK)
                                {
                                    // var content = await response.Content.ReadAsStringAsync();
                                    // return StatusCode((int)response.StatusCode, content);
                                    // LOG Success
                                }
                                return(response.Content.ToString());
                            }
                        }
            }
            catch (Exception ex)
            {
                // LOG ERROR
                string error = ex.Message.ToString();
                return(null);
            }
        }
コード例 #8
0
        public async void Post([FromBody] TransactionUpdateStatus[] transactionUpdateStatuses)
        {
            // Fire and forget

            /** iwr -Method POST -Uri https://ms-expense-react-func-app.azurewebsites.net/api/onExpSubmittedAddToQueToUpdTrans?code=<<...get..from...azure...fn..>>
             *      -Headers @{ "content-type"="application/json" }
             *      -Body '
             *         [{"id": "aa2612d0-626c-4fbc-bd2c-052837a9fa0e", "status": "Processed" },
             *          {"id": "c5204ebf-23fe-40e3-b582-4887cebdf796", "status": "Processed" }]'
             */
            try
            {
                string url = _configuration.GetSection("Api").GetSection("UpdateTransactionStatus").Value;
                using (var client = new HttpClient())
                    using (var request = new HttpRequestMessage(HttpMethod.Post, url))
                        using (var httpContent = new UtilHttpContent().CreateHttpContent(transactionUpdateStatuses))
                        {
                            request.Content = httpContent;
                            using (var response = await client
                                                  .SendAsync(request, HttpCompletionOption.ResponseHeadersRead))
                            {
                                if (response.StatusCode == System.Net.HttpStatusCode.OK)
                                {
                                    // var content = await response.Content.ReadAsStringAsync();
                                    // return StatusCode((int)response.StatusCode, content);
                                    // LOG Success
                                }
                            }
                        }
            }
            catch (Exception ex)
            {
                // LOG ERROR
                string error = ex.Message.ToString();
            }
        }