diff --git a/VeterinaryView/VeterinaryContracts/BindingModels/DrugBindingModel.cs b/VeterinaryView/VeterinaryContracts/BindingModels/DrugBindingModel.cs index b3a192a..4e16a0b 100644 --- a/VeterinaryView/VeterinaryContracts/BindingModels/DrugBindingModel.cs +++ b/VeterinaryView/VeterinaryContracts/BindingModels/DrugBindingModel.cs @@ -13,7 +13,7 @@ namespace VeterinaryContracts.BindingModels public string DrugName { get; set; } = string.Empty; public int Count { get; set; } public double Price { get; set; } - public Dictionary DrugMedications + public Dictionary DrugMedications { get; set; diff --git a/VeterinaryView/VeterinaryContracts/BindingModels/ServiceBindingModel.cs b/VeterinaryView/VeterinaryContracts/BindingModels/ServiceBindingModel.cs index 1fd5503..7ddaf00 100644 --- a/VeterinaryView/VeterinaryContracts/BindingModels/ServiceBindingModel.cs +++ b/VeterinaryView/VeterinaryContracts/BindingModels/ServiceBindingModel.cs @@ -13,7 +13,7 @@ namespace VeterinaryContracts.BindingModels public string ServiceName { get; set; } = string.Empty; public int VisitId { get; set; } public int DoctorId { get; set; } - public Dictionary ServiceMedications + public Dictionary ServiceMedications { get; set; diff --git a/VeterinaryView/VeterinaryContracts/ViewModels/DrugViewModel.cs b/VeterinaryView/VeterinaryContracts/ViewModels/DrugViewModel.cs index 3d0a0e4..08c2cd2 100644 --- a/VeterinaryView/VeterinaryContracts/ViewModels/DrugViewModel.cs +++ b/VeterinaryView/VeterinaryContracts/ViewModels/DrugViewModel.cs @@ -18,7 +18,7 @@ namespace VeterinaryContracts.ViewModels [DisplayName("Цена лекарства")] public double Price { get; set; } - public Dictionary DrugMedications + public Dictionary DrugMedications { get; set; diff --git a/VeterinaryView/VeterinaryContracts/ViewModels/ServiceViewModel.cs b/VeterinaryView/VeterinaryContracts/ViewModels/ServiceViewModel.cs index 78591da..3046ceb 100644 --- a/VeterinaryView/VeterinaryContracts/ViewModels/ServiceViewModel.cs +++ b/VeterinaryView/VeterinaryContracts/ViewModels/ServiceViewModel.cs @@ -15,7 +15,7 @@ namespace VeterinaryContracts.ViewModels public string ServiceName { get; set; } = string.Empty; public int VisitId { get; set; } public int DoctorId { get; set; } - public Dictionary ServiceMedications + public Dictionary ServiceMedications { get; set; diff --git a/VeterinaryView/VeterinaryDataModels/IDrugModel.cs b/VeterinaryView/VeterinaryDataModels/IDrugModel.cs new file mode 100644 index 0000000..f41989d --- /dev/null +++ b/VeterinaryView/VeterinaryDataModels/IDrugModel.cs @@ -0,0 +1,16 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace VeterinaryDataModels +{ + public interface IDrugModel :IId + { + string DrugName { get; } + int Count { get; } + double Price { get; } + Dictionary DrugMedications { get; } + } +} diff --git a/VeterinaryView/VeterinaryDataModels/IServiceModel.cs b/VeterinaryView/VeterinaryDataModels/IServiceModel.cs new file mode 100644 index 0000000..743cb2e --- /dev/null +++ b/VeterinaryView/VeterinaryDataModels/IServiceModel.cs @@ -0,0 +1,17 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace VeterinaryDataModels +{ + public interface IServiceModel : IId + { + String ServiceName { get;} + int VisitId { get; } + int DoctorId { get; } + Dictionary ServiceMedications { get; } + + } +} diff --git a/VeterinaryView/VeterinaryDatabaseImplement/Implements/MedicationStorage.cs b/VeterinaryView/VeterinaryDatabaseImplement/Implements/MedicationStorage.cs index b6c967d..89b1c78 100644 --- a/VeterinaryView/VeterinaryDatabaseImplement/Implements/MedicationStorage.cs +++ b/VeterinaryView/VeterinaryDatabaseImplement/Implements/MedicationStorage.cs @@ -25,13 +25,10 @@ namespace VeterinaryDatabaseImplement.Implements } public List GetFilteredList(MedicationSearchModel model) { - if (string.IsNullOrEmpty(model.MedicationName)) - { - return new(); - } + using var context = new VeterinaryDatabase(); - return context.Medications - .Where(x => x.MedicationName.Contains(model.MedicationName)) + return context.Medications.Where(x=>x.DoctorId == model.DoctorId) + .Where(x => String.IsNullOrEmpty(model.MedicationName) || x.MedicationName.Contains(model.MedicationName)) .Select(x => x.GetViewModel) .ToList(); } diff --git a/VeterinaryView/VeterinaryDatabaseImplement/Migrations/20240427075947_InitialCreate.Designer.cs b/VeterinaryView/VeterinaryDatabaseImplement/Migrations/20240427075947_InitialCreate.Designer.cs deleted file mode 100644 index 8811374..0000000 --- a/VeterinaryView/VeterinaryDatabaseImplement/Migrations/20240427075947_InitialCreate.Designer.cs +++ /dev/null @@ -1,551 +0,0 @@ -// -using System; -using Microsoft.EntityFrameworkCore; -using Microsoft.EntityFrameworkCore.Infrastructure; -using Microsoft.EntityFrameworkCore.Metadata; -using Microsoft.EntityFrameworkCore.Migrations; -using Microsoft.EntityFrameworkCore.Storage.ValueConversion; -using VeterinaryDatabaseImplement; - -#nullable disable - -namespace VeterinaryDatabaseImplement.Migrations -{ - [DbContext(typeof(VeterinaryDatabase))] - [Migration("20240427075947_InitialCreate")] - partial class InitialCreate - { - /// - protected override void BuildTargetModel(ModelBuilder modelBuilder) - { -#pragma warning disable 612, 618 - modelBuilder - .HasAnnotation("ProductVersion", "7.0.16") - .HasAnnotation("Relational:MaxIdentifierLength", 128); - - SqlServerModelBuilderExtensions.UseIdentityColumns(modelBuilder); - - modelBuilder.Entity("VeterinaryDatabaseImplement.Models.Doctor", b => - { - b.Property("Id") - .ValueGeneratedOnAdd() - .HasColumnType("int"); - - SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); - - b.Property("DoctorFIO") - .IsRequired() - .HasColumnType("nvarchar(max)"); - - b.Property("Login") - .IsRequired() - .HasColumnType("nvarchar(max)"); - - b.Property("Password") - .IsRequired() - .HasColumnType("nvarchar(max)"); - - b.HasKey("Id"); - - b.ToTable("Doctors"); - }); - - modelBuilder.Entity("VeterinaryDatabaseImplement.Models.Drug", b => - { - b.Property("Id") - .ValueGeneratedOnAdd() - .HasColumnType("int"); - - SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); - - b.Property("Count") - .HasColumnType("int"); - - b.Property("DrugName") - .IsRequired() - .HasColumnType("nvarchar(max)"); - - b.Property("Price") - .HasColumnType("float"); - - b.HasKey("Id"); - - b.ToTable("Drugs"); - }); - - modelBuilder.Entity("VeterinaryDatabaseImplement.Models.DrugMedication", b => - { - b.Property("Id") - .ValueGeneratedOnAdd() - .HasColumnType("int"); - - SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); - - b.Property("Count") - .HasColumnType("int"); - - b.Property("DrugId") - .HasColumnType("int"); - - b.Property("MedicationId") - .HasColumnType("int"); - - b.HasKey("Id"); - - b.HasIndex("DrugId"); - - b.HasIndex("MedicationId"); - - b.ToTable("DrugMedications"); - }); - - modelBuilder.Entity("VeterinaryDatabaseImplement.Models.Medication", b => - { - b.Property("Id") - .ValueGeneratedOnAdd() - .HasColumnType("int"); - - SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); - - b.Property("DoctorId") - .HasColumnType("int"); - - b.Property("MedicationName") - .IsRequired() - .HasColumnType("nvarchar(max)"); - - b.Property("Price") - .HasColumnType("float"); - - b.HasKey("Id"); - - b.HasIndex("DoctorId"); - - b.ToTable("Medications"); - }); - - modelBuilder.Entity("VeterinaryDatabaseImplement.Models.Owner", b => - { - b.Property("Id") - .ValueGeneratedOnAdd() - .HasColumnType("int"); - - SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); - - b.Property("Login") - .IsRequired() - .HasColumnType("nvarchar(max)"); - - b.Property("OwnerFIO") - .IsRequired() - .HasColumnType("nvarchar(max)"); - - b.Property("Password") - .IsRequired() - .HasColumnType("nvarchar(max)"); - - b.HasKey("Id"); - - b.ToTable("Owners"); - }); - - modelBuilder.Entity("VeterinaryDatabaseImplement.Models.Pet", b => - { - b.Property("Id") - .ValueGeneratedOnAdd() - .HasColumnType("int"); - - SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); - - b.Property("OwnerId") - .HasColumnType("int"); - - b.Property("PetBreed") - .IsRequired() - .HasColumnType("nvarchar(max)"); - - b.Property("PetGender") - .IsRequired() - .HasColumnType("nvarchar(max)"); - - b.Property("PetName") - .IsRequired() - .HasColumnType("nvarchar(max)"); - - b.Property("PetType") - .IsRequired() - .HasColumnType("nvarchar(max)"); - - b.HasKey("Id"); - - b.HasIndex("OwnerId"); - - b.ToTable("Pets"); - }); - - modelBuilder.Entity("VeterinaryDatabaseImplement.Models.Purchase", b => - { - b.Property("Id") - .ValueGeneratedOnAdd() - .HasColumnType("int"); - - SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); - - b.Property("Count") - .HasColumnType("int"); - - b.Property("DatePurchase") - .HasColumnType("datetime2"); - - b.Property("DrugId") - .HasColumnType("int"); - - b.Property("OwnerId") - .HasColumnType("int"); - - b.Property("Sum") - .HasColumnType("float"); - - b.HasKey("Id"); - - b.HasIndex("DrugId"); - - b.HasIndex("OwnerId"); - - b.ToTable("Purchases"); - }); - - modelBuilder.Entity("VeterinaryDatabaseImplement.Models.PurchasePet", b => - { - b.Property("Id") - .ValueGeneratedOnAdd() - .HasColumnType("int"); - - SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); - - b.Property("PetId") - .HasColumnType("int"); - - b.Property("PurchaseId") - .HasColumnType("int"); - - b.HasKey("Id"); - - b.HasIndex("PetId"); - - b.HasIndex("PurchaseId"); - - b.ToTable("PurchasePets"); - }); - - modelBuilder.Entity("VeterinaryDatabaseImplement.Models.Service", b => - { - b.Property("Id") - .ValueGeneratedOnAdd() - .HasColumnType("int"); - - SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); - - b.Property("DoctorId") - .HasColumnType("int"); - - b.Property("ServiceName") - .IsRequired() - .HasColumnType("nvarchar(max)"); - - b.Property("VisitId") - .HasColumnType("int"); - - b.HasKey("Id"); - - b.HasIndex("DoctorId"); - - b.HasIndex("VisitId"); - - b.ToTable("Services"); - }); - - modelBuilder.Entity("VeterinaryDatabaseImplement.Models.ServiceMedication", b => - { - b.Property("Id") - .ValueGeneratedOnAdd() - .HasColumnType("int"); - - SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); - - b.Property("Count") - .HasColumnType("int"); - - b.Property("MedicationId") - .HasColumnType("int"); - - b.Property("ServiceId") - .HasColumnType("int"); - - b.HasKey("Id"); - - b.HasIndex("MedicationId"); - - b.HasIndex("ServiceId"); - - b.ToTable("ServiceMedications"); - }); - - modelBuilder.Entity("VeterinaryDatabaseImplement.Models.Visit", b => - { - b.Property("Id") - .ValueGeneratedOnAdd() - .HasColumnType("int"); - - SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); - - b.Property("DateVisit") - .HasColumnType("datetime2"); - - b.Property("DoctorId") - .IsRequired() - .HasColumnType("int"); - - b.Property("OwnerId") - .HasColumnType("int"); - - b.HasKey("Id"); - - b.HasIndex("DoctorId"); - - b.HasIndex("OwnerId"); - - b.ToTable("Visits"); - }); - - modelBuilder.Entity("VeterinaryDatabaseImplement.Models.VisitPet", b => - { - b.Property("Id") - .ValueGeneratedOnAdd() - .HasColumnType("int"); - - SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); - - b.Property("PetId") - .HasColumnType("int"); - - b.Property("VisitId") - .HasColumnType("int"); - - b.HasKey("Id"); - - b.HasIndex("PetId"); - - b.HasIndex("VisitId"); - - b.ToTable("VisitPets"); - }); - - modelBuilder.Entity("VeterinaryDatabaseImplement.Models.DrugMedication", b => - { - b.HasOne("VeterinaryDatabaseImplement.Models.Drug", "Drug") - .WithMany("Medications") - .HasForeignKey("DrugId") - .OnDelete(DeleteBehavior.Cascade) - .IsRequired(); - - b.HasOne("VeterinaryDatabaseImplement.Models.Medication", "Medication") - .WithMany("DrugMedications") - .HasForeignKey("MedicationId") - .OnDelete(DeleteBehavior.Cascade) - .IsRequired(); - - b.Navigation("Drug"); - - b.Navigation("Medication"); - }); - - modelBuilder.Entity("VeterinaryDatabaseImplement.Models.Medication", b => - { - b.HasOne("VeterinaryDatabaseImplement.Models.Doctor", null) - .WithMany("Medications") - .HasForeignKey("DoctorId") - .OnDelete(DeleteBehavior.Cascade) - .IsRequired(); - }); - - modelBuilder.Entity("VeterinaryDatabaseImplement.Models.Pet", b => - { - b.HasOne("VeterinaryDatabaseImplement.Models.Owner", null) - .WithMany("Pets") - .HasForeignKey("OwnerId") - .OnDelete(DeleteBehavior.Cascade) - .IsRequired(); - }); - - modelBuilder.Entity("VeterinaryDatabaseImplement.Models.Purchase", b => - { - b.HasOne("VeterinaryDatabaseImplement.Models.Drug", "Drug") - .WithMany("Purchases") - .HasForeignKey("DrugId") - .OnDelete(DeleteBehavior.Cascade) - .IsRequired(); - - b.HasOne("VeterinaryDatabaseImplement.Models.Owner", "Owner") - .WithMany("Purchases") - .HasForeignKey("OwnerId") - .OnDelete(DeleteBehavior.Cascade) - .IsRequired(); - - b.Navigation("Drug"); - - b.Navigation("Owner"); - }); - - modelBuilder.Entity("VeterinaryDatabaseImplement.Models.PurchasePet", b => - { - b.HasOne("VeterinaryDatabaseImplement.Models.Pet", "Pet") - .WithMany("PurchasePets") - .HasForeignKey("PetId") - .OnDelete(DeleteBehavior.Cascade) - .IsRequired(); - - b.HasOne("VeterinaryDatabaseImplement.Models.Purchase", "Purchase") - .WithMany("Pets") - .HasForeignKey("PurchaseId") - .OnDelete(DeleteBehavior.Cascade) - .IsRequired(); - - b.Navigation("Pet"); - - b.Navigation("Purchase"); - }); - - modelBuilder.Entity("VeterinaryDatabaseImplement.Models.Service", b => - { - b.HasOne("VeterinaryDatabaseImplement.Models.Doctor", "Doctor") - .WithMany("Services") - .HasForeignKey("DoctorId") - .OnDelete(DeleteBehavior.Cascade) - .IsRequired(); - - b.HasOne("VeterinaryDatabaseImplement.Models.Visit", null) - .WithMany("Services") - .HasForeignKey("VisitId") - .OnDelete(DeleteBehavior.Cascade) - .IsRequired(); - - b.Navigation("Doctor"); - }); - - modelBuilder.Entity("VeterinaryDatabaseImplement.Models.ServiceMedication", b => - { - b.HasOne("VeterinaryDatabaseImplement.Models.Medication", "Medication") - .WithMany("ServiceMedications") - .HasForeignKey("MedicationId") - .OnDelete(DeleteBehavior.Cascade) - .IsRequired(); - - b.HasOne("VeterinaryDatabaseImplement.Models.Service", "Service") - .WithMany("Medications") - .HasForeignKey("ServiceId") - .OnDelete(DeleteBehavior.Cascade) - .IsRequired(); - - b.Navigation("Medication"); - - b.Navigation("Service"); - }); - - modelBuilder.Entity("VeterinaryDatabaseImplement.Models.Visit", b => - { - b.HasOne("VeterinaryDatabaseImplement.Models.Doctor", "Doctor") - .WithMany("Visits") - .HasForeignKey("DoctorId") - .OnDelete(DeleteBehavior.Cascade) - .IsRequired(); - - b.HasOne("VeterinaryDatabaseImplement.Models.Owner", "Owner") - .WithMany("Visits") - .HasForeignKey("OwnerId") - .OnDelete(DeleteBehavior.Cascade) - .IsRequired(); - - b.Navigation("Doctor"); - - b.Navigation("Owner"); - }); - - modelBuilder.Entity("VeterinaryDatabaseImplement.Models.VisitPet", b => - { - b.HasOne("VeterinaryDatabaseImplement.Models.Pet", "Pet") - .WithMany("VisitPets") - .HasForeignKey("PetId") - .OnDelete(DeleteBehavior.Cascade) - .IsRequired(); - - b.HasOne("VeterinaryDatabaseImplement.Models.Visit", "Visit") - .WithMany("Pets") - .HasForeignKey("VisitId") - .OnDelete(DeleteBehavior.Cascade) - .IsRequired(); - - b.Navigation("Pet"); - - b.Navigation("Visit"); - }); - - modelBuilder.Entity("VeterinaryDatabaseImplement.Models.Doctor", b => - { - b.Navigation("Medications"); - - b.Navigation("Services"); - - b.Navigation("Visits"); - }); - - modelBuilder.Entity("VeterinaryDatabaseImplement.Models.Drug", b => - { - b.Navigation("Medications"); - - b.Navigation("Purchases"); - }); - - modelBuilder.Entity("VeterinaryDatabaseImplement.Models.Medication", b => - { - b.Navigation("DrugMedications"); - - b.Navigation("ServiceMedications"); - }); - - modelBuilder.Entity("VeterinaryDatabaseImplement.Models.Owner", b => - { - b.Navigation("Pets"); - - b.Navigation("Purchases"); - - b.Navigation("Visits"); - }); - - modelBuilder.Entity("VeterinaryDatabaseImplement.Models.Pet", b => - { - b.Navigation("PurchasePets"); - - b.Navigation("VisitPets"); - }); - - modelBuilder.Entity("VeterinaryDatabaseImplement.Models.Purchase", b => - { - b.Navigation("Pets"); - }); - - modelBuilder.Entity("VeterinaryDatabaseImplement.Models.Service", b => - { - b.Navigation("Medications"); - }); - - modelBuilder.Entity("VeterinaryDatabaseImplement.Models.Visit", b => - { - b.Navigation("Pets"); - - b.Navigation("Services"); - }); -#pragma warning restore 612, 618 - } - } -} diff --git a/VeterinaryView/VeterinaryDatabaseImplement/Migrations/20240427075947_InitialCreate.cs b/VeterinaryView/VeterinaryDatabaseImplement/Migrations/20240427075947_InitialCreate.cs deleted file mode 100644 index 6d65bbd..0000000 --- a/VeterinaryView/VeterinaryDatabaseImplement/Migrations/20240427075947_InitialCreate.cs +++ /dev/null @@ -1,413 +0,0 @@ -using System; -using Microsoft.EntityFrameworkCore.Migrations; - -#nullable disable - -namespace VeterinaryDatabaseImplement.Migrations -{ - /// - public partial class InitialCreate : Migration - { - /// - protected override void Up(MigrationBuilder migrationBuilder) - { - migrationBuilder.CreateTable( - name: "Doctors", - columns: table => new - { - Id = table.Column(type: "int", nullable: false) - .Annotation("SqlServer:Identity", "1, 1"), - DoctorFIO = table.Column(type: "nvarchar(max)", nullable: false), - Login = table.Column(type: "nvarchar(max)", nullable: false), - Password = table.Column(type: "nvarchar(max)", nullable: false) - }, - constraints: table => - { - 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) - }, - constraints: table => - { - table.PrimaryKey("PK_Drugs", x => x.Id); - }); - - migrationBuilder.CreateTable( - name: "Owners", - columns: table => new - { - Id = table.Column(type: "int", nullable: false) - .Annotation("SqlServer:Identity", "1, 1"), - OwnerFIO = table.Column(type: "nvarchar(max)", nullable: false), - Login = table.Column(type: "nvarchar(max)", nullable: false), - Password = table.Column(type: "nvarchar(max)", nullable: false) - }, - constraints: table => - { - table.PrimaryKey("PK_Owners", x => x.Id); - }); - - migrationBuilder.CreateTable( - name: "Medications", - columns: table => new - { - Id = table.Column(type: "int", nullable: false) - .Annotation("SqlServer:Identity", "1, 1"), - MedicationName = table.Column(type: "nvarchar(max)", nullable: false), - Price = table.Column(type: "float", nullable: false), - DoctorId = table.Column(type: "int", nullable: false) - }, - constraints: table => - { - table.PrimaryKey("PK_Medications", x => x.Id); - table.ForeignKey( - name: "FK_Medications_Doctors_DoctorId", - column: x => x.DoctorId, - principalTable: "Doctors", - principalColumn: "Id", - onDelete: ReferentialAction.Restrict); - }); - - migrationBuilder.CreateTable( - name: "Pets", - columns: table => new - { - Id = table.Column(type: "int", nullable: false) - .Annotation("SqlServer:Identity", "1, 1"), - OwnerId = table.Column(type: "int", nullable: false), - PetName = table.Column(type: "nvarchar(max)", nullable: false), - PetType = table.Column(type: "nvarchar(max)", nullable: false), - PetBreed = table.Column(type: "nvarchar(max)", nullable: false), - PetGender = table.Column(type: "nvarchar(max)", nullable: false) - }, - constraints: table => - { - table.PrimaryKey("PK_Pets", x => x.Id); - table.ForeignKey( - name: "FK_Pets_Owners_OwnerId", - column: x => x.OwnerId, - principalTable: "Owners", - principalColumn: "Id", - onDelete: ReferentialAction.Restrict); - }); - - migrationBuilder.CreateTable( - name: "Purchases", - columns: table => new - { - Id = table.Column(type: "int", nullable: false) - .Annotation("SqlServer:Identity", "1, 1"), - OwnerId = table.Column(type: "int", nullable: false), - DrugId = table.Column(type: "int", nullable: false), - Count = table.Column(type: "int", nullable: false), - Sum = table.Column(type: "float", nullable: false), - DatePurchase = table.Column(type: "datetime2", nullable: false) - }, - constraints: table => - { - table.PrimaryKey("PK_Purchases", x => x.Id); - table.ForeignKey( - name: "FK_Purchases_Drugs_DrugId", - column: x => x.DrugId, - principalTable: "Drugs", - principalColumn: "Id", - onDelete: ReferentialAction.Cascade); - table.ForeignKey( - name: "FK_Purchases_Owners_OwnerId", - column: x => x.OwnerId, - principalTable: "Owners", - principalColumn: "Id", - 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), - 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 - { - Id = table.Column(type: "int", nullable: false) - .Annotation("SqlServer:Identity", "1, 1"), - DrugId = table.Column(type: "int", nullable: false), - MedicationId = table.Column(type: "int", nullable: false), - Count = table.Column(type: "int", nullable: false) - }, - constraints: table => - { - table.PrimaryKey("PK_DrugMedications", x => x.Id); - table.ForeignKey( - name: "FK_DrugMedications_Drugs_DrugId", - column: x => x.DrugId, - principalTable: "Drugs", - principalColumn: "Id", - onDelete: ReferentialAction.Cascade); - table.ForeignKey( - name: "FK_DrugMedications_Medications_MedicationId", - column: x => x.MedicationId, - principalTable: "Medications", - principalColumn: "Id", - 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 - { - Id = table.Column(type: "int", nullable: false) - .Annotation("SqlServer:Identity", "1, 1"), - ServiceName = table.Column(type: "nvarchar(max)", nullable: false), - DoctorId = table.Column(type: "int", nullable: false), - VisitId = table.Column(type: "int", nullable: false) - }, - constraints: table => - { - table.PrimaryKey("PK_Services", x => x.Id); - table.ForeignKey( - name: "FK_Services_Doctors_DoctorId", - column: x => x.DoctorId, - principalTable: "Doctors", - principalColumn: "Id", - onDelete: ReferentialAction.Restrict); - table.ForeignKey( - name: "FK_Services_Visits_VisitId", - column: x => x.VisitId, - principalTable: "Visits", - principalColumn: "Id", - onDelete: ReferentialAction.Cascade); - }); - - migrationBuilder.CreateTable( - name: "VisitPets", - columns: table => new - { - Id = table.Column(type: "int", nullable: false) - .Annotation("SqlServer:Identity", "1, 1"), - VisitId = table.Column(type: "int", nullable: false), - PetId = table.Column(type: "int", nullable: false) - }, - constraints: table => - { - table.PrimaryKey("PK_VisitPets", x => x.Id); - table.ForeignKey( - name: "FK_VisitPets_Pets_PetId", - column: x => x.PetId, - principalTable: "Pets", - principalColumn: "Id", - onDelete: ReferentialAction.Cascade); - table.ForeignKey( - name: "FK_VisitPets_Visits_VisitId", - column: x => x.VisitId, - principalTable: "Visits", - principalColumn: "Id", - onDelete: ReferentialAction.Cascade); - }); - - migrationBuilder.CreateTable( - name: "ServiceMedications", - columns: table => new - { - Id = table.Column(type: "int", nullable: false) - .Annotation("SqlServer:Identity", "1, 1"), - ServiceId = table.Column(type: "int", nullable: false), - MedicationId = table.Column(type: "int", nullable: false), - Count = table.Column(type: "int", nullable: false) - }, - constraints: table => - { - table.PrimaryKey("PK_ServiceMedications", x => x.Id); - table.ForeignKey( - name: "FK_ServiceMedications_Medications_MedicationId", - column: x => x.MedicationId, - principalTable: "Medications", - principalColumn: "Id", - onDelete: ReferentialAction.Cascade); - table.ForeignKey( - name: "FK_ServiceMedications_Services_ServiceId", - column: x => x.ServiceId, - principalTable: "Services", - principalColumn: "Id", - onDelete: ReferentialAction.Cascade); - }); - - migrationBuilder.CreateIndex( - name: "IX_DrugMedications_DrugId", - table: "DrugMedications", - column: "DrugId"); - - migrationBuilder.CreateIndex( - name: "IX_DrugMedications_MedicationId", - table: "DrugMedications", - column: "MedicationId"); - - migrationBuilder.CreateIndex( - name: "IX_Medications_DoctorId", - table: "Medications", - column: "DoctorId"); - - migrationBuilder.CreateIndex( - name: "IX_Pets_OwnerId", - table: "Pets", - column: "OwnerId"); - - migrationBuilder.CreateIndex( - name: "IX_PurchasePets_PetId", - table: "PurchasePets", - column: "PetId"); - - migrationBuilder.CreateIndex( - name: "IX_PurchasePets_PurchaseId", - table: "PurchasePets", - column: "PurchaseId"); - - migrationBuilder.CreateIndex( - name: "IX_Purchases_DrugId", - table: "Purchases", - column: "DrugId"); - - migrationBuilder.CreateIndex( - name: "IX_Purchases_OwnerId", - table: "Purchases", - column: "OwnerId"); - - migrationBuilder.CreateIndex( - name: "IX_ServiceMedications_MedicationId", - table: "ServiceMedications", - column: "MedicationId"); - - migrationBuilder.CreateIndex( - name: "IX_ServiceMedications_ServiceId", - table: "ServiceMedications", - column: "ServiceId"); - - migrationBuilder.CreateIndex( - name: "IX_Services_DoctorId", - table: "Services", - column: "DoctorId"); - - migrationBuilder.CreateIndex( - name: "IX_Services_VisitId", - table: "Services", - column: "VisitId"); - - migrationBuilder.CreateIndex( - name: "IX_VisitPets_PetId", - table: "VisitPets", - column: "PetId"); - - migrationBuilder.CreateIndex( - name: "IX_VisitPets_VisitId", - table: "VisitPets", - column: "VisitId"); - - migrationBuilder.CreateIndex( - name: "IX_Visits_DoctorId", - table: "Visits", - column: "DoctorId"); - - migrationBuilder.CreateIndex( - name: "IX_Visits_OwnerId", - table: "Visits", - column: "OwnerId"); - } - - /// - protected override void Down(MigrationBuilder migrationBuilder) - { - migrationBuilder.DropTable( - name: "DrugMedications"); - - migrationBuilder.DropTable( - name: "PurchasePets"); - - migrationBuilder.DropTable( - name: "ServiceMedications"); - - migrationBuilder.DropTable( - name: "VisitPets"); - - migrationBuilder.DropTable( - name: "Purchases"); - - migrationBuilder.DropTable( - name: "Medications"); - - migrationBuilder.DropTable( - name: "Services"); - - migrationBuilder.DropTable( - name: "Pets"); - - migrationBuilder.DropTable( - name: "Drugs"); - - migrationBuilder.DropTable( - name: "Visits"); - - migrationBuilder.DropTable( - name: "Doctors"); - - migrationBuilder.DropTable( - name: "Owners"); - } - } -} diff --git a/VeterinaryView/VeterinaryDatabaseImplement/Migrations/VeterinaryDatabaseModelSnapshot.cs b/VeterinaryView/VeterinaryDatabaseImplement/Migrations/VeterinaryDatabaseModelSnapshot.cs deleted file mode 100644 index 32e1cc9..0000000 --- a/VeterinaryView/VeterinaryDatabaseImplement/Migrations/VeterinaryDatabaseModelSnapshot.cs +++ /dev/null @@ -1,548 +0,0 @@ -// -using System; -using Microsoft.EntityFrameworkCore; -using Microsoft.EntityFrameworkCore.Infrastructure; -using Microsoft.EntityFrameworkCore.Metadata; -using Microsoft.EntityFrameworkCore.Storage.ValueConversion; -using VeterinaryDatabaseImplement; - -#nullable disable - -namespace VeterinaryDatabaseImplement.Migrations -{ - [DbContext(typeof(VeterinaryDatabase))] - partial class VeterinaryDatabaseModelSnapshot : ModelSnapshot - { - protected override void BuildModel(ModelBuilder modelBuilder) - { -#pragma warning disable 612, 618 - modelBuilder - .HasAnnotation("ProductVersion", "7.0.16") - .HasAnnotation("Relational:MaxIdentifierLength", 128); - - SqlServerModelBuilderExtensions.UseIdentityColumns(modelBuilder); - - modelBuilder.Entity("VeterinaryDatabaseImplement.Models.Doctor", b => - { - b.Property("Id") - .ValueGeneratedOnAdd() - .HasColumnType("int"); - - SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); - - b.Property("DoctorFIO") - .IsRequired() - .HasColumnType("nvarchar(max)"); - - b.Property("Login") - .IsRequired() - .HasColumnType("nvarchar(max)"); - - b.Property("Password") - .IsRequired() - .HasColumnType("nvarchar(max)"); - - b.HasKey("Id"); - - b.ToTable("Doctors"); - }); - - modelBuilder.Entity("VeterinaryDatabaseImplement.Models.Drug", b => - { - b.Property("Id") - .ValueGeneratedOnAdd() - .HasColumnType("int"); - - SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); - - b.Property("Count") - .HasColumnType("int"); - - b.Property("DrugName") - .IsRequired() - .HasColumnType("nvarchar(max)"); - - b.Property("Price") - .HasColumnType("float"); - - b.HasKey("Id"); - - b.ToTable("Drugs"); - }); - - modelBuilder.Entity("VeterinaryDatabaseImplement.Models.DrugMedication", b => - { - b.Property("Id") - .ValueGeneratedOnAdd() - .HasColumnType("int"); - - SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); - - b.Property("Count") - .HasColumnType("int"); - - b.Property("DrugId") - .HasColumnType("int"); - - b.Property("MedicationId") - .HasColumnType("int"); - - b.HasKey("Id"); - - b.HasIndex("DrugId"); - - b.HasIndex("MedicationId"); - - b.ToTable("DrugMedications"); - }); - - modelBuilder.Entity("VeterinaryDatabaseImplement.Models.Medication", b => - { - b.Property("Id") - .ValueGeneratedOnAdd() - .HasColumnType("int"); - - SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); - - b.Property("DoctorId") - .HasColumnType("int"); - - b.Property("MedicationName") - .IsRequired() - .HasColumnType("nvarchar(max)"); - - b.Property("Price") - .HasColumnType("float"); - - b.HasKey("Id"); - - b.HasIndex("DoctorId"); - - b.ToTable("Medications"); - }); - - modelBuilder.Entity("VeterinaryDatabaseImplement.Models.Owner", b => - { - b.Property("Id") - .ValueGeneratedOnAdd() - .HasColumnType("int"); - - SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); - - b.Property("Login") - .IsRequired() - .HasColumnType("nvarchar(max)"); - - b.Property("OwnerFIO") - .IsRequired() - .HasColumnType("nvarchar(max)"); - - b.Property("Password") - .IsRequired() - .HasColumnType("nvarchar(max)"); - - b.HasKey("Id"); - - b.ToTable("Owners"); - }); - - modelBuilder.Entity("VeterinaryDatabaseImplement.Models.Pet", b => - { - b.Property("Id") - .ValueGeneratedOnAdd() - .HasColumnType("int"); - - SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); - - b.Property("OwnerId") - .HasColumnType("int"); - - b.Property("PetBreed") - .IsRequired() - .HasColumnType("nvarchar(max)"); - - b.Property("PetGender") - .IsRequired() - .HasColumnType("nvarchar(max)"); - - b.Property("PetName") - .IsRequired() - .HasColumnType("nvarchar(max)"); - - b.Property("PetType") - .IsRequired() - .HasColumnType("nvarchar(max)"); - - b.HasKey("Id"); - - b.HasIndex("OwnerId"); - - b.ToTable("Pets"); - }); - - modelBuilder.Entity("VeterinaryDatabaseImplement.Models.Purchase", b => - { - b.Property("Id") - .ValueGeneratedOnAdd() - .HasColumnType("int"); - - SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); - - b.Property("Count") - .HasColumnType("int"); - - b.Property("DatePurchase") - .HasColumnType("datetime2"); - - b.Property("DrugId") - .HasColumnType("int"); - - b.Property("OwnerId") - .HasColumnType("int"); - - b.Property("Sum") - .HasColumnType("float"); - - b.HasKey("Id"); - - b.HasIndex("DrugId"); - - b.HasIndex("OwnerId"); - - b.ToTable("Purchases"); - }); - - modelBuilder.Entity("VeterinaryDatabaseImplement.Models.PurchasePet", b => - { - b.Property("Id") - .ValueGeneratedOnAdd() - .HasColumnType("int"); - - SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); - - b.Property("PetId") - .HasColumnType("int"); - - b.Property("PurchaseId") - .HasColumnType("int"); - - b.HasKey("Id"); - - b.HasIndex("PetId"); - - b.HasIndex("PurchaseId"); - - b.ToTable("PurchasePets"); - }); - - modelBuilder.Entity("VeterinaryDatabaseImplement.Models.Service", b => - { - b.Property("Id") - .ValueGeneratedOnAdd() - .HasColumnType("int"); - - SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); - - b.Property("DoctorId") - .HasColumnType("int"); - - b.Property("ServiceName") - .IsRequired() - .HasColumnType("nvarchar(max)"); - - b.Property("VisitId") - .HasColumnType("int"); - - b.HasKey("Id"); - - b.HasIndex("DoctorId"); - - b.HasIndex("VisitId"); - - b.ToTable("Services"); - }); - - modelBuilder.Entity("VeterinaryDatabaseImplement.Models.ServiceMedication", b => - { - b.Property("Id") - .ValueGeneratedOnAdd() - .HasColumnType("int"); - - SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); - - b.Property("Count") - .HasColumnType("int"); - - b.Property("MedicationId") - .HasColumnType("int"); - - b.Property("ServiceId") - .HasColumnType("int"); - - b.HasKey("Id"); - - b.HasIndex("MedicationId"); - - b.HasIndex("ServiceId"); - - b.ToTable("ServiceMedications"); - }); - - modelBuilder.Entity("VeterinaryDatabaseImplement.Models.Visit", b => - { - b.Property("Id") - .ValueGeneratedOnAdd() - .HasColumnType("int"); - - SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); - - b.Property("DateVisit") - .HasColumnType("datetime2"); - - b.Property("DoctorId") - .IsRequired() - .HasColumnType("int"); - - b.Property("OwnerId") - .HasColumnType("int"); - - b.HasKey("Id"); - - b.HasIndex("DoctorId"); - - b.HasIndex("OwnerId"); - - b.ToTable("Visits"); - }); - - modelBuilder.Entity("VeterinaryDatabaseImplement.Models.VisitPet", b => - { - b.Property("Id") - .ValueGeneratedOnAdd() - .HasColumnType("int"); - - SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); - - b.Property("PetId") - .HasColumnType("int"); - - b.Property("VisitId") - .HasColumnType("int"); - - b.HasKey("Id"); - - b.HasIndex("PetId"); - - b.HasIndex("VisitId"); - - b.ToTable("VisitPets"); - }); - - modelBuilder.Entity("VeterinaryDatabaseImplement.Models.DrugMedication", b => - { - b.HasOne("VeterinaryDatabaseImplement.Models.Drug", "Drug") - .WithMany("Medications") - .HasForeignKey("DrugId") - .OnDelete(DeleteBehavior.Cascade) - .IsRequired(); - - b.HasOne("VeterinaryDatabaseImplement.Models.Medication", "Medication") - .WithMany("DrugMedications") - .HasForeignKey("MedicationId") - .OnDelete(DeleteBehavior.Cascade) - .IsRequired(); - - b.Navigation("Drug"); - - b.Navigation("Medication"); - }); - - modelBuilder.Entity("VeterinaryDatabaseImplement.Models.Medication", b => - { - b.HasOne("VeterinaryDatabaseImplement.Models.Doctor", null) - .WithMany("Medications") - .HasForeignKey("DoctorId") - .OnDelete(DeleteBehavior.Cascade) - .IsRequired(); - }); - - modelBuilder.Entity("VeterinaryDatabaseImplement.Models.Pet", b => - { - b.HasOne("VeterinaryDatabaseImplement.Models.Owner", null) - .WithMany("Pets") - .HasForeignKey("OwnerId") - .OnDelete(DeleteBehavior.Cascade) - .IsRequired(); - }); - - modelBuilder.Entity("VeterinaryDatabaseImplement.Models.Purchase", b => - { - b.HasOne("VeterinaryDatabaseImplement.Models.Drug", "Drug") - .WithMany("Purchases") - .HasForeignKey("DrugId") - .OnDelete(DeleteBehavior.Cascade) - .IsRequired(); - - b.HasOne("VeterinaryDatabaseImplement.Models.Owner", "Owner") - .WithMany("Purchases") - .HasForeignKey("OwnerId") - .OnDelete(DeleteBehavior.Cascade) - .IsRequired(); - - b.Navigation("Drug"); - - b.Navigation("Owner"); - }); - - modelBuilder.Entity("VeterinaryDatabaseImplement.Models.PurchasePet", b => - { - b.HasOne("VeterinaryDatabaseImplement.Models.Pet", "Pet") - .WithMany("PurchasePets") - .HasForeignKey("PetId") - .OnDelete(DeleteBehavior.Cascade) - .IsRequired(); - - b.HasOne("VeterinaryDatabaseImplement.Models.Purchase", "Purchase") - .WithMany("Pets") - .HasForeignKey("PurchaseId") - .OnDelete(DeleteBehavior.Cascade) - .IsRequired(); - - b.Navigation("Pet"); - - b.Navigation("Purchase"); - }); - - modelBuilder.Entity("VeterinaryDatabaseImplement.Models.Service", b => - { - b.HasOne("VeterinaryDatabaseImplement.Models.Doctor", "Doctor") - .WithMany("Services") - .HasForeignKey("DoctorId") - .OnDelete(DeleteBehavior.Cascade) - .IsRequired(); - - b.HasOne("VeterinaryDatabaseImplement.Models.Visit", null) - .WithMany("Services") - .HasForeignKey("VisitId") - .OnDelete(DeleteBehavior.Cascade) - .IsRequired(); - - b.Navigation("Doctor"); - }); - - modelBuilder.Entity("VeterinaryDatabaseImplement.Models.ServiceMedication", b => - { - b.HasOne("VeterinaryDatabaseImplement.Models.Medication", "Medication") - .WithMany("ServiceMedications") - .HasForeignKey("MedicationId") - .OnDelete(DeleteBehavior.Cascade) - .IsRequired(); - - b.HasOne("VeterinaryDatabaseImplement.Models.Service", "Service") - .WithMany("Medications") - .HasForeignKey("ServiceId") - .OnDelete(DeleteBehavior.Cascade) - .IsRequired(); - - b.Navigation("Medication"); - - b.Navigation("Service"); - }); - - modelBuilder.Entity("VeterinaryDatabaseImplement.Models.Visit", b => - { - b.HasOne("VeterinaryDatabaseImplement.Models.Doctor", "Doctor") - .WithMany("Visits") - .HasForeignKey("DoctorId") - .OnDelete(DeleteBehavior.Cascade) - .IsRequired(); - - b.HasOne("VeterinaryDatabaseImplement.Models.Owner", "Owner") - .WithMany("Visits") - .HasForeignKey("OwnerId") - .OnDelete(DeleteBehavior.Cascade) - .IsRequired(); - - b.Navigation("Doctor"); - - b.Navigation("Owner"); - }); - - modelBuilder.Entity("VeterinaryDatabaseImplement.Models.VisitPet", b => - { - b.HasOne("VeterinaryDatabaseImplement.Models.Pet", "Pet") - .WithMany("VisitPets") - .HasForeignKey("PetId") - .OnDelete(DeleteBehavior.Cascade) - .IsRequired(); - - b.HasOne("VeterinaryDatabaseImplement.Models.Visit", "Visit") - .WithMany("Pets") - .HasForeignKey("VisitId") - .OnDelete(DeleteBehavior.Cascade) - .IsRequired(); - - b.Navigation("Pet"); - - b.Navigation("Visit"); - }); - - modelBuilder.Entity("VeterinaryDatabaseImplement.Models.Doctor", b => - { - b.Navigation("Medications"); - - b.Navigation("Services"); - - b.Navigation("Visits"); - }); - - modelBuilder.Entity("VeterinaryDatabaseImplement.Models.Drug", b => - { - b.Navigation("Medications"); - - b.Navigation("Purchases"); - }); - - modelBuilder.Entity("VeterinaryDatabaseImplement.Models.Medication", b => - { - b.Navigation("DrugMedications"); - - b.Navigation("ServiceMedications"); - }); - - modelBuilder.Entity("VeterinaryDatabaseImplement.Models.Owner", b => - { - b.Navigation("Pets"); - - b.Navigation("Purchases"); - - b.Navigation("Visits"); - }); - - modelBuilder.Entity("VeterinaryDatabaseImplement.Models.Pet", b => - { - b.Navigation("PurchasePets"); - - b.Navigation("VisitPets"); - }); - - modelBuilder.Entity("VeterinaryDatabaseImplement.Models.Purchase", b => - { - b.Navigation("Pets"); - }); - - modelBuilder.Entity("VeterinaryDatabaseImplement.Models.Service", b => - { - b.Navigation("Medications"); - }); - - modelBuilder.Entity("VeterinaryDatabaseImplement.Models.Visit", b => - { - b.Navigation("Pets"); - - b.Navigation("Services"); - }); -#pragma warning restore 612, 618 - } - } -} diff --git a/VeterinaryView/VeterinaryDatabaseImplement/Models/Drug.cs b/VeterinaryView/VeterinaryDatabaseImplement/Models/Drug.cs index faee98e..fc49d76 100644 --- a/VeterinaryView/VeterinaryDatabaseImplement/Models/Drug.cs +++ b/VeterinaryView/VeterinaryDatabaseImplement/Models/Drug.cs @@ -20,9 +20,9 @@ namespace VeterinaryDatabaseImplement.Models public double Price { get; set; } [Required] public int Count { get; set; } - private Dictionary? _drugMedications = null; + private Dictionary? _drugMedications = null; [NotMapped] - public Dictionary DrugMedications + public Dictionary DrugMedications { get { @@ -30,7 +30,7 @@ namespace VeterinaryDatabaseImplement.Models { _drugMedications = Medications .ToDictionary(recPC => recPC.MedicationId, recPC => - (recPC.Medication as IMedicationModel, recPC.Count)); + (recPC.Medication as IMedicationModel)); } return _drugMedications; } @@ -49,8 +49,7 @@ namespace VeterinaryDatabaseImplement.Models Count = model.Count, Medications = model.DrugMedications.Select(x => new DrugMedication { - Medication = context.Medications.First(y => y.Id == x.Key), - Count = x.Value.Item2 + Medication = context.Medications.First(y => y.Id == x.Key) }).ToList() }; } @@ -75,8 +74,6 @@ namespace VeterinaryDatabaseImplement.Models context.SaveChanges(); foreach (var updateMedication in drugMedications) { - updateMedication.Count = - model.DrugMedications[updateMedication.MedicationId].Item2; model.DrugMedications.Remove(updateMedication.MedicationId); } context.SaveChanges(); @@ -87,8 +84,7 @@ namespace VeterinaryDatabaseImplement.Models context.DrugMedications.Add(new DrugMedication { Drug = drug, - Medication = context.Medications.First(x => x.Id == pc.Key), - Count = pc.Value.Item2 + Medication = context.Medications.First(x => x.Id == pc.Key) }); context.SaveChanges(); } diff --git a/VeterinaryView/VeterinaryDatabaseImplement/Models/DrugMedication.cs b/VeterinaryView/VeterinaryDatabaseImplement/Models/DrugMedication.cs index bf2c99d..2b278fe 100644 --- a/VeterinaryView/VeterinaryDatabaseImplement/Models/DrugMedication.cs +++ b/VeterinaryView/VeterinaryDatabaseImplement/Models/DrugMedication.cs @@ -15,8 +15,6 @@ namespace VeterinaryDatabaseImplement.Models public int DrugId { get; set; } [Required] public int MedicationId { get; set; } - [Required] - public int Count { get; set; } public virtual Medication Medication { get; set; } = new(); public virtual Drug Drug { get; set; } = new(); } diff --git a/VeterinaryView/VeterinaryDatabaseImplement/Models/Service.cs b/VeterinaryView/VeterinaryDatabaseImplement/Models/Service.cs index 1e0b807..a95bc32 100644 --- a/VeterinaryView/VeterinaryDatabaseImplement/Models/Service.cs +++ b/VeterinaryView/VeterinaryDatabaseImplement/Models/Service.cs @@ -22,9 +22,9 @@ namespace VeterinaryDatabaseImplement.Models [Required] public int VisitId { get; private set; } public virtual Doctor? Doctor { get; private set; } - private Dictionary? _serviceMedications = null; + private Dictionary? _serviceMedications = null; [NotMapped] - public Dictionary ServiceMedications + public Dictionary ServiceMedications { get { @@ -32,7 +32,7 @@ namespace VeterinaryDatabaseImplement.Models { _serviceMedications = Medications .ToDictionary(recPC => recPC.MedicationId, recPC => - (recPC.Medication as IMedicationModel, recPC.Count)); + (recPC.Medication as IMedicationModel)); } return _serviceMedications; } @@ -49,8 +49,7 @@ namespace VeterinaryDatabaseImplement.Models VisitId = model.VisitId, Medications = model.ServiceMedications.Select(x => new ServiceMedication { - Medication = context.Medications.First(y => y.Id == x.Key), - Count = x.Value.Item2 + Medication = context.Medications.First(y => y.Id == x.Key) }).ToList() }; } @@ -76,8 +75,6 @@ namespace VeterinaryDatabaseImplement.Models context.SaveChanges(); foreach (var updateMedication in serviceMedications) { - updateMedication.Count = - model.ServiceMedications[updateMedication.MedicationId].Item2; model.ServiceMedications.Remove(updateMedication.MedicationId); } context.SaveChanges(); @@ -88,8 +85,7 @@ namespace VeterinaryDatabaseImplement.Models context.ServiceMedications.Add(new ServiceMedication { Service = service, - Medication = context.Medications.First(x => x.Id == pc.Key), - Count = pc.Value.Item2 + Medication = context.Medications.First(x => x.Id == pc.Key) }); context.SaveChanges(); } diff --git a/VeterinaryView/VeterinaryDatabaseImplement/Models/ServiceMedication.cs b/VeterinaryView/VeterinaryDatabaseImplement/Models/ServiceMedication.cs index 94f6f05..1f9070e 100644 --- a/VeterinaryView/VeterinaryDatabaseImplement/Models/ServiceMedication.cs +++ b/VeterinaryView/VeterinaryDatabaseImplement/Models/ServiceMedication.cs @@ -14,8 +14,6 @@ namespace VeterinaryDatabaseImplement.Models public int ServiceId { get; set; } [Required] public int MedicationId { get; set; } - [Required] - public int Count { get; set; } public virtual Medication Medication { get; set; } = new(); public virtual Service Service { get; set; } = new(); } diff --git a/VeterinaryView/VeterinaryRestApi/Controllers/DrugController.cs b/VeterinaryView/VeterinaryRestApi/Controllers/DrugController.cs index b02948b..3f24631 100644 --- a/VeterinaryView/VeterinaryRestApi/Controllers/DrugController.cs +++ b/VeterinaryView/VeterinaryRestApi/Controllers/DrugController.cs @@ -19,14 +19,14 @@ namespace VeterinaryRestApi.Controllers } [HttpGet] - public Tuple>>? GetDrug(int drugId) + public Tuple>? GetDrug(int drugId) { try { var elem = _drug.ReadElement(new DrugSearchModel { Id = drugId }); if (elem == null) return null; - return Tuple.Create(elem, elem.DrugMedications.Select(x => Tuple.Create(x.Value.Item1.MedicationName, x.Value.Item2)).ToList()); + return Tuple.Create(elem, elem.DrugMedications.Select(x => x.Value.MedicationName).ToList()); } catch (Exception ex) { diff --git a/VeterinaryView/VeterinaryRestApi/Controllers/ServiceController.cs b/VeterinaryView/VeterinaryRestApi/Controllers/ServiceController.cs index f9807ee..78405d9 100644 --- a/VeterinaryView/VeterinaryRestApi/Controllers/ServiceController.cs +++ b/VeterinaryView/VeterinaryRestApi/Controllers/ServiceController.cs @@ -19,14 +19,14 @@ namespace VeterinaryRestApi.Controllers } [HttpGet] - public Tuple>>? GetService(int serviceId) + public Tuple>? GetService(int serviceId) { try { var elem = _service.ReadElement(new ServiceSearchModel { Id = serviceId }); if (elem == null) return null; - return Tuple.Create(elem, elem.ServiceMedications.Select(x => Tuple.Create(x.Value.Item1.MedicationName, x.Value.Item2)).ToList()); + return Tuple.Create(elem, elem.ServiceMedications.Select(x => x.Value.MedicationName).ToList()); } catch (Exception ex) { diff --git a/VeterinaryView/VeterinaryShowDoctorApp/Controllers/HomeController.cs b/VeterinaryView/VeterinaryShowDoctorApp/Controllers/HomeController.cs index 5219ce1..4eb35bc 100644 --- a/VeterinaryView/VeterinaryShowDoctorApp/Controllers/HomeController.cs +++ b/VeterinaryView/VeterinaryShowDoctorApp/Controllers/HomeController.cs @@ -3,7 +3,10 @@ using System.Diagnostics; using VeterinaryShowDoctorApp.Models; using VeterinaryContracts.ViewModels; using VeterinaryContracts.BindingModels; - +using System.Text; +using VeterinaryDataModels; +using VeterinaryContracts.SearchModels; +using VeterinaryContracts.StorageContracts; namespace VeterinaryShowDoctorApp.Controllers { @@ -190,36 +193,147 @@ namespace VeterinaryShowDoctorApp.Controllers Response.Redirect("Index"); } + + public IActionResult Drugs() + { + if (APIDoctor.Doctor == null) + { + return Redirect("~/Home/Enter"); + } + return View(APIDoctor.GetRequest>($"api/drug/getdrugs?doctorid={APIDoctor.Doctor.Id}")); + + } + + public IActionResult CreateDrug() { if (APIDoctor.Doctor == null) { return Redirect("~/Home/Enter"); } + ViewBag.Medications = APIDoctor.GetRequest>($"api/medication/getmedications"); + return View(); } + + [HttpPost] - public void CreateDrug(string name, int price) + public void CreateDrug(string name, List medications, int count) { if (APIDoctor.Doctor == null) { throw new Exception("Вы как суда попали? Суда вход только авторизованным"); } - if (string.IsNullOrEmpty(name) || price <= 0) + double _price=0; + if (string.IsNullOrEmpty(name) || count <=0) { throw new Exception("Ошибка в введенных данных"); } - APIDoctor.PostRequest("api/medication/createmedication", new MedicationBindingModel + Dictionary a = new Dictionary(); + foreach (int medication in medications) { - MedicationName = name, - Price = price, - DoctorId = APIDoctor.Doctor.Id + a.Add(medication, new MedicationSearchModel { Id = medication } as IMedicationModel); + } + foreach (var elem in a) + { + _price += elem.Value.Price; + } + + APIDoctor.PostRequest("api/drug/createdrug", new DrugBindingModel + { + DrugName = name, + Price = Math.Round(_price, 2), + DrugMedications = a, + Count = count }); Response.Redirect("Index"); } + public IActionResult DeleteDrug() + { + if (APIDoctor.Doctor == null) + { + return Redirect("~/Home/Enter"); + } + ViewBag.Drugs = APIDoctor.GetRequest>($"api/drug/getdrugs?doctorid={APIDoctor.Doctor.Id}"); + return View(); + } + [HttpPost] + public void DeleteDrug(int drug) + { + if (APIDoctor.Doctor == null) + { + throw new Exception("Вы как суда попали? Суда вход только авторизованным"); + } + APIDoctor.PostRequest("api/drug/deletedrug", new DrugBindingModel + { + Id = drug + }); + Response.Redirect("Index"); + } + + public IActionResult UpdateDrug() + { + if (APIDoctor.Doctor == null) + { + return Redirect("~/Home/Enter"); + } + ViewBag.Drugs = APIDoctor.GetRequest>($"api/drug/getdrugs?doctorid={APIDoctor.Doctor.Id}"); + ViewBag.Medications = APIDoctor.GetRequest>($"api/medication/getmedications"); + return View(); + } + + [HttpPost] + public void UpdateDrug(int drug, string name, List medications, int count) + { + if (APIDoctor.Doctor == null) + { + throw new Exception("Вы как суда попали? Суда вход только авторизованным"); + } + double _price=0; + if (string.IsNullOrEmpty(name) || count <= 0) + { + throw new Exception("Ошибка в введенных данных"); + } + Dictionary a = new Dictionary(); + foreach (int medication in medications) + { + 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), + DrugMedications = a, + Count = count + }); + Response.Redirect("Index"); + } + + [HttpGet] + public Tuple>? GetDrug(int drugId) + { + if (APIDoctor.Doctor == null) + { + throw new Exception("Вы как суда попали? Суда вход только авторизованным"); + } + var result = APIDoctor.GetRequest>>($"api/drug/getdrug?drugid={drugId}"); + if (result == null) + { + return default; + } + + return result; + } + + [ResponseCache(Duration = 0, Location = ResponseCacheLocation.None, NoStore = true)] public IActionResult Error() diff --git a/VeterinaryView/VeterinaryShowDoctorApp/Views/Home/CreateDrug.cshtml b/VeterinaryView/VeterinaryShowDoctorApp/Views/Home/CreateDrug.cshtml new file mode 100644 index 0000000..32ab979 --- /dev/null +++ b/VeterinaryView/VeterinaryShowDoctorApp/Views/Home/CreateDrug.cshtml @@ -0,0 +1,44 @@ +@{ + ViewData["Title"] = "CreateDrug"; +} + +
+

Создание лекарства

+
+
+
+
Название:
+
+ +
+
+
+
Цена:
+
+ +
+
+
+
Количество:
+
+ +
+
+
+
Медикаменты:
+
+ +
+
+
+
+
+ +
+
+
diff --git a/VeterinaryView/VeterinaryShowDoctorApp/Views/Home/DeleteDrug.cshtml b/VeterinaryView/VeterinaryShowDoctorApp/Views/Home/DeleteDrug.cshtml new file mode 100644 index 0000000..109e10e --- /dev/null +++ b/VeterinaryView/VeterinaryShowDoctorApp/Views/Home/DeleteDrug.cshtml @@ -0,0 +1,18 @@ +@{ + ViewData["Title"] = "DeleteDrug"; +} +
+

Удаление лекарства

+
+
+
+
Лекарство:
+
+ +
+
+
+
+
+
+
s diff --git a/VeterinaryView/VeterinaryShowDoctorApp/Views/Home/Drugs.cshtml b/VeterinaryView/VeterinaryShowDoctorApp/Views/Home/Drugs.cshtml new file mode 100644 index 0000000..7ba8ff4 --- /dev/null +++ b/VeterinaryView/VeterinaryShowDoctorApp/Views/Home/Drugs.cshtml @@ -0,0 +1,53 @@ +@using VeterinaryContracts.ViewModels +@model List +@{ + ViewData["Title"] = "Drugs"; +} +
+

Лекарства

+
+
+ @{ + if (Model == null) + { +

Авторизируйтесь

+ return; + } +

+ Создать лекарство + Обновить лекарство + Удалить лекарство +

+ + + + + + + + + + @foreach (var item in Model) + { + + + + + + } + +
+ Номер + + Название + + Цена +
+ @Html.DisplayFor(modelItem =>item.Id) + + @Html.DisplayFor(modelItem =>item.DrugName) + + @Html.DisplayFor(modelItem =>item.Price) +
+ } +
diff --git a/VeterinaryView/VeterinaryShowDoctorApp/Views/Home/UpdateDrug.cshtml b/VeterinaryView/VeterinaryShowDoctorApp/Views/Home/UpdateDrug.cshtml new file mode 100644 index 0000000..be694a8 --- /dev/null +++ b/VeterinaryView/VeterinaryShowDoctorApp/Views/Home/UpdateDrug.cshtml @@ -0,0 +1,77 @@ +@using VeterinaryContracts.ViewModels; + +@{ + ViewData["Title"] = "UpdateDrug"; +} + +
+

Редактирование лекарства

+
+
+
+
Услуга:
+
+ +
+
+
+
Название:
+
+
+
+
Цена:
+
+
+
+
Количество:
+
+
+
+
+
Медикаменты:
+
+ +
+
+
+
+
+
+
+ +@section Scripts + { + +} diff --git a/VeterinaryView/VeterinaryShowDoctorApp/Views/Home/UpdateMedication.cshtml b/VeterinaryView/VeterinaryShowDoctorApp/Views/Home/UpdateMedication.cshtml index 2485c8c..0fa3c06 100644 --- a/VeterinaryView/VeterinaryShowDoctorApp/Views/Home/UpdateMedication.cshtml +++ b/VeterinaryView/VeterinaryShowDoctorApp/Views/Home/UpdateMedication.cshtml @@ -13,9 +13,6 @@
-
- -
Название:
@@ -26,17 +23,7 @@
- - - - - - - - -
- Животное -
+
@@ -56,7 +43,6 @@ success: function (result) { $('#name').val(result.item1.medicationName); $('#price').val(result.item1.price); - $('#table-elements').html(result.item2); } }); }; diff --git a/VeterinaryView/VeterinaryShowDoctorApp/Views/Shared/_Layout.cshtml b/VeterinaryView/VeterinaryShowDoctorApp/Views/Shared/_Layout.cshtml index 5b718f1..64ac521 100644 --- a/VeterinaryView/VeterinaryShowDoctorApp/Views/Shared/_Layout.cshtml +++ b/VeterinaryView/VeterinaryShowDoctorApp/Views/Shared/_Layout.cshtml @@ -31,6 +31,9 @@ +