всякое говно

This commit is contained in:
antoc0der 2024-05-25 14:47:52 +04:00
parent e8cc602897
commit 66cf43a690
12 changed files with 140 additions and 81 deletions

View File

@ -89,10 +89,10 @@ namespace VeterinaryBusinessLogic.BusinessLogic
{
throw new ArgumentNullException("Цена заказа должна быть больше 0", nameof(model.Sum));
}
if (model.DateCreate <= DateTime.Now)
{
throw new ArgumentNullException("Дата покупки не должна быть в прошлом", nameof(model.DateCreate));
}
//if (model.DateCreate < DateTime.Now)
//{
// throw new ArgumentNullException("Дата покупки не должна быть в прошлом", nameof(model.DateCreate));
//}
if (model.Count <= 0)
{
throw new ArgumentNullException("Количество элементов в заказе должно быть больше 0", nameof(model.Count));

View File

@ -19,6 +19,6 @@ namespace VeterinaryContracts.BindingModels
set;
} = new();
public int DoctorId { get; set; }
public DateTime DateCreate { get; set; }
}
}

View File

@ -11,6 +11,6 @@ namespace VeterinaryContracts.SearchModels
public int? Id { get; set; }
public string? DrugName { get; set; }
public int? DoctorId { get; set; }
public DateTime? DateCreate { get; set; }
}
}

View File

@ -17,6 +17,8 @@ namespace VeterinaryContracts.ViewModels
public int Count { get; set; }
[DisplayName("Цена лекарства")]
public double Price { get; set; }
[DisplayName("Дата создания")]
public DateTime DateCreate { get; set; }
public Dictionary<int, IMedicationModel> DrugMedications
{

View File

@ -13,5 +13,6 @@ namespace VeterinaryDataModels.Models
double Price { get; }
Dictionary<int, IMedicationModel> DrugMedications { get; }
int DoctorId { get; }
DateTime DateCreate { get; }
}
}

View File

@ -31,7 +31,8 @@ namespace VeterinaryDatabaseImplement.Implements
using var context = new VeterinaryDatabase();
return context.Drugs.Where(x => x.DoctorId == model.DoctorId).Include(x => x.Medications)
.ThenInclude(x => x.Medication)
.Where(x => String.IsNullOrEmpty(model.DrugName) || x.DrugName.Contains(model.DrugName))
.Where(x => String.IsNullOrEmpty(model.DrugName) || x.DrugName.Contains(model.DrugName) &&
(!model.DateCreate.HasValue || x.DateCreate >= model.DateCreate))
.ToList()
.Select(x => x.GetViewModel)
.ToList();

View File

@ -12,7 +12,7 @@ using VeterinaryDatabaseImplement;
namespace VeterinaryDatabaseImplement.Migrations
{
[DbContext(typeof(VeterinaryDatabase))]
[Migration("20240523163748_InitialCreate")]
[Migration("20240525104527_InitialCreate")]
partial class InitialCreate
{
/// <inheritdoc />
@ -61,6 +61,9 @@ namespace VeterinaryDatabaseImplement.Migrations
b.Property<int>("Count")
.HasColumnType("int");
b.Property<DateTime>("DateCreate")
.HasColumnType("datetime2");
b.Property<int>("DoctorId")
.HasColumnType("int");
@ -73,6 +76,8 @@ namespace VeterinaryDatabaseImplement.Migrations
b.HasKey("Id");
b.HasIndex("DoctorId");
b.ToTable("Drugs");
});
@ -345,6 +350,15 @@ namespace VeterinaryDatabaseImplement.Migrations
b.ToTable("VisitPets");
});
modelBuilder.Entity("VeterinaryDatabaseImplement.Models.Drug", b =>
{
b.HasOne("VeterinaryDatabaseImplement.Models.Doctor", null)
.WithMany("Drugs")
.HasForeignKey("DoctorId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
});
modelBuilder.Entity("VeterinaryDatabaseImplement.Models.DrugMedication", b =>
{
b.HasOne("VeterinaryDatabaseImplement.Models.Drug", "Drug")
@ -500,6 +514,8 @@ namespace VeterinaryDatabaseImplement.Migrations
modelBuilder.Entity("VeterinaryDatabaseImplement.Models.Doctor", b =>
{
b.Navigation("Drugs");
b.Navigation("Medications");
b.Navigation("Services");

View File

@ -26,22 +26,6 @@ namespace VeterinaryDatabaseImplement.Migrations
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),
DoctorId = table.Column<int>(type: "int", nullable: false)
},
constraints: table =>
{
table.PrimaryKey("PK_Drugs", x => x.Id);
});
migrationBuilder.CreateTable(
name: "Owners",
columns: table => new
@ -57,6 +41,29 @@ namespace VeterinaryDatabaseImplement.Migrations
table.PrimaryKey("PK_Owners", x => x.Id);
});
migrationBuilder.CreateTable(
name: "Drugs",
columns: table => new
{
Id = table.Column<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),
DoctorId = table.Column<int>(type: "int", nullable: false),
DateCreate = table.Column<DateTime>(type: "datetime2", nullable: false)
},
constraints: table =>
{
table.PrimaryKey("PK_Drugs", x => x.Id);
table.ForeignKey(
name: "FK_Drugs_Doctors_DoctorId",
column: x => x.DoctorId,
principalTable: "Doctors",
principalColumn: "Id",
onDelete: ReferentialAction.Restrict);
});
migrationBuilder.CreateTable(
name: "Medications",
columns: table => new
@ -101,6 +108,34 @@ namespace VeterinaryDatabaseImplement.Migrations
onDelete: ReferentialAction.Restrict);
});
migrationBuilder.CreateTable(
name: "Visits",
columns: table => new
{
Id = table.Column<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),
VisitName = table.Column<string>(type: "nvarchar(max)", 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: "Purchases",
columns: table => new
@ -131,34 +166,6 @@ namespace VeterinaryDatabaseImplement.Migrations
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),
VisitName = table.Column<string>(type: "nvarchar(max)", 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
@ -185,32 +192,6 @@ namespace VeterinaryDatabaseImplement.Migrations
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
@ -264,6 +245,32 @@ namespace VeterinaryDatabaseImplement.Migrations
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: "ServiceMedications",
columns: table => new
@ -300,6 +307,11 @@ namespace VeterinaryDatabaseImplement.Migrations
table: "DrugMedications",
column: "MedicationId");
migrationBuilder.CreateIndex(
name: "IX_Drugs_DoctorId",
table: "Drugs",
column: "DoctorId");
migrationBuilder.CreateIndex(
name: "IX_Medications_DoctorId",
table: "Medications",

View File

@ -58,6 +58,9 @@ namespace VeterinaryDatabaseImplement.Migrations
b.Property<int>("Count")
.HasColumnType("int");
b.Property<DateTime>("DateCreate")
.HasColumnType("datetime2");
b.Property<int>("DoctorId")
.HasColumnType("int");
@ -70,6 +73,8 @@ namespace VeterinaryDatabaseImplement.Migrations
b.HasKey("Id");
b.HasIndex("DoctorId");
b.ToTable("Drugs");
});
@ -342,6 +347,15 @@ namespace VeterinaryDatabaseImplement.Migrations
b.ToTable("VisitPets");
});
modelBuilder.Entity("VeterinaryDatabaseImplement.Models.Drug", b =>
{
b.HasOne("VeterinaryDatabaseImplement.Models.Doctor", null)
.WithMany("Drugs")
.HasForeignKey("DoctorId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
});
modelBuilder.Entity("VeterinaryDatabaseImplement.Models.DrugMedication", b =>
{
b.HasOne("VeterinaryDatabaseImplement.Models.Drug", "Drug")
@ -497,6 +511,8 @@ namespace VeterinaryDatabaseImplement.Migrations
modelBuilder.Entity("VeterinaryDatabaseImplement.Models.Doctor", b =>
{
b.Navigation("Drugs");
b.Navigation("Medications");
b.Navigation("Services");

View File

@ -26,6 +26,8 @@ namespace VeterinaryDatabaseImplement.Models
public virtual List<Medication> Medications { get; set; } = new();
[ForeignKey("DoctorId")]
public virtual List<Visit> Visits { get; set; } = new();
[ForeignKey("DoctorId")]
public virtual List<Drug> Drugs { get; set; } = new();
public static Doctor? Create(DoctorBindingModel model)
{
if (model == null)

View File

@ -1,4 +1,5 @@
using System;
using Microsoft.EntityFrameworkCore.Storage;
using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using System.ComponentModel.DataAnnotations.Schema;
@ -23,6 +24,8 @@ namespace VeterinaryDatabaseImplement.Models
public int Count { get; set; }
[Required]
public int DoctorId { get; private set; }
[Required]
public DateTime DateCreate { get; private set; }
private Dictionary<int, IMedicationModel>? _drugMedications = null;
[NotMapped]
public Dictionary<int, IMedicationModel> DrugMedications
@ -62,6 +65,7 @@ namespace VeterinaryDatabaseImplement.Models
DoctorId = model.DoctorId,
Medications = justMedications,
Price = prc,
DateCreate= model.DateCreate
};
}
public void Update(DrugBindingModel model)
@ -76,6 +80,7 @@ namespace VeterinaryDatabaseImplement.Models
Price = Price,
Count= Count,
DoctorId=DoctorId,
DateCreate = DateCreate
};
public void UpdateMedications(VeterinaryDatabase context, DrugBindingModel model)
{

View File

@ -359,15 +359,19 @@ namespace VeterinaryShowOwnerApp.Controllers
OwnerId = APIOwner.Owner.Id,
DrugId = drug,
PurchasePet = a,
Sum = Calc(count, drug)
Sum = Calc(count, drug),
DateCreate = DateTime.Now,
Count = count
});
Response.Redirect("Index");
}
// с какого хера ты не работаешь
[HttpPost]
public double Calc(int count, int drug)
{
var dru = APIOwner.GetRequest<DrugViewModel>($"api/drug/getonedrug?drugId={drug}");
return count * (dru?.Price ?? 1);
//return count * (dru?.Price ?? 1);
return Math.Round(count * (dru?.Price ?? 1), 2);
}
[HttpGet]