сделал рестухи

This commit is contained in:
gg12 darfren 2024-04-26 21:03:08 +04:00
parent 4fc5af7e05
commit e29bd639a4
5 changed files with 204 additions and 7 deletions

View File

@ -4,6 +4,7 @@ using System.Diagnostics;
using VetClinicContracts.BindingModels;
using VetClinicContracts.ViewModels;
using VetClinicDataBaseImplement.Models;
using VetClinicDataModels.Models;
namespace PharmacistApp.Controllers
{
@ -175,7 +176,8 @@ View(APIPharmacist.GetRequest<List<MedicineViewModel>>($"api/medicine/getmedicin
}
[HttpPost]
public void UpdateMedicine(int medicine, string name, int price)
public void UpdateMedicine(int medicine, string name, int price,
Dictionary<int, IAnimalModel> medicineAnimals = null)
{
if (APIPharmacist.Pharmacist == null)
{
@ -190,7 +192,8 @@ View(APIPharmacist.GetRequest<List<MedicineViewModel>>($"api/medicine/getmedicin
Id = medicine,
MedicineName = name,
Price = price,
PharmacistId = APIPharmacist.Pharmacist.Id
PharmacistId = APIPharmacist.Pharmacist.Id,
MedicineAnimals = medicineAnimals
});
Response.Redirect("Index");
}
@ -224,5 +227,16 @@ View(APIPharmacist.GetRequest<List<MedicineViewModel>>($"api/medicine/getmedicin
}
return Tuple.Create(result.Item1, table);
}
[HttpGet]
public AnimalViewModel? GetAnimal(int animalId)
{
if (APIPharmacist.Pharmacist == null)
{
throw new Exception("Âû êàê ñþäà ïîïàëè? Ñþäà âõîä òîëüêî àâòîðèçîâàííûì");
}
var result = APIPharmacist.GetRequest<AnimalViewModel>($"api/animal/getanimal?animalid={animalId}");
return result;
}
}
}

View File

@ -13,6 +13,9 @@
<div class="col-8">
<select id="medicine" name="medicine" class="form-control" asp-items="@(new SelectList(@ViewBag.Medicines, "Id", "MedicineName"))"></select>
</div>
<div class="col-8">
<select id="animal" name="animal" class="form-control" asp-items="@(new SelectList(@ViewBag.Animals, "Id", "AnimalName"))"></select>
</div>
</div>
<div class="row">
<div class="col-4">Название:</div>

View File

@ -31,8 +31,8 @@ namespace VetClinicDataBaseImplement.Implements
return context.Services.Include(x => x.Pharmacist)
.Include(x => x.Medicines)
.ThenInclude(x => x.Medicine)
.Where(x => (string.IsNullOrEmpty(model.ServiceName) || x.ServiceName.Contains(model.ServiceName)
&& (!model.PharmacistId.HasValue || x.PharmacistId == model.PharmacistId)))
.Where(x => (string.IsNullOrEmpty(model.ServiceName) || x.ServiceName.Contains(model.ServiceName))
&& (!model.PharmacistId.HasValue || x.PharmacistId == model.PharmacistId))
.ToList()
.Select(x => x.GetViewModel)
.ToList();
@ -72,7 +72,8 @@ namespace VetClinicDataBaseImplement.Implements
using var transaction = context.Database.BeginTransaction();
try
{
var iceCream = context.Services.FirstOrDefault(rec =>
var iceCream = context.Services.Include(x => x.Pharmacist)
.Include(x => x.Medicines).ThenInclude(x => x.Medicine).FirstOrDefault(rec =>
rec.Id == model.Id);
if (iceCream == null)
{
@ -93,10 +94,9 @@ namespace VetClinicDataBaseImplement.Implements
public ServiceViewModel? Delete(ServiceBindingModel model)
{
using var context = new VetClinicDatabase();
var element = context.Services
var element = context.Services.Include(x => x.Pharmacist)
.Include(x => x.Medicines)
.ThenInclude(x => x.Medicine)
.ThenInclude(x => x.Animals).ThenInclude(x => x.Animal)
.FirstOrDefault(rec => rec.Id == model.Id);
if (element != null)
{

View File

@ -0,0 +1,84 @@
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using VetClinicContracts.BindingModels;
using VetClinicContracts.BusinessLogicsContracts;
using VetClinicContracts.SearchModels;
using VetClinicContracts.ViewModels;
using VetClinicDataBaseImplement.Models;
namespace VetClinicRestApi.Controllers
{
[Route("api/[controller]/[action]")]
[ApiController]
public class GuidanceController : ControllerBase
{
private readonly ILogger _logger;
private readonly IGuidanceLogic _guidance;
public GuidanceController(ILogger<GuidanceController> logger,
IGuidanceLogic guidance)
{
_logger = logger;
_guidance = guidance;
}
[HttpGet]
public List<GuidanceViewModel>? GetGuidances(int serviceId)
{
try
{
return _guidance.ReadList(new GuidanceSearchModel
{
ServiceId = serviceId
});
}
catch (Exception ex)
{
_logger.LogError(ex, "Ошибка получения списка рекомендааций услуги id ={ Id}", serviceId);
throw;
}
}
[HttpPost]
public void CreateGuidance(GuidanceBindingModel model)
{
try
{
_guidance.Create(model);
}
catch (Exception ex)
{
_logger.LogError(ex, "Ошибка создания рекомендации");
throw;
}
}
[HttpPost]
public bool UpdateGuidance(GuidanceBindingModel model)
{
try
{
return _guidance.Update(model);
}
catch (Exception ex)
{
_logger.LogError(ex, "Не удалось обновить рекомендацию");
throw;
}
}
[HttpPost]
public bool DeleteGuidance(GuidanceBindingModel model)
{
try
{
return _guidance.Delete(model);
}
catch (Exception ex)
{
_logger.LogError(ex, "Ошибка удаления рекомендации");
throw;
}
}
}
}

View File

@ -0,0 +1,96 @@
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using VetClinicContracts.BindingModels;
using VetClinicContracts.BusinessLogicsContracts;
using VetClinicContracts.SearchModels;
using VetClinicContracts.ViewModels;
namespace VetClinicRestApi.Controllers
{
[Route("api/[controller]/[action]")]
[ApiController]
public class ServiceController : Controller
{
private readonly ILogger _logger;
private readonly IServiceLogic _service;
public ServiceController(ILogger<ServiceController> logger, IServiceLogic service)
{
_logger = logger;
_service = service;
}
[HttpGet]
public Tuple<ServiceViewModel, List<Tuple<string, int>>>? GetService(int serviceId)
{
try
{
var elem = _service.ReadElement(new ServiceSearchModel { Id = serviceId });
if (elem == null)
return null;
return Tuple.Create(elem, elem.ServiceMedicines.Select(x => Tuple.Create(x.Value.Item1.MedicineName, x.Value.Item2)).ToList());
}
catch (Exception ex)
{
_logger.LogError(ex, "Ошибка получения услуги по id={Id}", serviceId);
throw;
}
}
[HttpGet]
public List<ServiceViewModel> GetServices(int pharmacistId)
{
try
{
return _service.ReadList(new ServiceSearchModel { PharmacistId = pharmacistId });
}
catch (Exception ex)
{
_logger.LogError(ex, "Ошибка получения списка услуг");
throw;
}
}
[HttpPost]
public bool CreateService(ServiceBindingModel model)
{
try
{
return _service.Create(model);
}
catch (Exception ex)
{
_logger.LogError(ex, "Не удалось создать услугу");
throw;
}
}
[HttpPost]
public bool UpdateService(ServiceBindingModel model)
{
try
{
model.ServiceMedicines = null!;
return _service.Update(model);
}
catch (Exception ex)
{
_logger.LogError(ex, "Не удалось обновить услугу");
throw;
}
}
[HttpPost]
public bool DeleteService(ServiceBindingModel model)
{
try
{
return _service.Delete(model);
}
catch (Exception ex)
{
_logger.LogError(ex, "Ошибка удаления услуги");
throw;
}
}
}
}