From 66cf43a690fcdad59e732b5d1e6b5d3ebbe96511 Mon Sep 17 00:00:00 2001 From: antoc0der <1@DESKTOP-K1L8ND3> Date: Sat, 25 May 2024 14:47:52 +0400 Subject: [PATCH] =?UTF-8?q?=D0=B2=D1=81=D1=8F=D0=BA=D0=BE=D0=B5=20=D0=B3?= =?UTF-8?q?=D0=BE=D0=B2=D0=BD=D0=BE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../BusinessLogic/PurchaseLogic.cs | 8 +- .../BindingModels/DrugBindingModel.cs | 2 +- .../SearchModels/DrugSearchModel.cs | 2 +- .../ViewModels/DrugViewModel.cs | 2 + .../VeterinaryDataModels/Models/IDrugModel.cs | 1 + .../Implements/DrugStorage.cs | 3 +- ... 20240525104527_InitialCreate.Designer.cs} | 18 ++- ...ate.cs => 20240525104527_InitialCreate.cs} | 152 ++++++++++-------- .../VeterinaryDatabaseModelSnapshot.cs | 16 ++ .../Models/Doctor.cs | 2 + .../Models/Drug.cs | 7 +- .../Controllers/HomeController.cs | 8 +- 12 files changed, 140 insertions(+), 81 deletions(-) rename VeterinaryView/VeterinaryDatabaseImplement/Migrations/{20240523163748_InitialCreate.Designer.cs => 20240525104527_InitialCreate.Designer.cs} (96%) rename VeterinaryView/VeterinaryDatabaseImplement/Migrations/{20240523163748_InitialCreate.cs => 20240525104527_InitialCreate.cs} (96%) diff --git a/VeterinaryView/VeterinaryBusinessLogic/BusinessLogic/PurchaseLogic.cs b/VeterinaryView/VeterinaryBusinessLogic/BusinessLogic/PurchaseLogic.cs index 7894ace..d68a61c 100644 --- a/VeterinaryView/VeterinaryBusinessLogic/BusinessLogic/PurchaseLogic.cs +++ b/VeterinaryView/VeterinaryBusinessLogic/BusinessLogic/PurchaseLogic.cs @@ -89,10 +89,10 @@ namespace VeterinaryBusinessLogic.BusinessLogic { throw new ArgumentNullException("Цена заказа должна быть больше 0", nameof(model.Sum)); } - if (model.DateCreate <= DateTime.Now) - { - throw new ArgumentNullException("Дата покупки не должна быть в прошлом", nameof(model.DateCreate)); - } + //if (model.DateCreate < DateTime.Now) + //{ + // throw new ArgumentNullException("Дата покупки не должна быть в прошлом", nameof(model.DateCreate)); + //} if (model.Count <= 0) { throw new ArgumentNullException("Количество элементов в заказе должно быть больше 0", nameof(model.Count)); diff --git a/VeterinaryView/VeterinaryContracts/BindingModels/DrugBindingModel.cs b/VeterinaryView/VeterinaryContracts/BindingModels/DrugBindingModel.cs index d6d910b..20826ed 100644 --- a/VeterinaryView/VeterinaryContracts/BindingModels/DrugBindingModel.cs +++ b/VeterinaryView/VeterinaryContracts/BindingModels/DrugBindingModel.cs @@ -19,6 +19,6 @@ namespace VeterinaryContracts.BindingModels set; } = new(); public int DoctorId { get; set; } - + public DateTime DateCreate { get; set; } } } diff --git a/VeterinaryView/VeterinaryContracts/SearchModels/DrugSearchModel.cs b/VeterinaryView/VeterinaryContracts/SearchModels/DrugSearchModel.cs index b72297e..a931bc0 100644 --- a/VeterinaryView/VeterinaryContracts/SearchModels/DrugSearchModel.cs +++ b/VeterinaryView/VeterinaryContracts/SearchModels/DrugSearchModel.cs @@ -11,6 +11,6 @@ namespace VeterinaryContracts.SearchModels public int? Id { get; set; } public string? DrugName { get; set; } public int? DoctorId { get; set; } - + public DateTime? DateCreate { get; set; } } } diff --git a/VeterinaryView/VeterinaryContracts/ViewModels/DrugViewModel.cs b/VeterinaryView/VeterinaryContracts/ViewModels/DrugViewModel.cs index e203e9a..6bc78de 100644 --- a/VeterinaryView/VeterinaryContracts/ViewModels/DrugViewModel.cs +++ b/VeterinaryView/VeterinaryContracts/ViewModels/DrugViewModel.cs @@ -17,6 +17,8 @@ namespace VeterinaryContracts.ViewModels public int Count { get; set; } [DisplayName("Цена лекарства")] public double Price { get; set; } + [DisplayName("Дата создания")] + public DateTime DateCreate { get; set; } public Dictionary DrugMedications { diff --git a/VeterinaryView/VeterinaryDataModels/Models/IDrugModel.cs b/VeterinaryView/VeterinaryDataModels/Models/IDrugModel.cs index 3cd5f2a..43667ef 100644 --- a/VeterinaryView/VeterinaryDataModels/Models/IDrugModel.cs +++ b/VeterinaryView/VeterinaryDataModels/Models/IDrugModel.cs @@ -13,5 +13,6 @@ namespace VeterinaryDataModels.Models double Price { get; } Dictionary DrugMedications { get; } int DoctorId { get; } + DateTime DateCreate { get; } } } diff --git a/VeterinaryView/VeterinaryDatabaseImplement/Implements/DrugStorage.cs b/VeterinaryView/VeterinaryDatabaseImplement/Implements/DrugStorage.cs index 44a6a72..db165ab 100644 --- a/VeterinaryView/VeterinaryDatabaseImplement/Implements/DrugStorage.cs +++ b/VeterinaryView/VeterinaryDatabaseImplement/Implements/DrugStorage.cs @@ -31,7 +31,8 @@ namespace VeterinaryDatabaseImplement.Implements using var context = new VeterinaryDatabase(); return context.Drugs.Where(x => x.DoctorId == model.DoctorId).Include(x => x.Medications) .ThenInclude(x => x.Medication) - .Where(x => String.IsNullOrEmpty(model.DrugName) || x.DrugName.Contains(model.DrugName)) + .Where(x => String.IsNullOrEmpty(model.DrugName) || x.DrugName.Contains(model.DrugName) && + (!model.DateCreate.HasValue || x.DateCreate >= model.DateCreate)) .ToList() .Select(x => x.GetViewModel) .ToList(); diff --git a/VeterinaryView/VeterinaryDatabaseImplement/Migrations/20240523163748_InitialCreate.Designer.cs b/VeterinaryView/VeterinaryDatabaseImplement/Migrations/20240525104527_InitialCreate.Designer.cs similarity index 96% rename from VeterinaryView/VeterinaryDatabaseImplement/Migrations/20240523163748_InitialCreate.Designer.cs rename to VeterinaryView/VeterinaryDatabaseImplement/Migrations/20240525104527_InitialCreate.Designer.cs index 2fdcd3c..74fd834 100644 --- a/VeterinaryView/VeterinaryDatabaseImplement/Migrations/20240523163748_InitialCreate.Designer.cs +++ b/VeterinaryView/VeterinaryDatabaseImplement/Migrations/20240525104527_InitialCreate.Designer.cs @@ -12,7 +12,7 @@ using VeterinaryDatabaseImplement; namespace VeterinaryDatabaseImplement.Migrations { [DbContext(typeof(VeterinaryDatabase))] - [Migration("20240523163748_InitialCreate")] + [Migration("20240525104527_InitialCreate")] partial class InitialCreate { /// @@ -61,6 +61,9 @@ namespace VeterinaryDatabaseImplement.Migrations b.Property("Count") .HasColumnType("int"); + b.Property("DateCreate") + .HasColumnType("datetime2"); + b.Property("DoctorId") .HasColumnType("int"); @@ -73,6 +76,8 @@ namespace VeterinaryDatabaseImplement.Migrations b.HasKey("Id"); + b.HasIndex("DoctorId"); + b.ToTable("Drugs"); }); @@ -345,6 +350,15 @@ namespace VeterinaryDatabaseImplement.Migrations b.ToTable("VisitPets"); }); + modelBuilder.Entity("VeterinaryDatabaseImplement.Models.Drug", b => + { + b.HasOne("VeterinaryDatabaseImplement.Models.Doctor", null) + .WithMany("Drugs") + .HasForeignKey("DoctorId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + }); + modelBuilder.Entity("VeterinaryDatabaseImplement.Models.DrugMedication", b => { b.HasOne("VeterinaryDatabaseImplement.Models.Drug", "Drug") @@ -500,6 +514,8 @@ namespace VeterinaryDatabaseImplement.Migrations modelBuilder.Entity("VeterinaryDatabaseImplement.Models.Doctor", b => { + b.Navigation("Drugs"); + b.Navigation("Medications"); b.Navigation("Services"); diff --git a/VeterinaryView/VeterinaryDatabaseImplement/Migrations/20240523163748_InitialCreate.cs b/VeterinaryView/VeterinaryDatabaseImplement/Migrations/20240525104527_InitialCreate.cs similarity index 96% rename from VeterinaryView/VeterinaryDatabaseImplement/Migrations/20240523163748_InitialCreate.cs rename to VeterinaryView/VeterinaryDatabaseImplement/Migrations/20240525104527_InitialCreate.cs index d46cabb..4c3cf56 100644 --- a/VeterinaryView/VeterinaryDatabaseImplement/Migrations/20240523163748_InitialCreate.cs +++ b/VeterinaryView/VeterinaryDatabaseImplement/Migrations/20240525104527_InitialCreate.cs @@ -26,22 +26,6 @@ namespace VeterinaryDatabaseImplement.Migrations table.PrimaryKey("PK_Doctors", x => x.Id); }); - migrationBuilder.CreateTable( - name: "Drugs", - columns: table => new - { - Id = table.Column(type: "int", nullable: false) - .Annotation("SqlServer:Identity", "1, 1"), - DrugName = table.Column(type: "nvarchar(max)", nullable: false), - Price = table.Column(type: "float", nullable: false), - Count = table.Column(type: "int", nullable: false), - DoctorId = table.Column(type: "int", nullable: false) - }, - constraints: table => - { - table.PrimaryKey("PK_Drugs", x => x.Id); - }); - migrationBuilder.CreateTable( name: "Owners", columns: table => new @@ -57,6 +41,29 @@ namespace VeterinaryDatabaseImplement.Migrations table.PrimaryKey("PK_Owners", x => x.Id); }); + migrationBuilder.CreateTable( + name: "Drugs", + columns: table => new + { + Id = table.Column(type: "int", nullable: false) + .Annotation("SqlServer:Identity", "1, 1"), + DrugName = table.Column(type: "nvarchar(max)", nullable: false), + Price = table.Column(type: "float", nullable: false), + Count = table.Column(type: "int", nullable: false), + DoctorId = table.Column(type: "int", nullable: false), + DateCreate = table.Column(type: "datetime2", nullable: false) + }, + constraints: table => + { + table.PrimaryKey("PK_Drugs", x => x.Id); + table.ForeignKey( + name: "FK_Drugs_Doctors_DoctorId", + column: x => x.DoctorId, + principalTable: "Doctors", + principalColumn: "Id", + onDelete: ReferentialAction.Restrict); + }); + migrationBuilder.CreateTable( name: "Medications", columns: table => new @@ -101,6 +108,34 @@ namespace VeterinaryDatabaseImplement.Migrations onDelete: ReferentialAction.Restrict); }); + migrationBuilder.CreateTable( + name: "Visits", + columns: table => new + { + Id = table.Column(type: "int", nullable: false) + .Annotation("SqlServer:Identity", "1, 1"), + OwnerId = table.Column(type: "int", nullable: false), + DoctorId = table.Column(type: "int", nullable: false), + VisitName = table.Column(type: "nvarchar(max)", nullable: false), + DateVisit = table.Column(type: "datetime2", nullable: false) + }, + constraints: table => + { + table.PrimaryKey("PK_Visits", x => x.Id); + table.ForeignKey( + name: "FK_Visits_Doctors_DoctorId", + column: x => x.DoctorId, + principalTable: "Doctors", + principalColumn: "Id", + onDelete: ReferentialAction.Restrict); + table.ForeignKey( + name: "FK_Visits_Owners_OwnerId", + column: x => x.OwnerId, + principalTable: "Owners", + principalColumn: "Id", + onDelete: ReferentialAction.Restrict); + }); + migrationBuilder.CreateTable( name: "Purchases", columns: table => new @@ -131,34 +166,6 @@ namespace VeterinaryDatabaseImplement.Migrations onDelete: ReferentialAction.Restrict); }); - migrationBuilder.CreateTable( - name: "Visits", - columns: table => new - { - Id = table.Column(type: "int", nullable: false) - .Annotation("SqlServer:Identity", "1, 1"), - OwnerId = table.Column(type: "int", nullable: false), - DoctorId = table.Column(type: "int", nullable: false), - VisitName = table.Column(type: "nvarchar(max)", nullable: false), - DateVisit = table.Column(type: "datetime2", nullable: false) - }, - constraints: table => - { - table.PrimaryKey("PK_Visits", x => x.Id); - table.ForeignKey( - name: "FK_Visits_Doctors_DoctorId", - column: x => x.DoctorId, - principalTable: "Doctors", - principalColumn: "Id", - onDelete: ReferentialAction.Restrict); - table.ForeignKey( - name: "FK_Visits_Owners_OwnerId", - column: x => x.OwnerId, - principalTable: "Owners", - principalColumn: "Id", - onDelete: ReferentialAction.Restrict); - }); - migrationBuilder.CreateTable( name: "DrugMedications", columns: table => new @@ -185,32 +192,6 @@ namespace VeterinaryDatabaseImplement.Migrations onDelete: ReferentialAction.Cascade); }); - migrationBuilder.CreateTable( - name: "PurchasePets", - columns: table => new - { - Id = table.Column(type: "int", nullable: false) - .Annotation("SqlServer:Identity", "1, 1"), - PurchaseId = table.Column(type: "int", nullable: false), - PetId = table.Column(type: "int", nullable: false) - }, - constraints: table => - { - table.PrimaryKey("PK_PurchasePets", x => x.Id); - table.ForeignKey( - name: "FK_PurchasePets_Pets_PetId", - column: x => x.PetId, - principalTable: "Pets", - principalColumn: "Id", - onDelete: ReferentialAction.Cascade); - table.ForeignKey( - name: "FK_PurchasePets_Purchases_PurchaseId", - column: x => x.PurchaseId, - principalTable: "Purchases", - principalColumn: "Id", - onDelete: ReferentialAction.Cascade); - }); - migrationBuilder.CreateTable( name: "Services", columns: table => new @@ -264,6 +245,32 @@ namespace VeterinaryDatabaseImplement.Migrations onDelete: ReferentialAction.Cascade); }); + migrationBuilder.CreateTable( + name: "PurchasePets", + columns: table => new + { + Id = table.Column(type: "int", nullable: false) + .Annotation("SqlServer:Identity", "1, 1"), + PurchaseId = table.Column(type: "int", nullable: false), + PetId = table.Column(type: "int", nullable: false) + }, + constraints: table => + { + table.PrimaryKey("PK_PurchasePets", x => x.Id); + table.ForeignKey( + name: "FK_PurchasePets_Pets_PetId", + column: x => x.PetId, + principalTable: "Pets", + principalColumn: "Id", + onDelete: ReferentialAction.Cascade); + table.ForeignKey( + name: "FK_PurchasePets_Purchases_PurchaseId", + column: x => x.PurchaseId, + principalTable: "Purchases", + principalColumn: "Id", + onDelete: ReferentialAction.Cascade); + }); + migrationBuilder.CreateTable( name: "ServiceMedications", columns: table => new @@ -300,6 +307,11 @@ namespace VeterinaryDatabaseImplement.Migrations table: "DrugMedications", column: "MedicationId"); + migrationBuilder.CreateIndex( + name: "IX_Drugs_DoctorId", + table: "Drugs", + column: "DoctorId"); + migrationBuilder.CreateIndex( name: "IX_Medications_DoctorId", table: "Medications", diff --git a/VeterinaryView/VeterinaryDatabaseImplement/Migrations/VeterinaryDatabaseModelSnapshot.cs b/VeterinaryView/VeterinaryDatabaseImplement/Migrations/VeterinaryDatabaseModelSnapshot.cs index d185c82..82f197a 100644 --- a/VeterinaryView/VeterinaryDatabaseImplement/Migrations/VeterinaryDatabaseModelSnapshot.cs +++ b/VeterinaryView/VeterinaryDatabaseImplement/Migrations/VeterinaryDatabaseModelSnapshot.cs @@ -58,6 +58,9 @@ namespace VeterinaryDatabaseImplement.Migrations b.Property("Count") .HasColumnType("int"); + b.Property("DateCreate") + .HasColumnType("datetime2"); + b.Property("DoctorId") .HasColumnType("int"); @@ -70,6 +73,8 @@ namespace VeterinaryDatabaseImplement.Migrations b.HasKey("Id"); + b.HasIndex("DoctorId"); + b.ToTable("Drugs"); }); @@ -342,6 +347,15 @@ namespace VeterinaryDatabaseImplement.Migrations b.ToTable("VisitPets"); }); + modelBuilder.Entity("VeterinaryDatabaseImplement.Models.Drug", b => + { + b.HasOne("VeterinaryDatabaseImplement.Models.Doctor", null) + .WithMany("Drugs") + .HasForeignKey("DoctorId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + }); + modelBuilder.Entity("VeterinaryDatabaseImplement.Models.DrugMedication", b => { b.HasOne("VeterinaryDatabaseImplement.Models.Drug", "Drug") @@ -497,6 +511,8 @@ namespace VeterinaryDatabaseImplement.Migrations modelBuilder.Entity("VeterinaryDatabaseImplement.Models.Doctor", b => { + b.Navigation("Drugs"); + b.Navigation("Medications"); b.Navigation("Services"); diff --git a/VeterinaryView/VeterinaryDatabaseImplement/Models/Doctor.cs b/VeterinaryView/VeterinaryDatabaseImplement/Models/Doctor.cs index 7e310cb..14f96be 100644 --- a/VeterinaryView/VeterinaryDatabaseImplement/Models/Doctor.cs +++ b/VeterinaryView/VeterinaryDatabaseImplement/Models/Doctor.cs @@ -26,6 +26,8 @@ namespace VeterinaryDatabaseImplement.Models public virtual List Medications { get; set; } = new(); [ForeignKey("DoctorId")] public virtual List Visits { get; set; } = new(); + [ForeignKey("DoctorId")] + public virtual List Drugs { get; set; } = new(); public static Doctor? Create(DoctorBindingModel model) { if (model == null) diff --git a/VeterinaryView/VeterinaryDatabaseImplement/Models/Drug.cs b/VeterinaryView/VeterinaryDatabaseImplement/Models/Drug.cs index 3857087..793fda7 100644 --- a/VeterinaryView/VeterinaryDatabaseImplement/Models/Drug.cs +++ b/VeterinaryView/VeterinaryDatabaseImplement/Models/Drug.cs @@ -1,4 +1,5 @@ -using System; +using Microsoft.EntityFrameworkCore.Storage; +using System; using System.Collections.Generic; using System.ComponentModel.DataAnnotations; using System.ComponentModel.DataAnnotations.Schema; @@ -23,6 +24,8 @@ namespace VeterinaryDatabaseImplement.Models public int Count { get; set; } [Required] public int DoctorId { get; private set; } + [Required] + public DateTime DateCreate { get; private set; } private Dictionary? _drugMedications = null; [NotMapped] public Dictionary DrugMedications @@ -62,6 +65,7 @@ namespace VeterinaryDatabaseImplement.Models DoctorId = model.DoctorId, Medications = justMedications, Price = prc, + DateCreate= model.DateCreate }; } public void Update(DrugBindingModel model) @@ -76,6 +80,7 @@ namespace VeterinaryDatabaseImplement.Models Price = Price, Count= Count, DoctorId=DoctorId, + DateCreate = DateCreate }; public void UpdateMedications(VeterinaryDatabase context, DrugBindingModel model) { diff --git a/VeterinaryView/VeterinaryShowOwnerApp/Controllers/HomeController.cs b/VeterinaryView/VeterinaryShowOwnerApp/Controllers/HomeController.cs index 5681db1..4cd6e3c 100644 --- a/VeterinaryView/VeterinaryShowOwnerApp/Controllers/HomeController.cs +++ b/VeterinaryView/VeterinaryShowOwnerApp/Controllers/HomeController.cs @@ -359,15 +359,19 @@ namespace VeterinaryShowOwnerApp.Controllers OwnerId = APIOwner.Owner.Id, DrugId = drug, PurchasePet = a, - Sum = Calc(count, drug) + Sum = Calc(count, drug), + DateCreate = DateTime.Now, + Count = count }); Response.Redirect("Index"); } + // с какого хера ты не работаешь [HttpPost] public double Calc(int count, int drug) { var dru = APIOwner.GetRequest($"api/drug/getonedrug?drugId={drug}"); - return count * (dru?.Price ?? 1); + //return count * (dru?.Price ?? 1); + return Math.Round(count * (dru?.Price ?? 1), 2); } [HttpGet]