вход + отображение животных

This commit is contained in:
frog24 2024-05-28 15:18:47 +04:00
parent 513f56153b
commit d77cfebc06
4 changed files with 147 additions and 9 deletions

View File

@ -27,7 +27,22 @@ namespace ClientApp.Controllers
{
return View();
}
public IActionResult Enter()
[HttpPost]
public void Enter(string login, string password)
{
if (string.IsNullOrEmpty(login) ||
string.IsNullOrEmpty(password))
{
throw new Exception("Введите логин и пароль");
}
APIClient.Client = APIClient.GetRequest<ClientViewModel>($"api/client/login?email={login}&password={password}");
if (APIClient.Client == null)
{
throw new Exception("Неверный логин/пароль");
}
Response.Redirect("Index");
}
public IActionResult Enter()
{
return View();
}
@ -37,8 +52,12 @@ namespace ClientApp.Controllers
}
public IActionResult IndexAnimal()
{
return View(new List<AnimalViewModel>());
}
if (APIClient.Client == null)
{
return Redirect("~/Home/Enter");
}
return View(APIClient.GetRequest<List<AnimalViewModel>>($"api/animal/getanimals?clientid={APIClient.Client.Id}"));
}
public IActionResult CreateAnimal()
{
return View();
@ -57,7 +76,7 @@ namespace ClientApp.Controllers
Price = 228,
DcotorFIO = "name example",
DoctorId = 1,
ServiceMedicines = new Dictionary<int, (IMedicineModel, int)>()
ServiceMedicines = new Dictionary<int, IMedicineModel>()
});
services.Add(new ServiceViewModel
{
@ -66,7 +85,7 @@ namespace ClientApp.Controllers
Price = 2282,
DcotorFIO = "name example 2",
DoctorId = 2,
ServiceMedicines = new Dictionary<int, (IMedicineModel, int)>()
ServiceMedicines = new Dictionary<int, IMedicineModel>()
});
return View(services);
}
@ -84,7 +103,7 @@ namespace ClientApp.Controllers
Price = 228,
DoctorFIO = "Name example",
DoctorId = 1,
DrugMedicines = new Dictionary<int, (IMedicineModel, int)>()
DrugMedicines = new Dictionary<int, IMedicineModel>()
});
return View(drugs);
}

View File

@ -5,5 +5,6 @@
"Microsoft.AspNetCore": "Warning"
}
},
"AllowedHosts": "*"
"AllowedHosts": "*",
"IPAddress": "http://localhost:5244"
}

View File

@ -18,11 +18,11 @@ namespace VetclinicRestApi.Controllers
_animal = animal;
}
[HttpGet]
public List<AnimalViewModel> GetAnimals(int clentId)
public List<AnimalViewModel> GetAnimals(int clientId)
{
try
{
return _animal.ReadList(new AnimalSearchModel { ClientId = clentId });
return _animal.ReadList(new AnimalSearchModel { ClientId = clientId });
}
catch (Exception ex)
{

View File

@ -0,0 +1,118 @@
using Microsoft.AspNetCore.Mvc;
using VetclinicContracts.BindingModels;
using VetclinicContracts.BusinessLogicsContracts;
using VetclinicContracts.SearchModels;
using VetclinicContracts.ViewModels;
using VetclinicDatabaseImplement.Models;
using VetclinicDataModels.Enums;
namespace VetclinicRestApi.Controllers
{
[Route("api/[controller]/[action]")]
[ApiController]
public class DoctorVisitController : Controller
{
private readonly ILogger _logger;
private readonly IDoctorVisitLogic _doctorVisit;
public DoctorVisitController(ILogger<DoctorVisitController> logger, IDoctorVisitLogic doctorVisit)
{
_logger = logger;
_doctorVisit = doctorVisit;
}
[HttpGet]
public Tuple<DoctorVisitViewModel>? GetVisit(int visitId)
{
try
{
var elem = _doctorVisit.ReadElement(new DoctorVisitSearchModel { Id = visitId });
if (elem == null)
{
return null;
}
var res = Tuple.Create(elem);
return res;
}
catch (Exception ex)
{
_logger.LogError(ex, "Ошибка получения визита по id={Id}", visitId);
throw;
}
}
[HttpGet]
public List<DoctorVisitViewModel>? GetVisits(int? clientId = null)
{
try
{
return _doctorVisit.ReadList(new DoctorVisitSearchModel { ClientId = clientId });
}
catch (Exception ex)
{
_logger.LogError(ex, "Ошибка получения списка визитов");
throw;
}
}
[HttpGet]
public List<DoctorVisitViewModel> GetAllVisits()
{
try
{
return _doctorVisit.ReadList(null);
}
catch (Exception ex)
{
_logger.LogError(ex, "Ошибка получения списка визитов");
throw;
}
}
[HttpPost]
public bool CreateVisit(DoctorVisitBindingModel model)
{
try
{
return _doctorVisit.CreateDoctorVisit(model);
}
catch (Exception ex)
{
_logger.LogError(ex, "Не удалось создать визит");
throw;
}
}
[HttpPost]
public bool UpdateVisit(DoctorVisitBindingModel model)
{
try
{
if (model.Status == DoctorVisitStatus.Забронировано)
{
return _doctorVisit.BeginDoctorVisit(model);
}
if (model.Status == DoctorVisitStatus.Выполняется)
{
return _doctorVisit.FinishDoctorVisit(model);
}
throw new InvalidOperationException();
}
catch (Exception ex)
{
_logger.LogError(ex, "Не удалось обновить лекарства");
throw;
}
}
//[HttpPost]
//public bool DeleteVisit(DoctorVisitBindingModel model)
//{
// try
// {
// return _doctorVisit.FinishDoctorVisit(model);
// }
// catch (Exception ex)
// {
// _logger.LogError(ex, "Ошибка удаления лекарства");
// throw;
// }
//}
}
}