This commit is contained in:
antoc0der 2024-05-25 19:34:17 +04:00
parent 66cf43a690
commit ff38adfa15
8 changed files with 72 additions and 29 deletions

View File

@ -15,8 +15,8 @@ namespace VeterinaryBusinessLogic.OfficePackage.Implements
{
private WordprocessingDocument? _wordDocument;
private Body? _docBody;
private static JustificationValues
GetJustificationValues(WordJustificationType type)
// получение типов выравнивания
private static JustificationValues GetJustificationValues(WordJustificationType type)
{
return type switch
{
@ -25,6 +25,7 @@ namespace VeterinaryBusinessLogic.OfficePackage.Implements
_ => JustificationValues.Left,
};
}
// настройки страницы
private static SectionProperties CreateSectionProperties()
{
var properties = new SectionProperties();
@ -35,9 +36,8 @@ namespace VeterinaryBusinessLogic.OfficePackage.Implements
properties.AppendChild(pageSize);
return properties;
}
private static ParagraphProperties?
CreateParagraphProperties(WordTextProperties? paragraphProperties)
// задание форматирования для абзаца
private static ParagraphProperties? CreateParagraphProperties(WordTextProperties? paragraphProperties)
{
if (paragraphProperties == null)
{

View File

@ -11,6 +11,6 @@ namespace VeterinaryDataModels.Models
string ServiceName { get; }
int VisitId { get; }
int DoctorId { get; }
Dictionary<int, IMedicationModel> ServiceMedications { get; }
Dictionary<int, IMedicationModel> ServiceMedications { get; }
}
}

View File

@ -78,9 +78,10 @@ namespace VeterinaryDatabaseImplement.Implements
{
return null;
}
drug.Update(model);
context.SaveChanges();
drug.UpdateMedications(context, model);
context.SaveChanges();
drug.Update(context,model);
transaction.Commit();
return drug.GetViewModel;
}

View File

@ -68,10 +68,19 @@ namespace VeterinaryDatabaseImplement.Models
DateCreate= model.DateCreate
};
}
public void Update(DrugBindingModel model)
public void Update(VeterinaryDatabase context, DrugBindingModel model)
{
var justMedications = model.DrugMedications.Select(x => new DrugMedication
{
Medication = context.Medications.First(y => y.Id == x.Key)
}).ToList();
double prc = 0;
foreach (var justMedication in justMedications)
{
prc += justMedication.Medication.Price;
}
DrugName = model.DrugName;
Price = model.Price;
Price = prc;
}
public DrugViewModel GetViewModel => new()
{
@ -87,17 +96,24 @@ namespace VeterinaryDatabaseImplement.Models
var drugMedications = context.DrugMedications.Where(rec => rec.DrugId == model.Id).ToList();
if (drugMedications != null && drugMedications.Count > 0)
{
// из таблицы бд удаляем строчки, которые были отменены(которые раньше были а тепперь их в модели нет)
context.DrugMedications.RemoveRange(drugMedications.Where(rec => !model.DrugMedications.ContainsKey(rec.MedicationId)));
// сохраняемся
context.SaveChanges();
foreach (var updateMedication in drugMedications)
{
// из модели убираем то что осталось( но зачем?)
model.DrugMedications.Remove(updateMedication.MedicationId);
}
// сохраняемся
context.SaveChanges();
}
// собственно говоря, драг с которым мы работаем
var drug = context.Drugs.First(x => x.Id == Id);
foreach (var pc in model.DrugMedications)
{
// в бдшку добавляем строчки которые остались
context.DrugMedications.Add(new DrugMedication
{
Drug = drug,
@ -106,6 +122,7 @@ namespace VeterinaryDatabaseImplement.Models
context.SaveChanges();
}
_drugMedications = null;
}
}

View File

@ -18,7 +18,6 @@ namespace VeterinaryRestApi.Controllers
_logger = logger;
_drug = drug;
}
// naher ya eto pisal
[HttpGet]
public Tuple<DrugViewModel, List<string>>? GetDrug(int drugId)
{
@ -27,11 +26,13 @@ namespace VeterinaryRestApi.Controllers
var elem = _drug.ReadElement(new DrugSearchModel { Id = drugId });
if (elem == null)
return null;
return Tuple.Create(elem, elem.DrugMedications.Select(x => x.Value.MedicationName).ToList());
var huinya = Tuple.Create(elem, elem.DrugMedications.Select(x => x.Value.MedicationName).ToList());
return huinya;
//return Tuple.Create(elem, elem.DrugMedications.Select(x => x.Value.MedicationName).ToList());
}
catch (Exception ex)
{
_logger.LogError(ex, "Ошибка получения услуги по id={Id}", drugId);
_logger.LogError(ex, "Ошибка получения лекарства по id={Id}", drugId);
throw;
}
}
@ -47,7 +48,7 @@ namespace VeterinaryRestApi.Controllers
}
catch (Exception ex)
{
_logger.LogError(ex, "Ошибка получения продукта по id={Id}",drugId);
_logger.LogError(ex, "Ошибка получения лекарства по id={Id}",drugId);
throw;
}
}
@ -97,7 +98,7 @@ namespace VeterinaryRestApi.Controllers
{
try
{
model.DrugMedications = null!;
//model.DrugMedications = null!;
return _drug.Update(model);
}
catch (Exception ex)

View File

@ -3,6 +3,7 @@ using VeterinaryContracts.BindingModels;
using VeterinaryContracts.BusinessLogicContracts;
using VeterinaryContracts.SearchModels;
using VeterinaryContracts.ViewModels;
using VeterinaryDatabaseImplement.Models;
namespace VeterinaryRestApi.Controllers
{
@ -17,7 +18,22 @@ namespace VeterinaryRestApi.Controllers
_logger = logger;
_medication = medication;
}
[HttpGet]
public MedicationViewModel? GetMedication(int medicationId)
{
try
{
return _medication.ReadElement(new MedicationSearchModel
{
Id = medicationId
});
}
catch (Exception ex)
{
_logger.LogError(ex, "Ошибка получения медикамента по id={Id}", medicationId);
throw;
}
}
[HttpGet]
public List<MedicationViewModel> GetMedications(int doctorId)
{

View File

@ -107,6 +107,20 @@ namespace VeterinaryShowDoctorApp.Controllers
return;
}
// medications
[HttpGet]
public MedicationViewModel? GetMedication(int medicationId)
{
if (APIDoctor.Doctor == null)
{
throw new Exception("Вы как суда попали? Суда вход только авторизованным");
}
var result = APIDoctor.GetRequest <MedicationViewModel>($"api/medication/getmedication?medicationid={medicationId}");
if (result == null)
{
return default;
}
return result;
}
public IActionResult CreateMedication()
{
if (APIDoctor.Doctor == null)
@ -222,9 +236,6 @@ namespace VeterinaryShowDoctorApp.Controllers
Dictionary<int, IMedicationModel> a = new Dictionary<int, IMedicationModel>();
foreach (int medication in medications)
{
var yeah = new MedicationSearchModel { Id = medication } ;
IMedicationModel tmp = yeah as IMedicationModel;
// фигачит нулл в значение
a.Add(medication, new MedicationSearchModel { Id = medication } as IMedicationModel);
}
APIDoctor.PostRequest("api/drug/createdrug", new DrugBindingModel
@ -233,7 +244,8 @@ namespace VeterinaryShowDoctorApp.Controllers
Price = 0,
DrugMedications = a,
Count = count,
DoctorId = APIDoctor.Doctor.Id
DoctorId = APIDoctor.Doctor.Id,
DateCreate = DateTime.Now,
});
Response.Redirect("Drugs");
}
@ -269,7 +281,7 @@ namespace VeterinaryShowDoctorApp.Controllers
return Redirect("~/Home/Enter");
}
ViewBag.Drugs = APIDoctor.GetRequest<List<DrugViewModel>>($"api/drug/getdrugs?doctorid={APIDoctor.Doctor.Id}");
ViewBag.Medications = APIDoctor.GetRequest<List<MedicationViewModel>>($"api/medication/getmedications");
ViewBag.Medications = APIDoctor.GetRequest<List<MedicationViewModel>>($"api/medication/getmedications?doctorid={APIDoctor.Doctor.Id}");
return View();
}
@ -290,15 +302,11 @@ namespace VeterinaryShowDoctorApp.Controllers
{
a.Add(medication, new MedicationSearchModel { Id = medication } as IMedicationModel);
}
foreach (var elem in a)
{
_price += elem.Value.Price;
}
APIDoctor.PostRequest("api/drug/updatedrug", new DrugBindingModel
{
Id = drug,
DrugName = name,
Price = Math.Round(_price, 2),
Price = 0,
DrugMedications = a,
Count = count
});

View File

@ -20,7 +20,7 @@
</div>
<div class="row">
<div class="col-4">Цена:</div>
<div class="col-8"><input type="number" id="price" name="price" class="form-control" /></div>
<div class="col-8"><input type="text" id="price" name="price" class="form-control" /></div>
</div>
@ -41,8 +41,8 @@
url: "/Home/GetMedication",
data: { medicationId: medication },
success: function (result) {
$('#name').val(result.item1.medicationName);
$('#price').val(result.item1.price);
$('#name').val(result.medicationName);
$('#price').val(result.price);
}
});
};