Add project files.
This commit is contained in:
38
ConstructorAppUI/Controllers/ContactUsController.cs
Normal file
38
ConstructorAppUI/Controllers/ContactUsController.cs
Normal file
@@ -0,0 +1,38 @@
|
||||
using ConstructorAppUI.Dtos.ContactUsDtos;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using Newtonsoft.Json;
|
||||
|
||||
namespace ConstructorAppUI.Controllers
|
||||
{
|
||||
public class ContactUsController : Controller
|
||||
{
|
||||
private readonly IHttpClientFactory _httpClientFactory;
|
||||
private readonly string _apiBaseUrl;
|
||||
|
||||
public ContactUsController(IHttpClientFactory httpClientFactory, IConfiguration configuration)
|
||||
{
|
||||
_httpClientFactory = httpClientFactory;
|
||||
_apiBaseUrl = configuration["ApiSettings:BaseUrl"];
|
||||
}
|
||||
|
||||
public async Task<IActionResult> Index()
|
||||
{
|
||||
var client = _httpClientFactory.CreateClient();
|
||||
var responseMessage = await client.GetAsync($"{_apiBaseUrl}/api/ContactUs");
|
||||
if (responseMessage.IsSuccessStatusCode)
|
||||
{
|
||||
var jsonData = await responseMessage.Content.ReadAsStringAsync();
|
||||
var values = JsonConvert.DeserializeObject<List<ResultContactUsDto>>(jsonData);
|
||||
return View(values);
|
||||
}
|
||||
return View();
|
||||
}
|
||||
|
||||
public async Task<IActionResult> MarkAsRead(int id)
|
||||
{
|
||||
var client = _httpClientFactory.CreateClient();
|
||||
await client.GetAsync($"{_apiBaseUrl}/api/ContactUs/MarkAsRead/{id}");
|
||||
return RedirectToAction("Index");
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user