Projects (GanjooRazor -> DiwanRazor, GanjoorService.sln -> DiwanService.sln), files, folders, classes, namespaces, settings, API routes (/api/diwan) and DB tables (Diwan*). External addresses (ganjoor.net, github.com/ganjoor) unchanged. Migrations renamed consistently (no pending model changes); requires a fresh database. Upstream RUNNING_LOCALLY/SEMANTIC_SEARCH docs archived unmodified under docs/. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
128 lines
5.1 KiB
C#
128 lines
5.1 KiB
C#
using DiwanRazor.Utils;
|
|
using Microsoft.AspNetCore.Mvc;
|
|
using Microsoft.AspNetCore.Mvc.RazorPages;
|
|
using Newtonsoft.Json;
|
|
using RMuseum.Models.Diwan;
|
|
using System.Net.Http;
|
|
using System.Text;
|
|
using System.Threading.Tasks;
|
|
namespace DiwanRazor.Areas.Admin.Pages
|
|
{
|
|
public class LocationsModel : PageModel
|
|
{
|
|
public string LastMessage { get; set; }
|
|
public DiwanGeoLocation[] Locations { get; set; }
|
|
|
|
[BindProperty]
|
|
public DiwanGeoLocation Location { get; set; }
|
|
|
|
private async Task ReadLocationsAsync()
|
|
{
|
|
LastMessage = "";
|
|
|
|
using (HttpClient secureClient = new HttpClient(new DiwanReloginHandler(Request, Response)))
|
|
{
|
|
if (await DiwanSessionChecker.PrepareClient(secureClient, Request, Response))
|
|
{
|
|
var response = await secureClient.GetAsync($"{APIRoot.Url}/api/locations");
|
|
if (!response.IsSuccessStatusCode)
|
|
{
|
|
LastMessage = JsonConvert.DeserializeObject<string>(await response.Content.ReadAsStringAsync());
|
|
return;
|
|
}
|
|
Locations = JsonConvert.DeserializeObject<DiwanGeoLocation[]>(await response.Content.ReadAsStringAsync());
|
|
|
|
}
|
|
else
|
|
{
|
|
LastMessage = "لطفاً از دیوان خارج و مجددا به آن وارد شوید.";
|
|
}
|
|
|
|
}
|
|
}
|
|
public async Task<IActionResult> OnGetAsync()
|
|
{
|
|
if (string.IsNullOrEmpty(Request.Cookies["Token"]))
|
|
return Redirect("/");
|
|
|
|
await ReadLocationsAsync();
|
|
|
|
return Page();
|
|
}
|
|
|
|
public async Task<IActionResult> OnPostAsync(DiwanGeoLocation Location)
|
|
{
|
|
LastMessage = "";
|
|
using (HttpClient secureClient = new HttpClient(new DiwanReloginHandler(Request, Response)))
|
|
{
|
|
if (await DiwanSessionChecker.PrepareClient(secureClient, Request, Response))
|
|
{
|
|
HttpResponseMessage response = await secureClient.PostAsync($"{APIRoot.Url}/api/locations", new StringContent(JsonConvert.SerializeObject(Location), Encoding.UTF8, "application/json"));
|
|
if (!response.IsSuccessStatusCode)
|
|
{
|
|
LastMessage = JsonConvert.DeserializeObject<string>(await response.Content.ReadAsStringAsync());
|
|
}
|
|
else
|
|
{
|
|
await ReadLocationsAsync();
|
|
}
|
|
}
|
|
else
|
|
{
|
|
LastMessage = "لطفاً از دیوان خارج و مجددا به آن وارد شوید.";
|
|
}
|
|
}
|
|
return Page();
|
|
}
|
|
|
|
public async Task<IActionResult> OnDeleteAsync(int id)
|
|
{
|
|
using (HttpClient secureClient = new HttpClient(new DiwanReloginHandler(Request, Response)))
|
|
{
|
|
if (await DiwanSessionChecker.PrepareClient(secureClient, Request, Response))
|
|
{
|
|
var response = await secureClient.DeleteAsync($"{APIRoot.Url}/api/locations/{id}");
|
|
|
|
if (!response.IsSuccessStatusCode)
|
|
{
|
|
return new BadRequestObjectResult(JsonConvert.DeserializeObject<string>(await response.Content.ReadAsStringAsync()));
|
|
}
|
|
}
|
|
else
|
|
{
|
|
return new BadRequestObjectResult("لطفاً از دیوان خارج و مجددا به آن وارد شوید.");
|
|
}
|
|
}
|
|
return new JsonResult(true);
|
|
}
|
|
|
|
public async Task<IActionResult> OnPutEditAsync(int id, string name, double latitude, double longitude)
|
|
{
|
|
using (HttpClient secureClient = new HttpClient(new DiwanReloginHandler(Request, Response)))
|
|
{
|
|
if (await DiwanSessionChecker.PrepareClient(secureClient, Request, Response))
|
|
{
|
|
DiwanGeoLocation model = new DiwanGeoLocation()
|
|
{
|
|
Id = id,
|
|
Name = name,
|
|
Latitude = latitude,
|
|
Longitude = longitude
|
|
};
|
|
HttpResponseMessage response = await secureClient.PutAsync($"{APIRoot.Url}/api/locations", new StringContent(JsonConvert.SerializeObject(model), Encoding.UTF8, "application/json"));
|
|
if (!response.IsSuccessStatusCode)
|
|
{
|
|
return new BadRequestObjectResult(JsonConvert.DeserializeObject<string>(await response.Content.ReadAsStringAsync()));
|
|
}
|
|
}
|
|
else
|
|
{
|
|
return new BadRequestObjectResult("لطفاً از دیوان خارج و مجددا به آن وارد شوید.");
|
|
}
|
|
|
|
}
|
|
return new JsonResult(true);
|
|
}
|
|
}
|
|
}
|