This commit is contained in:
Yunusov_Niyaz 2024-04-30 01:49:52 +04:00
commit 4b15da7812
23 changed files with 371 additions and 1570 deletions

View File

@ -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<int, (IMedicationModel, int)> DrugMedications
public Dictionary<int, IMedicationModel> DrugMedications
{
get;
set;

View File

@ -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<int, (IMedicationModel, int)> ServiceMedications
public Dictionary<int, IMedicationModel> ServiceMedications
{
get;
set;

View File

@ -18,7 +18,7 @@ namespace VeterinaryContracts.ViewModels
[DisplayName("Цена лекарства")]
public double Price { get; set; }
public Dictionary<int, (IMedicationModel, int)> DrugMedications
public Dictionary<int, IMedicationModel> DrugMedications
{
get;
set;

View File

@ -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<int, (IMedicationModel, int)> ServiceMedications
public Dictionary<int, IMedicationModel> ServiceMedications
{
get;
set;

View File

@ -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<int, IMedicationModel> DrugMedications { get; }
}
}

View File

@ -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<int, IMedicationModel> ServiceMedications { get; }
}
}

View File

@ -25,13 +25,10 @@ namespace VeterinaryDatabaseImplement.Implements
}
public List<MedicationViewModel> 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();
}

View File

@ -1,551 +0,0 @@
// <auto-generated />
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
{
/// <inheritdoc />
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<int>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("int");
SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property<int>("Id"));
b.Property<string>("DoctorFIO")
.IsRequired()
.HasColumnType("nvarchar(max)");
b.Property<string>("Login")
.IsRequired()
.HasColumnType("nvarchar(max)");
b.Property<string>("Password")
.IsRequired()
.HasColumnType("nvarchar(max)");
b.HasKey("Id");
b.ToTable("Doctors");
});
modelBuilder.Entity("VeterinaryDatabaseImplement.Models.Drug", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("int");
SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property<int>("Id"));
b.Property<int>("Count")
.HasColumnType("int");
b.Property<string>("DrugName")
.IsRequired()
.HasColumnType("nvarchar(max)");
b.Property<double>("Price")
.HasColumnType("float");
b.HasKey("Id");
b.ToTable("Drugs");
});
modelBuilder.Entity("VeterinaryDatabaseImplement.Models.DrugMedication", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("int");
SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property<int>("Id"));
b.Property<int>("Count")
.HasColumnType("int");
b.Property<int>("DrugId")
.HasColumnType("int");
b.Property<int>("MedicationId")
.HasColumnType("int");
b.HasKey("Id");
b.HasIndex("DrugId");
b.HasIndex("MedicationId");
b.ToTable("DrugMedications");
});
modelBuilder.Entity("VeterinaryDatabaseImplement.Models.Medication", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("int");
SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property<int>("Id"));
b.Property<int>("DoctorId")
.HasColumnType("int");
b.Property<string>("MedicationName")
.IsRequired()
.HasColumnType("nvarchar(max)");
b.Property<double>("Price")
.HasColumnType("float");
b.HasKey("Id");
b.HasIndex("DoctorId");
b.ToTable("Medications");
});
modelBuilder.Entity("VeterinaryDatabaseImplement.Models.Owner", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("int");
SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property<int>("Id"));
b.Property<string>("Login")
.IsRequired()
.HasColumnType("nvarchar(max)");
b.Property<string>("OwnerFIO")
.IsRequired()
.HasColumnType("nvarchar(max)");
b.Property<string>("Password")
.IsRequired()
.HasColumnType("nvarchar(max)");
b.HasKey("Id");
b.ToTable("Owners");
});
modelBuilder.Entity("VeterinaryDatabaseImplement.Models.Pet", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("int");
SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property<int>("Id"));
b.Property<int>("OwnerId")
.HasColumnType("int");
b.Property<string>("PetBreed")
.IsRequired()
.HasColumnType("nvarchar(max)");
b.Property<string>("PetGender")
.IsRequired()
.HasColumnType("nvarchar(max)");
b.Property<string>("PetName")
.IsRequired()
.HasColumnType("nvarchar(max)");
b.Property<string>("PetType")
.IsRequired()
.HasColumnType("nvarchar(max)");
b.HasKey("Id");
b.HasIndex("OwnerId");
b.ToTable("Pets");
});
modelBuilder.Entity("VeterinaryDatabaseImplement.Models.Purchase", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("int");
SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property<int>("Id"));
b.Property<int>("Count")
.HasColumnType("int");
b.Property<DateTime>("DatePurchase")
.HasColumnType("datetime2");
b.Property<int>("DrugId")
.HasColumnType("int");
b.Property<int>("OwnerId")
.HasColumnType("int");
b.Property<double>("Sum")
.HasColumnType("float");
b.HasKey("Id");
b.HasIndex("DrugId");
b.HasIndex("OwnerId");
b.ToTable("Purchases");
});
modelBuilder.Entity("VeterinaryDatabaseImplement.Models.PurchasePet", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("int");
SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property<int>("Id"));
b.Property<int>("PetId")
.HasColumnType("int");
b.Property<int>("PurchaseId")
.HasColumnType("int");
b.HasKey("Id");
b.HasIndex("PetId");
b.HasIndex("PurchaseId");
b.ToTable("PurchasePets");
});
modelBuilder.Entity("VeterinaryDatabaseImplement.Models.Service", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("int");
SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property<int>("Id"));
b.Property<int>("DoctorId")
.HasColumnType("int");
b.Property<string>("ServiceName")
.IsRequired()
.HasColumnType("nvarchar(max)");
b.Property<int>("VisitId")
.HasColumnType("int");
b.HasKey("Id");
b.HasIndex("DoctorId");
b.HasIndex("VisitId");
b.ToTable("Services");
});
modelBuilder.Entity("VeterinaryDatabaseImplement.Models.ServiceMedication", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("int");
SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property<int>("Id"));
b.Property<int>("Count")
.HasColumnType("int");
b.Property<int>("MedicationId")
.HasColumnType("int");
b.Property<int>("ServiceId")
.HasColumnType("int");
b.HasKey("Id");
b.HasIndex("MedicationId");
b.HasIndex("ServiceId");
b.ToTable("ServiceMedications");
});
modelBuilder.Entity("VeterinaryDatabaseImplement.Models.Visit", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("int");
SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property<int>("Id"));
b.Property<DateTime>("DateVisit")
.HasColumnType("datetime2");
b.Property<int?>("DoctorId")
.IsRequired()
.HasColumnType("int");
b.Property<int>("OwnerId")
.HasColumnType("int");
b.HasKey("Id");
b.HasIndex("DoctorId");
b.HasIndex("OwnerId");
b.ToTable("Visits");
});
modelBuilder.Entity("VeterinaryDatabaseImplement.Models.VisitPet", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("int");
SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property<int>("Id"));
b.Property<int>("PetId")
.HasColumnType("int");
b.Property<int>("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
}
}
}

View File

@ -1,413 +0,0 @@
using System;
using Microsoft.EntityFrameworkCore.Migrations;
#nullable disable
namespace VeterinaryDatabaseImplement.Migrations
{
/// <inheritdoc />
public partial class InitialCreate : Migration
{
/// <inheritdoc />
protected override void Up(MigrationBuilder migrationBuilder)
{
migrationBuilder.CreateTable(
name: "Doctors",
columns: table => new
{
Id = table.Column<int>(type: "int", nullable: false)
.Annotation("SqlServer:Identity", "1, 1"),
DoctorFIO = table.Column<string>(type: "nvarchar(max)", nullable: false),
Login = table.Column<string>(type: "nvarchar(max)", nullable: false),
Password = table.Column<string>(type: "nvarchar(max)", nullable: false)
},
constraints: table =>
{
table.PrimaryKey("PK_Doctors", x => x.Id);
});
migrationBuilder.CreateTable(
name: "Drugs",
columns: table => new
{
Id = table.Column<int>(type: "int", nullable: false)
.Annotation("SqlServer:Identity", "1, 1"),
DrugName = table.Column<string>(type: "nvarchar(max)", nullable: false),
Price = table.Column<double>(type: "float", nullable: false),
Count = table.Column<int>(type: "int", nullable: false)
},
constraints: table =>
{
table.PrimaryKey("PK_Drugs", x => x.Id);
});
migrationBuilder.CreateTable(
name: "Owners",
columns: table => new
{
Id = table.Column<int>(type: "int", nullable: false)
.Annotation("SqlServer:Identity", "1, 1"),
OwnerFIO = table.Column<string>(type: "nvarchar(max)", nullable: false),
Login = table.Column<string>(type: "nvarchar(max)", nullable: false),
Password = table.Column<string>(type: "nvarchar(max)", nullable: false)
},
constraints: table =>
{
table.PrimaryKey("PK_Owners", x => x.Id);
});
migrationBuilder.CreateTable(
name: "Medications",
columns: table => new
{
Id = table.Column<int>(type: "int", nullable: false)
.Annotation("SqlServer:Identity", "1, 1"),
MedicationName = table.Column<string>(type: "nvarchar(max)", nullable: false),
Price = table.Column<double>(type: "float", nullable: false),
DoctorId = table.Column<int>(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<int>(type: "int", nullable: false)
.Annotation("SqlServer:Identity", "1, 1"),
OwnerId = table.Column<int>(type: "int", nullable: false),
PetName = table.Column<string>(type: "nvarchar(max)", nullable: false),
PetType = table.Column<string>(type: "nvarchar(max)", nullable: false),
PetBreed = table.Column<string>(type: "nvarchar(max)", nullable: false),
PetGender = table.Column<string>(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<int>(type: "int", nullable: false)
.Annotation("SqlServer:Identity", "1, 1"),
OwnerId = table.Column<int>(type: "int", nullable: false),
DrugId = table.Column<int>(type: "int", nullable: false),
Count = table.Column<int>(type: "int", nullable: false),
Sum = table.Column<double>(type: "float", nullable: false),
DatePurchase = table.Column<DateTime>(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<int>(type: "int", nullable: false)
.Annotation("SqlServer:Identity", "1, 1"),
OwnerId = table.Column<int>(type: "int", nullable: false),
DoctorId = table.Column<int>(type: "int", nullable: false),
DateVisit = table.Column<DateTime>(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<int>(type: "int", nullable: false)
.Annotation("SqlServer:Identity", "1, 1"),
DrugId = table.Column<int>(type: "int", nullable: false),
MedicationId = table.Column<int>(type: "int", nullable: false),
Count = table.Column<int>(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<int>(type: "int", nullable: false)
.Annotation("SqlServer:Identity", "1, 1"),
PurchaseId = table.Column<int>(type: "int", nullable: false),
PetId = table.Column<int>(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<int>(type: "int", nullable: false)
.Annotation("SqlServer:Identity", "1, 1"),
ServiceName = table.Column<string>(type: "nvarchar(max)", nullable: false),
DoctorId = table.Column<int>(type: "int", nullable: false),
VisitId = table.Column<int>(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<int>(type: "int", nullable: false)
.Annotation("SqlServer:Identity", "1, 1"),
VisitId = table.Column<int>(type: "int", nullable: false),
PetId = table.Column<int>(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<int>(type: "int", nullable: false)
.Annotation("SqlServer:Identity", "1, 1"),
ServiceId = table.Column<int>(type: "int", nullable: false),
MedicationId = table.Column<int>(type: "int", nullable: false),
Count = table.Column<int>(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");
}
/// <inheritdoc />
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");
}
}
}

View File

@ -1,548 +0,0 @@
// <auto-generated />
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<int>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("int");
SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property<int>("Id"));
b.Property<string>("DoctorFIO")
.IsRequired()
.HasColumnType("nvarchar(max)");
b.Property<string>("Login")
.IsRequired()
.HasColumnType("nvarchar(max)");
b.Property<string>("Password")
.IsRequired()
.HasColumnType("nvarchar(max)");
b.HasKey("Id");
b.ToTable("Doctors");
});
modelBuilder.Entity("VeterinaryDatabaseImplement.Models.Drug", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("int");
SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property<int>("Id"));
b.Property<int>("Count")
.HasColumnType("int");
b.Property<string>("DrugName")
.IsRequired()
.HasColumnType("nvarchar(max)");
b.Property<double>("Price")
.HasColumnType("float");
b.HasKey("Id");
b.ToTable("Drugs");
});
modelBuilder.Entity("VeterinaryDatabaseImplement.Models.DrugMedication", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("int");
SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property<int>("Id"));
b.Property<int>("Count")
.HasColumnType("int");
b.Property<int>("DrugId")
.HasColumnType("int");
b.Property<int>("MedicationId")
.HasColumnType("int");
b.HasKey("Id");
b.HasIndex("DrugId");
b.HasIndex("MedicationId");
b.ToTable("DrugMedications");
});
modelBuilder.Entity("VeterinaryDatabaseImplement.Models.Medication", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("int");
SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property<int>("Id"));
b.Property<int>("DoctorId")
.HasColumnType("int");
b.Property<string>("MedicationName")
.IsRequired()
.HasColumnType("nvarchar(max)");
b.Property<double>("Price")
.HasColumnType("float");
b.HasKey("Id");
b.HasIndex("DoctorId");
b.ToTable("Medications");
});
modelBuilder.Entity("VeterinaryDatabaseImplement.Models.Owner", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("int");
SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property<int>("Id"));
b.Property<string>("Login")
.IsRequired()
.HasColumnType("nvarchar(max)");
b.Property<string>("OwnerFIO")
.IsRequired()
.HasColumnType("nvarchar(max)");
b.Property<string>("Password")
.IsRequired()
.HasColumnType("nvarchar(max)");
b.HasKey("Id");
b.ToTable("Owners");
});
modelBuilder.Entity("VeterinaryDatabaseImplement.Models.Pet", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("int");
SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property<int>("Id"));
b.Property<int>("OwnerId")
.HasColumnType("int");
b.Property<string>("PetBreed")
.IsRequired()
.HasColumnType("nvarchar(max)");
b.Property<string>("PetGender")
.IsRequired()
.HasColumnType("nvarchar(max)");
b.Property<string>("PetName")
.IsRequired()
.HasColumnType("nvarchar(max)");
b.Property<string>("PetType")
.IsRequired()
.HasColumnType("nvarchar(max)");
b.HasKey("Id");
b.HasIndex("OwnerId");
b.ToTable("Pets");
});
modelBuilder.Entity("VeterinaryDatabaseImplement.Models.Purchase", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("int");
SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property<int>("Id"));
b.Property<int>("Count")
.HasColumnType("int");
b.Property<DateTime>("DatePurchase")
.HasColumnType("datetime2");
b.Property<int>("DrugId")
.HasColumnType("int");
b.Property<int>("OwnerId")
.HasColumnType("int");
b.Property<double>("Sum")
.HasColumnType("float");
b.HasKey("Id");
b.HasIndex("DrugId");
b.HasIndex("OwnerId");
b.ToTable("Purchases");
});
modelBuilder.Entity("VeterinaryDatabaseImplement.Models.PurchasePet", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("int");
SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property<int>("Id"));
b.Property<int>("PetId")
.HasColumnType("int");
b.Property<int>("PurchaseId")
.HasColumnType("int");
b.HasKey("Id");
b.HasIndex("PetId");
b.HasIndex("PurchaseId");
b.ToTable("PurchasePets");
});
modelBuilder.Entity("VeterinaryDatabaseImplement.Models.Service", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("int");
SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property<int>("Id"));
b.Property<int>("DoctorId")
.HasColumnType("int");
b.Property<string>("ServiceName")
.IsRequired()
.HasColumnType("nvarchar(max)");
b.Property<int>("VisitId")
.HasColumnType("int");
b.HasKey("Id");
b.HasIndex("DoctorId");
b.HasIndex("VisitId");
b.ToTable("Services");
});
modelBuilder.Entity("VeterinaryDatabaseImplement.Models.ServiceMedication", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("int");
SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property<int>("Id"));
b.Property<int>("Count")
.HasColumnType("int");
b.Property<int>("MedicationId")
.HasColumnType("int");
b.Property<int>("ServiceId")
.HasColumnType("int");
b.HasKey("Id");
b.HasIndex("MedicationId");
b.HasIndex("ServiceId");
b.ToTable("ServiceMedications");
});
modelBuilder.Entity("VeterinaryDatabaseImplement.Models.Visit", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("int");
SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property<int>("Id"));
b.Property<DateTime>("DateVisit")
.HasColumnType("datetime2");
b.Property<int?>("DoctorId")
.IsRequired()
.HasColumnType("int");
b.Property<int>("OwnerId")
.HasColumnType("int");
b.HasKey("Id");
b.HasIndex("DoctorId");
b.HasIndex("OwnerId");
b.ToTable("Visits");
});
modelBuilder.Entity("VeterinaryDatabaseImplement.Models.VisitPet", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("int");
SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property<int>("Id"));
b.Property<int>("PetId")
.HasColumnType("int");
b.Property<int>("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
}
}
}

View File

@ -20,9 +20,9 @@ namespace VeterinaryDatabaseImplement.Models
public double Price { get; set; }
[Required]
public int Count { get; set; }
private Dictionary<int, (IMedicationModel, int)>? _drugMedications = null;
private Dictionary<int, IMedicationModel>? _drugMedications = null;
[NotMapped]
public Dictionary<int, (IMedicationModel, int)> DrugMedications
public Dictionary<int, IMedicationModel> 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();
}

View File

@ -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();
}

View File

@ -22,9 +22,9 @@ namespace VeterinaryDatabaseImplement.Models
[Required]
public int VisitId { get; private set; }
public virtual Doctor? Doctor { get; private set; }
private Dictionary<int, (IMedicationModel, int)>? _serviceMedications = null;
private Dictionary<int, IMedicationModel>? _serviceMedications = null;
[NotMapped]
public Dictionary<int, (IMedicationModel, int)> ServiceMedications
public Dictionary<int, IMedicationModel> 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();
}

View File

@ -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();
}

View File

@ -19,14 +19,14 @@ namespace VeterinaryRestApi.Controllers
}
[HttpGet]
public Tuple<DrugViewModel, List<Tuple<string, int>>>? GetDrug(int drugId)
public Tuple<DrugViewModel, List<string>>? 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)
{

View File

@ -19,14 +19,14 @@ namespace VeterinaryRestApi.Controllers
}
[HttpGet]
public Tuple<ServiceViewModel, List<Tuple<string, int>>>? GetService(int serviceId)
public Tuple<ServiceViewModel, List<string>>? 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)
{

View File

@ -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<List<DrugViewModel>>($"api/drug/getdrugs?doctorid={APIDoctor.Doctor.Id}"));
}
public IActionResult CreateDrug()
{
if (APIDoctor.Doctor == null)
{
return Redirect("~/Home/Enter");
}
ViewBag.Medications = APIDoctor.GetRequest<List<MedicationViewModel>>($"api/medication/getmedications");
return View();
}
[HttpPost]
public void CreateDrug(string name, int price)
public void CreateDrug(string name, List<int> 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<int, IMedicationModel> a = new Dictionary<int, IMedicationModel>();
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<List<DrugViewModel>>($"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<List<DrugViewModel>>($"api/drug/getdrugs?doctorid={APIDoctor.Doctor.Id}");
ViewBag.Medications = APIDoctor.GetRequest<List<MedicationViewModel>>($"api/medication/getmedications");
return View();
}
[HttpPost]
public void UpdateDrug(int drug, string name, List<int> medications, int count)
{
if (APIDoctor.Doctor == null)
{
throw new Exception("Вы как суда попали? Суда вход только авторизованным");
}
double _price=0;
if (string.IsNullOrEmpty(name) || count <= 0)
{
throw new Exception("Ошибка в введенных данных");
}
Dictionary<int, IMedicationModel> a = new Dictionary<int, IMedicationModel>();
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<DrugViewModel, List<string>>? GetDrug(int drugId)
{
if (APIDoctor.Doctor == null)
{
throw new Exception("Вы как суда попали? Суда вход только авторизованным");
}
var result = APIDoctor.GetRequest<Tuple<DrugViewModel, List<string>>>($"api/drug/getdrug?drugid={drugId}");
if (result == null)
{
return default;
}
return result;
}
[ResponseCache(Duration = 0, Location = ResponseCacheLocation.None, NoStore = true)]
public IActionResult Error()

View File

@ -0,0 +1,44 @@
@{
ViewData["Title"] = "CreateDrug";
}
<div class="text-center">
<h2 class="display-4">Создание лекарства</h2>
</div>
<form method="post">
<div class="row">
<div class="col-4">Название:</div>
<div class="col-8">
<input type="text" name="name" id="name" />
</div>
</div>
<div class="row">
<div class="col-4">Цена:</div>
<div class="col-8">
<input type="text" name="price" id="price" />
</div>
</div>
<div class="row">
<div class="col-4">Количество:</div>
<div class="col-8">
<input type="number" name="count" id="count" />
</div>
</div>
<div class="row">
<div class="col-4">Медикаменты:</div>
<div class="col-8">
<select name="medications" class="form-control" multiple size="6" id="medications">
@foreach (var medication in ViewBag.Medications)
{
<option value="@medication.Id">@medication.MedicationName</option>
}
</select>
</div>
</div>
<div class="row">
<div class="col-8"></div>
<div class="col-4">
<input type="submit" value="Создать" class="btn btn-primary" />
</div>
</div>
</form>

View File

@ -0,0 +1,18 @@
@{
ViewData["Title"] = "DeleteDrug";
}
<div class="text-center">
<h2 class="display-4">Удаление лекарства</h2>
</div>
<form method="post">
<div class="row">
<div class="col-4">Лекарство:</div>
<div class="col-8">
<select id="drug" name="drug" class="form-control" asp-items="@(new SelectList(@ViewBag.Drugs, "Id", "DrugName"))"></select>
</div>
</div>
<div class="row">
<div class="col-4"></div>
<div class="col-8"><input type="submit" value="Удалить" class="btn btn-danger" /></div>
</div>
</form>s

View File

@ -0,0 +1,53 @@
@using VeterinaryContracts.ViewModels
@model List<DrugViewModel>
@{
ViewData["Title"] = "Drugs";
}
<div class="text-center">
<h1 class="display-4">Лекарства</h1>
</div>
<div class="text-center">
@{
if (Model == null)
{
<h3 class="display-4">Авторизируйтесь</h3>
return;
}
<p>
<a asp-action="CreateDrug">Создать лекарство</a>
<a asp-action="UpdateDrug">Обновить лекарство</a>
<a asp-action="DeleteDrug">Удалить лекарство</a>
</p>
<table class="table">
<thead>
<tr>
<th>
Номер
</th>
<th>
Название
</th>
<th>
Цена
</th>
</tr>
</thead>
<tbody>
@foreach (var item in Model)
{
<tr>
<td>
@Html.DisplayFor(modelItem =>item.Id)
</td>
<td>
@Html.DisplayFor(modelItem =>item.DrugName)
</td>
<td>
@Html.DisplayFor(modelItem =>item.Price)
</td>
</tr>
}
</tbody>
</table>
}
</div>

View File

@ -0,0 +1,77 @@
@using VeterinaryContracts.ViewModels;
@{
ViewData["Title"] = "UpdateDrug";
}
<div class="text-center">
<h2 class="display-4">Редактирование лекарства</h2>
</div>
<form method="post">
<div class="row">
<div class="col-4">Услуга:</div>
<div class="col-8">
<select id="drug" name="drug" class="form-control" asp-items="@(new SelectList(@ViewBag.Drugs, "Id", "DrugName"))"></select>
</div>
</div>
<div class="row">
<div class="col-4">Название:</div>
<div class="col-8"><input type="text" name="name" id="name" class="form-control" /></div>
</div>
<div class="row">
<div class="col-4">Цена:</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>
<div class="col-8"><input type="number" name="count" id="count" />
</div>
</div>
<div class="row">
<div class="col-4">Медикаменты:</div>
<div class="col-8">
<select name="medications" class="form-control" multiple size="5" id="medications">
@foreach (var medication in ViewBag.Medications)
{
<option value="@medication.Id" id="@medication.MedicationName">@medication.MedicationName</option>
}
</select>
</div>
</div>
<div class="row">
<div class="col-8"></div>
<div class="col-4"><input type="submit" value="Сохранить" class="btn btn-primary" /></div>
</div>
</form>
@section Scripts
{
<script>
function check() {
var drug = $('#drug').val();
$("#medications option:selected").removeAttr("selected");
if (drug) {
$.ajax({
method: "GET",
url: "/Home/GetDrug",
data: { drugId: drug },
success: function (result) {
console.log(result.item2);
$('#name').val(result.item1.drugName);
$('#price').val(result.item1.price);
$('#count').val(result.item1.count);
$.map(result.item2, function (n) {
console.log("#" + n);
$("#" + n).attr("selected", "selected")
});
}
});
};
}
check();
$('#drug').on('change', function () {
check();
});
</script>
}

View File

@ -13,9 +13,6 @@
<div class="col-8">
<select id="medication" name="medication" class="form-control" asp-items="@(new SelectList(@ViewBag.Medications, "Id", "MedicationName"))"></select>
</div>
<div class="col-8">
<select id="animal" name="animal" class="form-control" asp-items="@(new SelectList(@ViewBag.Animals, "Id", "AnimalName"))"></select>
</div>
</div>
<div class="row">
<div class="col-4">Название:</div>
@ -26,17 +23,7 @@
<div class="col-8"><input type="number" id="price" name="price" class="form-control" /></div>
</div>
<table class="table">
<thead>
<tr>
<th>
Животное
</th>
</tr>
</thead>
<tbody id="table-elements">
</tbody>
</table>
<div class="row">
<div class="col-8"></div>
<div class="col-4"><input type="submit" value="Сохранить" class="btn btn-primary" /></div>
@ -56,7 +43,6 @@
success: function (result) {
$('#name').val(result.item1.medicationName);
$('#price').val(result.item1.price);
$('#table-elements').html(result.item2);
}
});
};

View File

@ -31,6 +31,9 @@
<li class="nav-item">
<a class="nav-link text-dark" asparea="" asp-controller="Home" asp-action="Register">Регистрация</a>
</li>
<li class="nav-item">
<a class="nav-link text-dark" asparea="" asp-controller="Home" asp-action="Drugs">Лекарства</a>
</li>
</ul>
</div>
</div>