Да начнём материться

This commit is contained in:
Yunusov_Niyaz 2024-05-26 22:03:17 +04:00
commit 248feacf7b
5 changed files with 27 additions and 13 deletions

View File

@ -18,6 +18,7 @@ namespace VeterinaryDatabaseImplement.Implements
{
using var context = new VeterinaryDatabase();
return context.Services.Include(x=>x.Doctor)
.Include(x => x.Visit)
.Include(x => x.Medications)
.ThenInclude(x => x.Medication)
.ToList()
@ -28,7 +29,7 @@ namespace VeterinaryDatabaseImplement.Implements
{
using var context = new VeterinaryDatabase();
return context.Services.Include(x => x.Doctor).Include(x => x.Medications)
return context.Services.Include(x => x.Doctor).Include(x => x.Visit).Include(x => x.Medications)
.ThenInclude(x => x.Medication)
.Where(x => String.IsNullOrEmpty(model.ServiceName) || x.ServiceName.Contains(model.ServiceName))
.ToList()
@ -44,6 +45,7 @@ namespace VeterinaryDatabaseImplement.Implements
}
using var context = new VeterinaryDatabase();
return context.Services.Include(x => x.Doctor)
.Include(x => x.Visit)
.Include(x => x.Medications)
.ThenInclude(x => x.Medication)
.FirstOrDefault(x => (!string.IsNullOrEmpty(model.ServiceName) &&
@ -91,7 +93,7 @@ namespace VeterinaryDatabaseImplement.Implements
public ServiceViewModel? Delete(ServiceBindingModel model)
{
using var context = new VeterinaryDatabase();
var element = context.Services.Include(x => x.Doctor)
var element = context.Services.Include(x => x.Doctor).Include(x => x.Visit)
.Include(x => x.Medications)
.FirstOrDefault(rec => rec.Id == model.Id);
if (element != null)

View File

@ -19,10 +19,12 @@ namespace VeterinaryDatabaseImplement.Models
public string ServiceName { get; set; } = string.Empty;
[Required]
public int DoctorId { get; private set; }
public virtual Doctor? Doctor { get; private set; }
[Required]
public int VisitId { get; private set; }
public virtual Doctor? Doctor { get; private set; }
public virtual Visit? Visit { get; private set; }
private Dictionary<int, IMedicationModel>? _serviceMedications = null;
[NotMapped]
@ -66,6 +68,8 @@ namespace VeterinaryDatabaseImplement.Models
DoctorId = DoctorId,
VisitId = VisitId,
VisitName = Visit?.VisitName ?? string.Empty,
ServiceMedications = ServiceMedications
};
public void UpdateMedications(VeterinaryDatabase context, ServiceBindingModel model)

View File

@ -17,16 +17,17 @@ namespace VeterinaryRestApi.Controllers
_logger = logger;
_service = service;
}
[HttpGet]
public Tuple<ServiceViewModel, List<string>>? GetService(int serviceId)
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.ServiceMedications.Select(x => x.Value.MedicationName).ToList());
var res = Tuple.Create(elem, elem.ServiceMedications.Select(x => Tuple.Create(x.Value.MedicationName, x.Value.Id)).ToList());
res.Item1.ServiceMedications = null!;
return res;
}
catch (Exception ex)
{
@ -35,11 +36,18 @@ namespace VeterinaryRestApi.Controllers
}
}
[HttpGet]
public List<ServiceViewModel> GetServices(int doctorId)
public List<ServiceViewModel> GetServices(int? doctorId = null)
{
try
{
return _service.ReadList(new ServiceSearchModel { DoctorId = doctorId });
List<ServiceViewModel> res;
if (!doctorId.HasValue)
res = _service.ReadList(null);
else
res = _service.ReadList(new ServiceSearchModel { DoctorId = doctorId.Value });
foreach (var service in res)
service.ServiceMedications = null;
return res;
}
catch (Exception ex)
{
@ -66,7 +74,7 @@ namespace VeterinaryRestApi.Controllers
{
try
{
model.ServiceMedications = null!;
///model.ServiceMedications = null!;
return _service.Update(model);
}
catch (Exception ex)

View File

@ -433,13 +433,13 @@ namespace VeterinaryShowDoctorApp.Controllers
Response.Redirect("Services");
}
[HttpGet]
public Tuple<ServiceViewModel, List<string>>? GetService(int serviceId)
public Tuple<ServiceViewModel, List<Tuple<string, int>>>? GetService(int serviceId)
{
if (APIDoctor.Doctor == null)
{
throw new Exception("Вы как суда попали? Суда вход только авторизованным");
}
var result = APIDoctor.GetRequest<Tuple<ServiceViewModel, List<string>>>($"api/service/getservice?serviceid={serviceId}");
var result = APIDoctor.GetRequest<Tuple<ServiceViewModel, List<Tuple<string, int>>>>($"api/service/getservice?serviceid={serviceId}");
if (result == null)
{
return default;

View File

@ -24,7 +24,7 @@
<select name="medications" class="form-control" multiple size="5" id="medications">
@foreach (var medication in ViewBag.Medications)
{
<option value="@medication.Id" id="@medication.MedicationName">@medication.MedicationName</option>
<option value="@medication.Id" data-name="@medication.Id">@medication.MedicationName</option>
}
</select>
</div>
@ -51,7 +51,7 @@
$('#name').val(result.item1.serviceName);
$.map(result.item2, function (n) {
console.log("#" + n);
$("#" + n).attr("selected", "selected")
$(`option[data-name=${n.item2}]`).attr("selected", "selected")
});
}