Answers for "BaseAdress generic in c# MVC"

C#
0

BaseAdress generic in c# MVC

public async Task<ActionResult> GetStates()
                {

                    httpClient = HttpContext.Items["httpclient"] as HttpClient;
                    HttpResponseMessage response = await httpClient.GetAsync(httpClient.BaseAddress + "api/Admin/GetStates");
                    if (response.IsSuccessStatusCode)
                    {
                        string stateInfo = response.Content.ReadAsStringAsync().Result;
                        if (!string.IsNullOrEmpty(stateInfo))
                        {
                            return new ContentResult { Content = stateInfo, ContentType = "application/json" };
                        }
                    }

                    return new JsonResult();
                }
                public async Task<ActionResult> ClientsInfo()
                {

                    httpClient = HttpContext.Items["httpclient"] as HttpClient;
                    HttpResponseMessage response = await httpClient.GetAsync(httpClient.BaseAddress + "api/Admin/GetClients");
                    if (response.IsSuccessStatusCode)
                    {
                        string roleInfo = response.Content.ReadAsStringAsync().Result;
                        if (!string.IsNullOrEmpty(roleInfo))
                        {
                            return new ContentResult { Content = roleInfo, ContentType = "application/json" };
                        }
                    }

                    return new JsonResult();
                }

                public async Task<ActionResult> GetRoles()
                {
                    httpClient = HttpContext.Items["httpclient"] as HttpClient;
                    HttpResponseMessage response = await httpClient.GetAsync(httpClient.BaseAddress + "api/Roles");
                    if (response.IsSuccessStatusCode)
                    {
                        string roleInfo = response.Content.ReadAsStringAsync().Result;
                        if (!string.IsNullOrEmpty(roleInfo))
                        {
                            return new ContentResult { Content = roleInfo, ContentType = "application/json" };
                        }
                    }

                    return new JsonResult();
                }
...........
//for post and delete actions similarly
Posted by: Guest on September-18-2021

C# Answers by Framework

Browse Popular Code Answers by Language