дебаг идет
This commit is contained in:
parent
69cdb744c9
commit
58cc5f1286
@ -99,7 +99,7 @@ namespace VeterinaryBusinessLogic.BusinessLogic
|
||||
{
|
||||
throw new ArgumentNullException("Лекарств должно быть больше нуля", nameof(model.Count));
|
||||
}
|
||||
if (model.Price <= 0)
|
||||
if (model.Price < 0)
|
||||
{
|
||||
throw new ArgumentNullException("Цена лекарства должна быть больше 0", nameof(model.Price));
|
||||
}
|
||||
|
@ -28,14 +28,10 @@ namespace VeterinaryDatabaseImplement.Implements
|
||||
}
|
||||
public List<DrugViewModel> GetFilteredList(DrugSearchModel model)
|
||||
{
|
||||
if (string.IsNullOrEmpty(model.DrugName))
|
||||
{
|
||||
return new();
|
||||
}
|
||||
using var context = new VeterinaryDatabase();
|
||||
return context.Drugs.Where(x => x.DoctorId == model.DoctorId).Include(x => x.Medications)
|
||||
.ThenInclude(x => x.Medication)
|
||||
.Where(x => x.DrugName.Contains(model.DrugName))
|
||||
.Where(x => String.IsNullOrEmpty(model.DrugName) || x.DrugName.Contains(model.DrugName))
|
||||
.ToList()
|
||||
.Select(x => x.GetViewModel)
|
||||
.ToList();
|
||||
|
@ -26,14 +26,11 @@ namespace VeterinaryDatabaseImplement.Implements
|
||||
}
|
||||
public List<ServiceViewModel> GetFilteredList(ServiceSearchModel model)
|
||||
{
|
||||
if (string.IsNullOrEmpty(model.ServiceName))
|
||||
{
|
||||
return new();
|
||||
}
|
||||
|
||||
using var context = new VeterinaryDatabase();
|
||||
return context.Services.Include(x => x.Doctor).Include(x => x.Medications)
|
||||
.ThenInclude(x => x.Medication)
|
||||
.Where(x => x.ServiceName.Contains(model.ServiceName))
|
||||
.Where(x => String.IsNullOrEmpty(model.ServiceName) || x.ServiceName.Contains(model.ServiceName))
|
||||
.ToList()
|
||||
.Select(x => x.GetViewModel)
|
||||
.ToList();
|
||||
|
@ -6,6 +6,7 @@ using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using VeterinaryContracts.BindingModels;
|
||||
using VeterinaryContracts.SearchModels;
|
||||
using VeterinaryContracts.ViewModels;
|
||||
using VeterinaryDataModels.Models;
|
||||
|
||||
@ -43,17 +44,24 @@ namespace VeterinaryDatabaseImplement.Models
|
||||
public virtual List<Purchase> Purchases { get; set; } = new();
|
||||
public static Drug Create(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;
|
||||
}
|
||||
return new Drug()
|
||||
{
|
||||
Id = model.Id,
|
||||
DrugName = model.DrugName,
|
||||
Price = model.Price,
|
||||
|
||||
Count = model.Count,
|
||||
DoctorId = model.DoctorId,
|
||||
Medications = model.DrugMedications.Select(x => new DrugMedication
|
||||
{
|
||||
Medication = context.Medications.First(y => y.Id == x.Key)
|
||||
}).ToList()
|
||||
Medications = justMedications,
|
||||
Price = prc,
|
||||
};
|
||||
}
|
||||
public void Update(DrugBindingModel model)
|
||||
@ -66,8 +74,8 @@ namespace VeterinaryDatabaseImplement.Models
|
||||
Id = Id,
|
||||
DrugName = DrugName,
|
||||
Price = Price,
|
||||
Count= Count,
|
||||
DoctorId=DoctorId,
|
||||
DrugMedications = DrugMedications
|
||||
};
|
||||
public void UpdateMedications(VeterinaryDatabase context, DrugBindingModel model)
|
||||
{
|
||||
|
@ -65,7 +65,6 @@ namespace VeterinaryDatabaseImplement.Models
|
||||
ServiceName = ServiceName,
|
||||
DoctorId = DoctorId,
|
||||
VisitId = VisitId,
|
||||
ServiceMedications = ServiceMedications
|
||||
};
|
||||
|
||||
public void UpdateMedications(VeterinaryDatabase context, ServiceBindingModel model)
|
||||
|
@ -48,15 +48,24 @@ namespace VeterinaryRestApi.Controllers
|
||||
throw;
|
||||
}
|
||||
}
|
||||
[HttpGet]
|
||||
public List<DrugViewModel> GetAllDrugs(int doctorId)
|
||||
{
|
||||
try
|
||||
{
|
||||
return _drug.ReadList(null);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_logger.LogError(ex, "Ошибка получения списка лекартсв");
|
||||
throw;
|
||||
}
|
||||
}
|
||||
[HttpPost]
|
||||
public bool CreateDrug(DrugBindingModel model)
|
||||
{
|
||||
try
|
||||
{
|
||||
foreach(var medication in model.DrugMedications)
|
||||
{
|
||||
model.Price += medication.Value.Price;
|
||||
}
|
||||
return _drug.Create(model);
|
||||
}
|
||||
catch (Exception ex)
|
||||
|
@ -222,6 +222,8 @@ 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);
|
||||
}
|
||||
@ -233,7 +235,7 @@ namespace VeterinaryShowDoctorApp.Controllers
|
||||
Count = count,
|
||||
DoctorId = APIDoctor.Doctor.Id
|
||||
});
|
||||
Response.Redirect("Index");
|
||||
Response.Redirect("Drugs");
|
||||
}
|
||||
|
||||
public IActionResult DeleteDrug()
|
||||
@ -257,7 +259,7 @@ namespace VeterinaryShowDoctorApp.Controllers
|
||||
{
|
||||
Id = drug
|
||||
});
|
||||
Response.Redirect("Index");
|
||||
Response.Redirect("Drugs");
|
||||
}
|
||||
|
||||
public IActionResult UpdateDrug()
|
||||
@ -300,7 +302,7 @@ namespace VeterinaryShowDoctorApp.Controllers
|
||||
DrugMedications = a,
|
||||
Count = count
|
||||
});
|
||||
Response.Redirect("Index");
|
||||
Response.Redirect("Drugs");
|
||||
}
|
||||
|
||||
[HttpGet]
|
||||
@ -363,7 +365,7 @@ namespace VeterinaryShowDoctorApp.Controllers
|
||||
VisitId = visit,
|
||||
DoctorId = APIDoctor.Doctor.Id
|
||||
});
|
||||
Response.Redirect("Index");
|
||||
Response.Redirect("Services");
|
||||
}
|
||||
public IActionResult DeleteService()
|
||||
{
|
||||
@ -385,7 +387,7 @@ namespace VeterinaryShowDoctorApp.Controllers
|
||||
{
|
||||
Id = service
|
||||
});
|
||||
Response.Redirect("Index");
|
||||
Response.Redirect("Services");
|
||||
}
|
||||
public IActionResult UpdateService()
|
||||
{
|
||||
@ -420,7 +422,7 @@ namespace VeterinaryShowDoctorApp.Controllers
|
||||
ServiceName = name,
|
||||
ServiceMedications = a
|
||||
});
|
||||
Response.Redirect("Index");
|
||||
Response.Redirect("Services");
|
||||
}
|
||||
[HttpGet]
|
||||
public Tuple<ServiceViewModel, List<string>>? GetService(int serviceId)
|
||||
|
@ -15,7 +15,7 @@
|
||||
<div class="row">
|
||||
<div class="col-4">Визиты:</div>
|
||||
<div class="col-8">
|
||||
<select id="visits" name="visits" class="form-control" asp-items="@(new SelectList(@ViewBag.Visits, "Id", "VisitName"))"></select>
|
||||
<select id="visit" name="visit" class="form-control" asp-items="@(new SelectList(@ViewBag.Visits, "Id", "VisitName"))"></select>
|
||||
</div>
|
||||
</div>
|
||||
<div class="row">
|
||||
|
@ -27,6 +27,9 @@
|
||||
<th>
|
||||
Название
|
||||
</th>
|
||||
<th>
|
||||
Количество
|
||||
</th>
|
||||
<th>
|
||||
Цена
|
||||
</th>
|
||||
@ -42,6 +45,9 @@
|
||||
<td>
|
||||
@Html.DisplayFor(modelItem =>item.DrugName)
|
||||
</td>
|
||||
<td>
|
||||
@Html.DisplayFor(modelItem =>item.Count)
|
||||
</td>
|
||||
<td>
|
||||
@Html.DisplayFor(modelItem =>item.Price)
|
||||
</td>
|
||||
|
@ -27,6 +27,9 @@
|
||||
<th>
|
||||
Название
|
||||
</th>
|
||||
<th>
|
||||
Посещение
|
||||
</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
@ -39,6 +42,9 @@
|
||||
<td>
|
||||
@Html.DisplayFor(modelItem =>item.ServiceName)
|
||||
</td>
|
||||
<td>
|
||||
@Html.DisplayFor(modelItem =>item.VisitId)
|
||||
</td>
|
||||
</tr>
|
||||
}
|
||||
</tbody>
|
||||
|
Loading…
Reference in New Issue
Block a user