diff --git a/VeterinaryView/VeterinaryDatabaseImplement/Implements/MedicationStorage.cs b/VeterinaryView/VeterinaryDatabaseImplement/Implements/MedicationStorage.cs index 9a9e1bb..c9e5afa 100644 --- a/VeterinaryView/VeterinaryDatabaseImplement/Implements/MedicationStorage.cs +++ b/VeterinaryView/VeterinaryDatabaseImplement/Implements/MedicationStorage.cs @@ -96,7 +96,7 @@ namespace VeterinaryDatabaseImplement.Implements { MedicationName = medication.MedicationName, Purchases = context.Purchases.Include(purchase => purchase.Drug).ThenInclude(drug => drug.Medications) - .Where(purchase => purchase.Drug != null && purchase.Drug.Medications.Select(x => x.MedicationId).ToList().Contains(medication.Id)) + .Where(purchase => purchase.Drug != null && purchase.Drug.Medications.Any(m => m.MedicationId == medication.Id)) .Select(purchase => purchase.GetViewModel).ToList() }).ToList(); } @@ -106,28 +106,25 @@ namespace VeterinaryDatabaseImplement.Implements using var context = new VeterinaryDatabase(); return context.Medications - .Select(pet => new ReportDrugsVisitsViewModel() - { - MedicationName = pet.MedicationName, - Drugs = context.Drugs - .Where(drug => drug.DateCreate <= model.DateTo && - drug.DateCreate >= model.DateFrom && drug.Medications - .Select(x => x.MedicationId) - .ToList() - .Contains(pet.Id)) - .Select(drug => drug.GetViewModel) - .ToList(), - Visits = context.Services - .Include(service => service.Visit) - .Where(service => service.Visit!=null&&service.Visit.DateVisit <= model.DateTo && - service.Visit.DateVisit >= model.DateFrom && service.Medications - .Select(x => x.MedicationId) - .ToList() - .Contains(pet.Id)) - .Select(service => service.Visit.GetViewModel) - .ToList(), - }) - .ToList(); + .Select(pet => new ReportDrugsVisitsViewModel() + { + MedicationName = pet.MedicationName, + Drugs = context.Drugs + .Where(drug => drug.DateCreate <= model.DateTo && + drug.DateCreate >= model.DateFrom && drug.Medications.Any(m => m.MedicationId == pet.Id)) + .Select(drug => drug.GetViewModel) + .ToList(), + Visits = context.Services + .Include(service => service.Visit) + .Where(service => service.Visit != null && service.Visit.DateVisit <= model.DateTo && + service.Visit.DateVisit >= model.DateFrom && service.Medications.Any(m => m.MedicationId == pet.Id)) + .Select(service => service.Visit.GetViewModel) + .ToList(), + }) + .ToList(); } + + + } } diff --git a/VeterinaryView/VeterinaryDatabaseImplement/Implements/PetStorage.cs b/VeterinaryView/VeterinaryDatabaseImplement/Implements/PetStorage.cs index 6a86763..cff141d 100644 --- a/VeterinaryView/VeterinaryDatabaseImplement/Implements/PetStorage.cs +++ b/VeterinaryView/VeterinaryDatabaseImplement/Implements/PetStorage.cs @@ -53,7 +53,7 @@ namespace VeterinaryDatabaseImplement.Implements { PetName = pet.PetName, Services = context.Services.Include(service => service.Visit).ThenInclude(visit => visit.Pets) - .Where(service => service.Visit!=null&&service.Visit.Pets.Select(x => x.PetId).ToList().Contains(pet.Id)) + .Where(service => service.Visit!=null&&service.Visit.Pets.Any(p => p.PetId == pet.Id)) .Select(service => service.GetViewModel).ToList() }).ToList(); } @@ -62,28 +62,22 @@ namespace VeterinaryDatabaseImplement.Implements using var context = new VeterinaryDatabase(); return context.Pets - .Select(pet => new ReportVisitsDrugsViewModel() - { - PetName = pet.PetName, - Visits = context.Visits - .Where(visit => visit.DateVisit <= model.DateTo && - visit.DateVisit >= model.DateFrom && visit.Pets - .Select(x => x.PetId) - .ToList() - .Contains(pet.Id)) - .Select(visit => visit.GetViewModel) - .ToList(), - Drugs = context.Purchases - .Include(purchase => purchase.Drug) - .Where(purchase => purchase.DateCreate <= model.DateTo && - purchase.DateCreate >= model.DateFrom && purchase.Pets - .Select(x => x.PetId) - .ToList() - .Contains(pet.Id)) - .Select(purchase => purchase.Drug.GetViewModel) - .ToList(), - }) - .ToList(); + .Select(pet => new ReportVisitsDrugsViewModel() + { + PetName = pet.PetName, + Visits = context.Visits + .Where(visit => visit.DateVisit <= model.DateTo && + visit.DateVisit >= model.DateFrom && visit.Pets.Any(p => p.PetId == pet.Id)) + .Select(visit => visit.GetViewModel) + .ToList(), + Drugs = context.Purchases + .Include(purchase => purchase.Drug) + .Where(purchase => purchase.DateCreate <= model.DateTo && + purchase.DateCreate >= model.DateFrom && purchase.Pets.Any(p => p.PetId == pet.Id)) + .Select(purchase => purchase.Drug.GetViewModel) + .ToList(), + }) + .ToList(); } public PetViewModel? Insert(PetBindingModel model) { diff --git a/VeterinaryView/VeterinaryRestApi/Controllers/DrugController.cs b/VeterinaryView/VeterinaryRestApi/Controllers/DrugController.cs index d013e3e..e6852ee 100644 --- a/VeterinaryView/VeterinaryRestApi/Controllers/DrugController.cs +++ b/VeterinaryView/VeterinaryRestApi/Controllers/DrugController.cs @@ -41,10 +41,12 @@ namespace VeterinaryRestApi.Controllers { try { - return _drug.ReadElement(new DrugSearchModel - { - Id =drugId - }); + var elem = _drug.ReadElement(new DrugSearchModel{Id =drugId}); + if (elem == null) + return null; + elem.DrugMedications = null!; + return elem; + } catch (Exception ex) { diff --git a/VeterinaryView/VeterinaryShowDoctorApp/Controllers/HomeController.cs b/VeterinaryView/VeterinaryShowDoctorApp/Controllers/HomeController.cs index 5d8a7cb..546e2e3 100644 --- a/VeterinaryView/VeterinaryShowDoctorApp/Controllers/HomeController.cs +++ b/VeterinaryView/VeterinaryShowDoctorApp/Controllers/HomeController.cs @@ -498,7 +498,7 @@ namespace VeterinaryShowDoctorApp.Controllers APIDoctor.PostRequest("api/report/createpurchaselistwordfile", new ReportPurchaseMedicationBindingModel { Medications = medications, - FileName = "C:\\ReportsCourseWork\\wordfile.docx" + FileName = "C:\\Users\\1\\Downloads\\wordfile.docx" }); Response.Redirect("GetWordFile"); } @@ -507,7 +507,7 @@ namespace VeterinaryShowDoctorApp.Controllers APIDoctor.PostRequest("api/report/createpurchaselistexcelfile", new ReportPurchaseMedicationBindingModel { Medications = medications, - FileName = "C:\\ReportsCourseWork\\excelfile.xlsx" + FileName = "C:\\Users\\1\\Downloads\\excelfile.xlsx" }); Response.Redirect("GetExcelFile"); } @@ -516,12 +516,12 @@ namespace VeterinaryShowDoctorApp.Controllers [HttpGet] public IActionResult GetWordFile() { - return new PhysicalFileResult("C:\\ReportsCourseWork\\wordfile.docx", "application/vnd.openxmlformats-officedocument.wordprocessingml.document"); + return new PhysicalFileResult("C:\\Users\\1\\Downloads\\wordfile.docx", "application/vnd.openxmlformats-officedocument.wordprocessingml.document"); } public IActionResult GetExcelFile() { - return new PhysicalFileResult("C:\\ReportsCourseWork\\excelfile.xlsx", "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet"); + return new PhysicalFileResult("C:\\Users\\1\\Downloads\\excelfile.xlsx", "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet"); } [HttpGet] public IActionResult Report() @@ -542,7 +542,7 @@ namespace VeterinaryShowDoctorApp.Controllers string dateFromS = dateFrom.ToString("s", CultureInfo.InvariantCulture); string dateToS = dateTo.ToString("s", CultureInfo.InvariantCulture); result = APIDoctor.GetRequest> - ($"api/report/getvisitsguidesreport?datefrom={dateFromS}&dateto={dateToS}&doctorid={APIDoctor.Doctor.Id}")!; // переделать + ($"api/report/getdrugsvisitsreport?datefrom={dateFromS}&dateto={dateToS}&doctorid={APIDoctor.Doctor.Id}")!; } catch (Exception ex) @@ -603,7 +603,7 @@ namespace VeterinaryShowDoctorApp.Controllers { throw new Exception("Вы как суда попали? Суда вход только авторизованным"); } - APIDoctor.PostRequest("api/report/sendvisitsguidesreporttoemail", new ReportDrugsVisitsBindingModel // поменять + APIDoctor.PostRequest("api/report/senddrugsvisitsreporttoemail", new ReportDrugsVisitsBindingModel { FileName = "C:\\ReportsCourseWork\\pdffile.pdf", DoctorId = APIDoctor.Doctor.Id, diff --git a/VeterinaryView/VeterinaryShowOwnerApp/Controllers/HomeController.cs b/VeterinaryView/VeterinaryShowOwnerApp/Controllers/HomeController.cs index 23ba107..21fec2c 100644 --- a/VeterinaryView/VeterinaryShowOwnerApp/Controllers/HomeController.cs +++ b/VeterinaryView/VeterinaryShowOwnerApp/Controllers/HomeController.cs @@ -353,7 +353,7 @@ namespace VeterinaryShowOwnerApp.Controllers return Redirect("~/Home/Enter"); } ViewBag.Pets = APIOwner.GetRequest>($"api/pet/getpets?ownerid={APIOwner.Owner.Id}"); - ViewBag.Drugs = APIOwner.GetRequest>($"api/drug/getalldrugs"); + ViewBag.Drugs = APIOwner.GetRequest>($"api/drug/getdrugs?doctorid={null}"); return View(); } [HttpPost] @@ -437,8 +437,8 @@ namespace VeterinaryShowOwnerApp.Controllers APIOwner.PostRequest("api/reportowner/createservicelistwordfile", new ReportServicesBindingModel { Pets = pets, - FileName = "C:\\ReportsCourseWork\\wordfile.docx" - }); + FileName = "C:\\Users\\1\\Downloads\\wordfile.docx" + }); Response.Redirect("GetWordFile"); } else @@ -446,23 +446,23 @@ namespace VeterinaryShowOwnerApp.Controllers APIOwner.PostRequest("api/reportowner/createservicelistexcelfile", new ReportServicesBindingModel { Pets = pets, - FileName = "C:\\ReportsCourseWork\\excelfile.xlsx" - }); + FileName = "C:\\Users\\1\\Downloads\\excelfile.xlsx" + }); Response.Redirect("GetExcelFile"); } } - [HttpGet] - public IActionResult GetWordFile() - { - return new PhysicalFileResult("C:\\ReportsCourseWork\\wordfile.docx", "application/vnd.openxmlformats-officedocument.wordprocessingml.document"); - } + [HttpGet] + public IActionResult GetWordFile() + { + return new PhysicalFileResult("C:\\Users\\1\\Downloads\\wordfile.docx", "application/vnd.openxmlformats-officedocument.wordprocessingml.document"); + } - public IActionResult GetExcelFile() - { - return new PhysicalFileResult("C:\\ReportsCourseWork\\excelfile.xlsx", "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet"); - } - [HttpGet] + public IActionResult GetExcelFile() + { + return new PhysicalFileResult("C:\\Users\\1\\Downloads\\excelfile.xlsx", "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet"); + } + [HttpGet] public IActionResult Report() { ViewBag.Report = new List();