This commit is contained in:
gg12 darfren 2024-04-27 17:03:13 +04:00
parent 1ff125d5a9
commit ea42dc9fc4
3 changed files with 26 additions and 8 deletions

View File

@ -125,13 +125,22 @@ View(APIPharmacist.GetRequest<List<MedicineViewModel>>($"api/medicine/getmedicin
[HttpPost]
public void CreateMedicine(string name, int price, List<int> animals)
public void CreateMedicine(string name, string price, List<int> animals)
{
if (APIPharmacist.Pharmacist == null)
{
throw new Exception("Âû êàê ñþäà ïîïàëè? Ñþäà âõîä òîëüêî àâòîðèçîâàííûì");
}
if (string.IsNullOrEmpty(name) || price <= 0)
double _price;
try
{
_price = Convert.ToDouble(price);
}
catch(Exception ex)
{
throw new Exception("Îøèáêà â ââåäåííûõ äàííûõ");
}
if (string.IsNullOrEmpty(name) || _price <= 0)
{
throw new Exception("Îøèáêà â ââåäåííûõ äàííûõ");
}
@ -144,7 +153,7 @@ View(APIPharmacist.GetRequest<List<MedicineViewModel>>($"api/medicine/getmedicin
APIPharmacist.PostRequest("api/medicine/createmedicine", new MedicineBindingModel
{
MedicineName = name,
Price = price,
Price = Math.Round(_price, 2),
PharmacistId = APIPharmacist.Pharmacist.Id,
MedicineAnimals = a
}) ;
@ -187,14 +196,23 @@ 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, string price,
List<int> animals)
{
if (APIPharmacist.Pharmacist == null)
{
throw new Exception("Âû êàê ñþäà ïîïàëè? Ñþäà âõîä òîëüêî àâòîðèçîâàííûì");
}
if (string.IsNullOrEmpty(name) || price <= 0)
double _price;
try
{
_price = Convert.ToDouble(price);
}
catch (Exception ex)
{
throw new Exception("Îøèáêà â ââåäåííûõ äàííûõ");
}
if (string.IsNullOrEmpty(name) || _price <= 0)
{
throw new Exception("Îøèáêà â ââåäåííûõ äàííûõ");
}
@ -207,7 +225,7 @@ View(APIPharmacist.GetRequest<List<MedicineViewModel>>($"api/medicine/getmedicin
{
Id = medicine,
MedicineName = name,
Price = price,
Price = Math.Round(_price, 2),
PharmacistId = APIPharmacist.Pharmacist.Id,
MedicineAnimals = a
});

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>
<div class="row">
<div class="col-4">Животные:</div>

View File

@ -80,7 +80,7 @@ namespace VetClinicDataBaseImplement.Models
if (medicineAnimals != null && medicineAnimals.Count > 0)
{
context.MedicineAnimals.RemoveRange(medicineAnimals.Where(rec
=> !model.MedicineAnimals.ContainsKey(rec.AnimalId)));
=> !model.MedicineAnimals.ContainsKey(rec.MedicineId)));
context.SaveChanges();
}