я не плачу это дощ

This commit is contained in:
Allllen4a 2024-05-30 03:02:48 +04:00
parent f44ebf5a64
commit 225eee8349
3 changed files with 31 additions and 29 deletions

View File

@ -17,7 +17,7 @@ namespace BeautySalonDatabaseImplement
{
if (optionsBuilder.IsConfigured == false)
{
optionsBuilder.UseSqlServer(@"Data Source=PRETTYNAME;Initial Catalog=BeautySalonDatabase;Integrated Security=True;MultipleActiveResultSets=True;;TrustServerCertificate=True");
optionsBuilder.UseSqlServer(@"Data Source=ALYONA\;Initial Catalog=BeautySalonDatabase;Integrated Security=True;MultipleActiveResultSets=True;;TrustServerCertificate=True");
}
base.OnConfiguring(optionsBuilder);
}

View File

@ -18,32 +18,32 @@ namespace WorkerWebApp
_worker.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));
}
public static T? GetRequest<T>(string requestUrl)
public static async Task<T?> GetRequest<T>(string requestUrl)
{
var response = await _worker.GetAsync(requestUrl);
var result = await response.Content.ReadAsStringAsync();
if (response.IsSuccessStatusCode)
{
var response = _worker.GetAsync(requestUrl);
var result = response.Result.Content.ReadAsStringAsync().Result;
if (response.Result.IsSuccessStatusCode)
{
return JsonConvert.DeserializeObject<T>(result);
}
else
{
throw new Exception(result);
}
return JsonConvert.DeserializeObject<T>(result);
}
public static void PostRequest<T>(string requestUrl, T model)
else
{
var json = JsonConvert.SerializeObject(model);
var data = new StringContent(json, Encoding.UTF8, "application/json");
var response = _worker.PostAsync(requestUrl, data);
var result = response.Result.Content.ReadAsStringAsync().Result;
if (!response.Result.IsSuccessStatusCode)
{
throw new Exception(result);
}
throw new Exception(result);
}
}
public static async Task PostRequest<T>(string requestUrl, T model)
{
var json = JsonConvert.SerializeObject(model);
var data = new StringContent(json, Encoding.UTF8, "application/json");
var response = await _worker.PostAsync(requestUrl, data);
var result = await response.Content.ReadAsStringAsync();
if (!response.IsSuccessStatusCode)
{
throw new Exception(result);
}
}
}
}

View File

@ -76,21 +76,23 @@ namespace WorkerWebApp.Controllers
return View();
}
[HttpPost]
public void Enter(string login, string password)
public async Task Enter(string login, string password)
{
if (string.IsNullOrEmpty(login) ||
string.IsNullOrEmpty(password))
if (string.IsNullOrEmpty(login) || string.IsNullOrEmpty(password))
{
throw new Exception("Введите логин и пароль");
}
APIWorker.Worker =
APIWorker.GetRequest<WorkerViewModel>($"api/worker/login?login={login}&password={password}");
APIWorker.Worker = await APIWorker.GetRequest<WorkerViewModel>($"api/worker/login?login={login}&password={password}");
if (APIWorker.Worker == null)
{
throw new Exception("Неверный логин/пароль");
}
Response.Redirect("Index");
}
[HttpGet]
public IActionResult Register()
{