From c92e3a3ee574788bc896970adaa306ab1444ab36 Mon Sep 17 00:00:00 2001 From: GokaPek Date: Mon, 25 Mar 2024 20:21:59 +0400 Subject: [PATCH 1/3] 2 --- .../AbstractLawFirmDataBase.cs | 27 +++ .../AbstractLawFirmDataBaseImplement.csproj | 27 +++ .../Implements/ComponentStorage.cs | 45 +++++ .../Implements/DocumentStorage.cs | 46 +++++ .../Implements/OrderStorage.cs | 45 +++++ .../20240325152423_InitialCreate.Designer.cs | 168 ++++++++++++++++++ .../20240325152423_InitialCreate.cs | 122 +++++++++++++ .../AbstractLawFirmDataBaseModelSnapshot.cs | 166 +++++++++++++++++ .../Models/Component.cs | 63 +++++++ .../Models/Document.cs | 97 ++++++++++ .../Models/DocumentComponent.cs | 24 +++ .../Models/Order.cs | 65 +++++++ .../DataFileSingleton.cs | 6 +- LawFirm/LawFirm.sln | 8 +- LawFirm/LawFirmView/LawFirmView.csproj | 5 + 15 files changed, 910 insertions(+), 4 deletions(-) create mode 100644 LawFirm/AbstractLawFirmDatabaseImplement/AbstractLawFirmDataBase.cs create mode 100644 LawFirm/AbstractLawFirmDatabaseImplement/AbstractLawFirmDataBaseImplement.csproj create mode 100644 LawFirm/AbstractLawFirmDatabaseImplement/Implements/ComponentStorage.cs create mode 100644 LawFirm/AbstractLawFirmDatabaseImplement/Implements/DocumentStorage.cs create mode 100644 LawFirm/AbstractLawFirmDatabaseImplement/Implements/OrderStorage.cs create mode 100644 LawFirm/AbstractLawFirmDatabaseImplement/Migrations/20240325152423_InitialCreate.Designer.cs create mode 100644 LawFirm/AbstractLawFirmDatabaseImplement/Migrations/20240325152423_InitialCreate.cs create mode 100644 LawFirm/AbstractLawFirmDatabaseImplement/Migrations/AbstractLawFirmDataBaseModelSnapshot.cs create mode 100644 LawFirm/AbstractLawFirmDatabaseImplement/Models/Component.cs create mode 100644 LawFirm/AbstractLawFirmDatabaseImplement/Models/Document.cs create mode 100644 LawFirm/AbstractLawFirmDatabaseImplement/Models/DocumentComponent.cs create mode 100644 LawFirm/AbstractLawFirmDatabaseImplement/Models/Order.cs diff --git a/LawFirm/AbstractLawFirmDatabaseImplement/AbstractLawFirmDataBase.cs b/LawFirm/AbstractLawFirmDatabaseImplement/AbstractLawFirmDataBase.cs new file mode 100644 index 0000000..df28dd3 --- /dev/null +++ b/LawFirm/AbstractLawFirmDatabaseImplement/AbstractLawFirmDataBase.cs @@ -0,0 +1,27 @@ +using AbstractLawFirmDataBaseImplement.Models; +using Microsoft.EntityFrameworkCore; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace AbstractLawFirmDataBaseImplement +{ + public class AbstractLawFirmDataBase : DbContext + { + protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder) + { + if (optionsBuilder.IsConfigured == false) + { + optionsBuilder.UseSqlServer(@"Data Source=GOKA\SQLEXPRESS;Initial Catalog=AbstractLawFirmDataBase Full;Integrated Security=True;MultipleActiveResultSets=True;;TrustServerCertificate=True"); + } + base.OnConfiguring(optionsBuilder); + } + public virtual DbSet Components { set; get; } + public virtual DbSet Documents { set; get; } + public virtual DbSet DocumentComponents { set; get; } + public virtual DbSet Orders { set; get; } + } + +} diff --git a/LawFirm/AbstractLawFirmDatabaseImplement/AbstractLawFirmDataBaseImplement.csproj b/LawFirm/AbstractLawFirmDatabaseImplement/AbstractLawFirmDataBaseImplement.csproj new file mode 100644 index 0000000..3c3080a --- /dev/null +++ b/LawFirm/AbstractLawFirmDatabaseImplement/AbstractLawFirmDataBaseImplement.csproj @@ -0,0 +1,27 @@ + + + + net6.0 + enable + enable + + + + + + all + runtime; build; native; contentfiles; analyzers; buildtransitive + + + + all + runtime; build; native; contentfiles; analyzers; buildtransitive + + + + + + + + + diff --git a/LawFirm/AbstractLawFirmDatabaseImplement/Implements/ComponentStorage.cs b/LawFirm/AbstractLawFirmDatabaseImplement/Implements/ComponentStorage.cs new file mode 100644 index 0000000..8b18364 --- /dev/null +++ b/LawFirm/AbstractLawFirmDatabaseImplement/Implements/ComponentStorage.cs @@ -0,0 +1,45 @@ +using AbstractLawFirmContracts.BindingModels.BindingModels; +using AbstractLawFirmContracts.SearchModels; +using AbstractLawFirmContracts.StoragesContracts; +using AbstractLawFirmContracts.ViewModels; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace AbstractLawFirmDatabaseImplement.Implements +{ + public class ComponentStorage : IComponentStorage + { + public ComponentViewModel? Delete(ComponentBindingModel model) + { + throw new NotImplementedException(); + } + + public ComponentViewModel? GetElement(ComponentSearchModel model) + { + throw new NotImplementedException(); + } + + public List GetFilteredList(ComponentSearchModel model) + { + throw new NotImplementedException(); + } + + public List GetFullList() + { + throw new NotImplementedException(); + } + + public ComponentViewModel? Insert(ComponentBindingModel model) + { + throw new NotImplementedException(); + } + + public ComponentViewModel? Update(ComponentBindingModel model) + { + throw new NotImplementedException(); + } + } +} diff --git a/LawFirm/AbstractLawFirmDatabaseImplement/Implements/DocumentStorage.cs b/LawFirm/AbstractLawFirmDatabaseImplement/Implements/DocumentStorage.cs new file mode 100644 index 0000000..4727a60 --- /dev/null +++ b/LawFirm/AbstractLawFirmDatabaseImplement/Implements/DocumentStorage.cs @@ -0,0 +1,46 @@ +using AbstractLawFirmContracts.BindingModels; +using AbstractLawFirmContracts.BindingModels.BindingModels; +using AbstractLawFirmContracts.SearchModels; +using AbstractLawFirmContracts.StoragesContracts; +using AbstractLawFirmContracts.ViewModels; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace AbstractLawFirmDatabaseImplement.Implements +{ + public class DocumentStorage : IDocumentStorage + { + public DocumentViewModel? Delete(DocumentBindingModel model) + { + throw new NotImplementedException(); + } + + public DocumentViewModel? GetElement(DocumentSearchModel model) + { + throw new NotImplementedException(); + } + + public List GetFilteredList(DocumentSearchModel model) + { + throw new NotImplementedException(); + } + + public List GetFullList() + { + throw new NotImplementedException(); + } + + public DocumentViewModel? Insert(DocumentBindingModel model) + { + throw new NotImplementedException(); + } + + public DocumentViewModel? Update(DocumentBindingModel model) + { + throw new NotImplementedException(); + } + } +} diff --git a/LawFirm/AbstractLawFirmDatabaseImplement/Implements/OrderStorage.cs b/LawFirm/AbstractLawFirmDatabaseImplement/Implements/OrderStorage.cs new file mode 100644 index 0000000..036e6fc --- /dev/null +++ b/LawFirm/AbstractLawFirmDatabaseImplement/Implements/OrderStorage.cs @@ -0,0 +1,45 @@ +using AbstractLawFirmContracts.BindingModels; +using AbstractLawFirmContracts.SearchModels; +using AbstractLawFirmContracts.ViewModels; +using AbstractLawFirmContracts.StoragesContracts; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace AbstractLawFirmDatabaseImplement.Implements +{ + public class OrderStorage : IOrderStorage + { + public OrderViewModel? Delete(OrderBindingModel model) + { + throw new NotImplementedException(); + } + + public OrderViewModel? GetElement(OrderSearchModel model) + { + throw new NotImplementedException(); + } + + public List GetFilteredList(OrderSearchModel model) + { + throw new NotImplementedException(); + } + + public List GetFullList() + { + throw new NotImplementedException(); + } + + public OrderViewModel? Insert(OrderBindingModel model) + { + throw new NotImplementedException(); + } + + public OrderViewModel? Update(OrderBindingModel model) + { + throw new NotImplementedException(); + } + } +} diff --git a/LawFirm/AbstractLawFirmDatabaseImplement/Migrations/20240325152423_InitialCreate.Designer.cs b/LawFirm/AbstractLawFirmDatabaseImplement/Migrations/20240325152423_InitialCreate.Designer.cs new file mode 100644 index 0000000..14fd17b --- /dev/null +++ b/LawFirm/AbstractLawFirmDatabaseImplement/Migrations/20240325152423_InitialCreate.Designer.cs @@ -0,0 +1,168 @@ +// +using System; +using AbstractLawFirmDataBaseImplement; +using Microsoft.EntityFrameworkCore; +using Microsoft.EntityFrameworkCore.Infrastructure; +using Microsoft.EntityFrameworkCore.Metadata; +using Microsoft.EntityFrameworkCore.Migrations; +using Microsoft.EntityFrameworkCore.Storage.ValueConversion; + +#nullable disable + +namespace AbstractLawFirmDatabaseImplement.Migrations +{ + [DbContext(typeof(AbstractLawFirmDataBase))] + [Migration("20240325152423_InitialCreate")] + partial class InitialCreate + { + protected override void BuildTargetModel(ModelBuilder modelBuilder) + { +#pragma warning disable 612, 618 + modelBuilder + .HasAnnotation("ProductVersion", "6.0.28") + .HasAnnotation("Relational:MaxIdentifierLength", 128); + + SqlServerModelBuilderExtensions.UseIdentityColumns(modelBuilder, 1L, 1); + + modelBuilder.Entity("AbstractLawFirmDataBaseImplement.Models.Component", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("int"); + + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id"), 1L, 1); + + b.Property("ComponentName") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.Property("Cost") + .HasColumnType("float"); + + b.HasKey("Id"); + + b.ToTable("Components"); + }); + + modelBuilder.Entity("AbstractLawFirmDataBaseImplement.Models.Document", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("int"); + + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id"), 1L, 1); + + b.Property("DocumentName") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.Property("Price") + .HasColumnType("float"); + + b.HasKey("Id"); + + b.ToTable("Documents"); + }); + + modelBuilder.Entity("AbstractLawFirmDataBaseImplement.Models.DocumentComponent", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("int"); + + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id"), 1L, 1); + + b.Property("ComponentId") + .HasColumnType("int"); + + b.Property("Count") + .HasColumnType("int"); + + b.Property("DocumentId") + .HasColumnType("int"); + + b.HasKey("Id"); + + b.HasIndex("ComponentId"); + + b.HasIndex("DocumentId"); + + b.ToTable("DocumentComponents"); + }); + + modelBuilder.Entity("AbstractLawFirmDataBaseImplement.Models.Order", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("int"); + + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id"), 1L, 1); + + b.Property("Count") + .HasColumnType("int"); + + b.Property("DateCreate") + .HasColumnType("datetime2"); + + b.Property("DateImplement") + .HasColumnType("datetime2"); + + b.Property("DocumentId") + .HasColumnType("int"); + + b.Property("Status") + .HasColumnType("int"); + + b.Property("Sum") + .HasColumnType("float"); + + b.HasKey("Id"); + + b.HasIndex("DocumentId"); + + b.ToTable("Orders"); + }); + + modelBuilder.Entity("AbstractLawFirmDataBaseImplement.Models.DocumentComponent", b => + { + b.HasOne("AbstractLawFirmDataBaseImplement.Models.Component", "Component") + .WithMany("DocumentComponents") + .HasForeignKey("ComponentId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.HasOne("AbstractLawFirmDataBaseImplement.Models.Document", "Document") + .WithMany("Components") + .HasForeignKey("DocumentId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.Navigation("Component"); + + b.Navigation("Document"); + }); + + modelBuilder.Entity("AbstractLawFirmDataBaseImplement.Models.Order", b => + { + b.HasOne("AbstractLawFirmDataBaseImplement.Models.Document", null) + .WithMany("Orders") + .HasForeignKey("DocumentId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + }); + + modelBuilder.Entity("AbstractLawFirmDataBaseImplement.Models.Component", b => + { + b.Navigation("DocumentComponents"); + }); + + modelBuilder.Entity("AbstractLawFirmDataBaseImplement.Models.Document", b => + { + b.Navigation("Components"); + + b.Navigation("Orders"); + }); +#pragma warning restore 612, 618 + } + } +} diff --git a/LawFirm/AbstractLawFirmDatabaseImplement/Migrations/20240325152423_InitialCreate.cs b/LawFirm/AbstractLawFirmDatabaseImplement/Migrations/20240325152423_InitialCreate.cs new file mode 100644 index 0000000..e26ca5e --- /dev/null +++ b/LawFirm/AbstractLawFirmDatabaseImplement/Migrations/20240325152423_InitialCreate.cs @@ -0,0 +1,122 @@ +using System; +using Microsoft.EntityFrameworkCore.Migrations; + +#nullable disable + +namespace AbstractLawFirmDatabaseImplement.Migrations +{ + public partial class InitialCreate : Migration + { + protected override void Up(MigrationBuilder migrationBuilder) + { + migrationBuilder.CreateTable( + name: "Components", + columns: table => new + { + Id = table.Column(type: "int", nullable: false) + .Annotation("SqlServer:Identity", "1, 1"), + ComponentName = table.Column(type: "nvarchar(max)", nullable: false), + Cost = table.Column(type: "float", nullable: false) + }, + constraints: table => + { + table.PrimaryKey("PK_Components", x => x.Id); + }); + + migrationBuilder.CreateTable( + name: "Documents", + columns: table => new + { + Id = table.Column(type: "int", nullable: false) + .Annotation("SqlServer:Identity", "1, 1"), + DocumentName = table.Column(type: "nvarchar(max)", nullable: false), + Price = table.Column(type: "float", nullable: false) + }, + constraints: table => + { + table.PrimaryKey("PK_Documents", x => x.Id); + }); + + migrationBuilder.CreateTable( + name: "DocumentComponents", + columns: table => new + { + Id = table.Column(type: "int", nullable: false) + .Annotation("SqlServer:Identity", "1, 1"), + DocumentId = table.Column(type: "int", nullable: false), + ComponentId = table.Column(type: "int", nullable: false), + Count = table.Column(type: "int", nullable: false) + }, + constraints: table => + { + table.PrimaryKey("PK_DocumentComponents", x => x.Id); + table.ForeignKey( + name: "FK_DocumentComponents_Components_ComponentId", + column: x => x.ComponentId, + principalTable: "Components", + principalColumn: "Id", + onDelete: ReferentialAction.Cascade); + table.ForeignKey( + name: "FK_DocumentComponents_Documents_DocumentId", + column: x => x.DocumentId, + principalTable: "Documents", + principalColumn: "Id", + onDelete: ReferentialAction.Cascade); + }); + + migrationBuilder.CreateTable( + name: "Orders", + columns: table => new + { + Id = table.Column(type: "int", nullable: false) + .Annotation("SqlServer:Identity", "1, 1"), + DocumentId = table.Column(type: "int", nullable: false), + Count = table.Column(type: "int", nullable: false), + Sum = table.Column(type: "float", nullable: false), + Status = table.Column(type: "int", nullable: false), + DateCreate = table.Column(type: "datetime2", nullable: false), + DateImplement = table.Column(type: "datetime2", nullable: true) + }, + constraints: table => + { + table.PrimaryKey("PK_Orders", x => x.Id); + table.ForeignKey( + name: "FK_Orders_Documents_DocumentId", + column: x => x.DocumentId, + principalTable: "Documents", + principalColumn: "Id", + onDelete: ReferentialAction.Cascade); + }); + + migrationBuilder.CreateIndex( + name: "IX_DocumentComponents_ComponentId", + table: "DocumentComponents", + column: "ComponentId"); + + migrationBuilder.CreateIndex( + name: "IX_DocumentComponents_DocumentId", + table: "DocumentComponents", + column: "DocumentId"); + + migrationBuilder.CreateIndex( + name: "IX_Orders_DocumentId", + table: "Orders", + column: "DocumentId"); + } + + protected override void Down(MigrationBuilder migrationBuilder) + { + migrationBuilder.DropTable( + name: "DocumentComponents"); + + migrationBuilder.DropTable( + name: "Orders"); + + migrationBuilder.DropTable( + name: "Components"); + + migrationBuilder.DropTable( + name: "Documents"); + } + } +} diff --git a/LawFirm/AbstractLawFirmDatabaseImplement/Migrations/AbstractLawFirmDataBaseModelSnapshot.cs b/LawFirm/AbstractLawFirmDatabaseImplement/Migrations/AbstractLawFirmDataBaseModelSnapshot.cs new file mode 100644 index 0000000..c6d34ab --- /dev/null +++ b/LawFirm/AbstractLawFirmDatabaseImplement/Migrations/AbstractLawFirmDataBaseModelSnapshot.cs @@ -0,0 +1,166 @@ +// +using System; +using AbstractLawFirmDataBaseImplement; +using Microsoft.EntityFrameworkCore; +using Microsoft.EntityFrameworkCore.Infrastructure; +using Microsoft.EntityFrameworkCore.Metadata; +using Microsoft.EntityFrameworkCore.Storage.ValueConversion; + +#nullable disable + +namespace AbstractLawFirmDatabaseImplement.Migrations +{ + [DbContext(typeof(AbstractLawFirmDataBase))] + partial class AbstractLawFirmDataBaseModelSnapshot : ModelSnapshot + { + protected override void BuildModel(ModelBuilder modelBuilder) + { +#pragma warning disable 612, 618 + modelBuilder + .HasAnnotation("ProductVersion", "6.0.28") + .HasAnnotation("Relational:MaxIdentifierLength", 128); + + SqlServerModelBuilderExtensions.UseIdentityColumns(modelBuilder, 1L, 1); + + modelBuilder.Entity("AbstractLawFirmDataBaseImplement.Models.Component", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("int"); + + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id"), 1L, 1); + + b.Property("ComponentName") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.Property("Cost") + .HasColumnType("float"); + + b.HasKey("Id"); + + b.ToTable("Components"); + }); + + modelBuilder.Entity("AbstractLawFirmDataBaseImplement.Models.Document", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("int"); + + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id"), 1L, 1); + + b.Property("DocumentName") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.Property("Price") + .HasColumnType("float"); + + b.HasKey("Id"); + + b.ToTable("Documents"); + }); + + modelBuilder.Entity("AbstractLawFirmDataBaseImplement.Models.DocumentComponent", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("int"); + + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id"), 1L, 1); + + b.Property("ComponentId") + .HasColumnType("int"); + + b.Property("Count") + .HasColumnType("int"); + + b.Property("DocumentId") + .HasColumnType("int"); + + b.HasKey("Id"); + + b.HasIndex("ComponentId"); + + b.HasIndex("DocumentId"); + + b.ToTable("DocumentComponents"); + }); + + modelBuilder.Entity("AbstractLawFirmDataBaseImplement.Models.Order", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("int"); + + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id"), 1L, 1); + + b.Property("Count") + .HasColumnType("int"); + + b.Property("DateCreate") + .HasColumnType("datetime2"); + + b.Property("DateImplement") + .HasColumnType("datetime2"); + + b.Property("DocumentId") + .HasColumnType("int"); + + b.Property("Status") + .HasColumnType("int"); + + b.Property("Sum") + .HasColumnType("float"); + + b.HasKey("Id"); + + b.HasIndex("DocumentId"); + + b.ToTable("Orders"); + }); + + modelBuilder.Entity("AbstractLawFirmDataBaseImplement.Models.DocumentComponent", b => + { + b.HasOne("AbstractLawFirmDataBaseImplement.Models.Component", "Component") + .WithMany("DocumentComponents") + .HasForeignKey("ComponentId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.HasOne("AbstractLawFirmDataBaseImplement.Models.Document", "Document") + .WithMany("Components") + .HasForeignKey("DocumentId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.Navigation("Component"); + + b.Navigation("Document"); + }); + + modelBuilder.Entity("AbstractLawFirmDataBaseImplement.Models.Order", b => + { + b.HasOne("AbstractLawFirmDataBaseImplement.Models.Document", null) + .WithMany("Orders") + .HasForeignKey("DocumentId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + }); + + modelBuilder.Entity("AbstractLawFirmDataBaseImplement.Models.Component", b => + { + b.Navigation("DocumentComponents"); + }); + + modelBuilder.Entity("AbstractLawFirmDataBaseImplement.Models.Document", b => + { + b.Navigation("Components"); + + b.Navigation("Orders"); + }); +#pragma warning restore 612, 618 + } + } +} diff --git a/LawFirm/AbstractLawFirmDatabaseImplement/Models/Component.cs b/LawFirm/AbstractLawFirmDatabaseImplement/Models/Component.cs new file mode 100644 index 0000000..c1edd27 --- /dev/null +++ b/LawFirm/AbstractLawFirmDatabaseImplement/Models/Component.cs @@ -0,0 +1,63 @@ +using AbstractLawFirmContracts.BindingModels.BindingModels; +using AbstractLawFirmContracts.ViewModels; +using AbstractLawFirmDataModels.Models; +using System; +using System.Collections.Generic; +using System.ComponentModel.DataAnnotations.Schema; +using System.ComponentModel.DataAnnotations; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using AbstractLawFirmDataBaseImplement.Models; + +namespace AbstractLawFirmDataBaseImplement.Models +{ + public class Component : IComponentModel + { + public int Id { get; private set; } + [Required] + public string ComponentName { get; private set; } = string.Empty; + [Required] + public double Cost { get; set; } + [ForeignKey("ComponentId")] + public virtual List DocumentComponents { get; set; } = new(); + public static Component? Create(ComponentBindingModel model) + { + if (model == null) + { + return null; + } + return new Component() + { + Id = model.Id, + ComponentName = model.ComponentName, + Cost = model.Cost + }; + } + public static Component Create(ComponentViewModel model) + { + return new Component + { + Id = model.Id, + ComponentName = model.ComponentName, + Cost = model.Cost + }; + } + public void Update(ComponentBindingModel model) + { + if (model == null) + { + return; + } + ComponentName = model.ComponentName; + Cost = model.Cost; + } + public ComponentViewModel GetViewModel => new() + { + Id = Id, + ComponentName = ComponentName, + Cost = Cost + }; + + } +} diff --git a/LawFirm/AbstractLawFirmDatabaseImplement/Models/Document.cs b/LawFirm/AbstractLawFirmDatabaseImplement/Models/Document.cs new file mode 100644 index 0000000..b1ba0a2 --- /dev/null +++ b/LawFirm/AbstractLawFirmDatabaseImplement/Models/Document.cs @@ -0,0 +1,97 @@ +using AbstractLawFirmContracts.BindingModels; +using AbstractLawFirmContracts.ViewModels; +using AbstractLawFirmDataModels.Models; +using System; +using System.Collections.Generic; +using System.ComponentModel.DataAnnotations.Schema; +using System.ComponentModel.DataAnnotations; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using AbstractLawFirmDataBaseImplement.Models; + +namespace AbstractLawFirmDataBaseImplement.Models +{ + public class Document : IDocumentModel + { + public int Id { get; set; } + [Required] + public string DocumentName { get; set; } = string.Empty; + [Required] + public double Price { get; set; } + private Dictionary? _productComponents = + null; + [NotMapped] + public Dictionary DocumentComponents + { + get + { + if (_productComponents == null) + { + _productComponents = Components + .ToDictionary(recPC => recPC.ComponentId, recPC => + (recPC.Component as IComponentModel, recPC.Count)); + } + return _productComponents; + } + } + [ForeignKey("DocumentId")] + public virtual List Components { get; set; } = new(); + [ForeignKey("DocumentId")] + public virtual List Orders { get; set; } = new(); + public static Document Create(AbstractLawFirmDataBase context, DocumentBindingModel model) + { + return new Document() + { + Id = model.Id, + DocumentName = model.DocumentName, + Price = model.Price, + Components = model.DocumentComponents.Select(x => new DocumentComponent + { + Component = context.Components.First(y => y.Id == x.Key), + Count = x.Value.Item2 + }).ToList() + }; + } + public void Update(DocumentBindingModel model) + { + DocumentName = model.DocumentName; + Price = model.Price; + } + public DocumentViewModel GetViewModel => new() + { + Id = Id, + DocumentName = DocumentName, + Price = Price, + DocumentComponents = DocumentComponents + }; + public void UpdateComponents(AbstractLawFirmDataBase context, DocumentBindingModel model) + { + var documentComponents = context.DocumentComponents.Where(rec => rec.DocumentId == model.Id).ToList(); + if (documentComponents != null && documentComponents.Count > 0) + { // удалили те, которых нет в модели + context.DocumentComponents.RemoveRange(documentComponents.Where(rec => !model.DocumentComponents.ContainsKey(rec.ComponentId))); + context.SaveChanges(); + // обновили количество у существующих записей + foreach (var updateComponent in documentComponents) + { + updateComponent.Count = model.DocumentComponents[updateComponent.ComponentId].Item2; + model.DocumentComponents.Remove(updateComponent.ComponentId); + } + context.SaveChanges(); + } + var product = context.Documents.First(x => x.Id == Id); + foreach (var pc in model.DocumentComponents) + { + context.DocumentComponents.Add(new DocumentComponent + { + Document = product, + Component = context.Components.First(x => x.Id == pc.Key), + Count = pc.Value.Item2 + }); + context.SaveChanges(); + } + _productComponents = null; + } + } +} diff --git a/LawFirm/AbstractLawFirmDatabaseImplement/Models/DocumentComponent.cs b/LawFirm/AbstractLawFirmDatabaseImplement/Models/DocumentComponent.cs new file mode 100644 index 0000000..a24c3f4 --- /dev/null +++ b/LawFirm/AbstractLawFirmDatabaseImplement/Models/DocumentComponent.cs @@ -0,0 +1,24 @@ +using AbstractLawFirmDataBaseImplement.Models; +using System; +using System.Collections.Generic; +using System.ComponentModel.DataAnnotations; +using System.Linq; +using System.Reflection.Metadata; +using System.Text; +using System.Threading.Tasks; + +namespace AbstractLawFirmDataBaseImplement.Models +{ + public class DocumentComponent + { + public int Id { get; set; } + [Required] + public int DocumentId { get; set; } + [Required] + public int ComponentId { get; set; } + [Required] + public int Count { get; set; } + public virtual Component Component { get; set; } = new(); + public virtual Document Document { get; set; } = new(); + } +} diff --git a/LawFirm/AbstractLawFirmDatabaseImplement/Models/Order.cs b/LawFirm/AbstractLawFirmDatabaseImplement/Models/Order.cs new file mode 100644 index 0000000..f875f25 --- /dev/null +++ b/LawFirm/AbstractLawFirmDatabaseImplement/Models/Order.cs @@ -0,0 +1,65 @@ +using AbstractLawFirmContracts.BindingModels; +using AbstractLawFirmContracts.ViewModels; +using AbstractLawFirmDataModels.Enums; +using AbstractLawFirmDataModels.Models; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace AbstractLawFirmDataBaseImplement.Models +{ + public class Order : IOrderModel + { + public int Id { get; private set; } + public int DocumentId { get; private set; } + public int Count { get; private set; } + public double Sum { get; private set; } + public OrderStatus Status { get; private set; } + public DateTime DateCreate { get; private set; } + public DateTime? DateImplement { get; private set; } + public static Order? Create(OrderBindingModel? model) + { + if (model == null) + { + return null; + } + return new Order() + { + Id = model.Id, + DocumentId = model.DocumentId, + Count = model.Count, + Sum = model.Sum, + Status = model.Status, + DateCreate = model.DateCreate, + DateImplement = model.DateImplement, + }; + } + public void Update(OrderBindingModel? model) + { + if (model == null) + { + return; + } + Id = model.Id; + DocumentId = model.DocumentId; + Count = model.Count; + Sum = model.Sum; + Status = model.Status; + DateCreate = model.DateCreate; + DateImplement = model.DateImplement; + } + public OrderViewModel GetViewModel => new() + { + Id = Id, + DocumentId = DocumentId, + Count = Count, + Sum = Sum, + Status = Status, + DateCreate = DateCreate, + DateImplement = DateImplement, + }; + + } +} diff --git a/LawFirm/AbstractLawFirmFileImpliment/DataFileSingleton.cs b/LawFirm/AbstractLawFirmFileImpliment/DataFileSingleton.cs index a220336..98e142b 100644 --- a/LawFirm/AbstractLawFirmFileImpliment/DataFileSingleton.cs +++ b/LawFirm/AbstractLawFirmFileImpliment/DataFileSingleton.cs @@ -13,7 +13,7 @@ namespace AbstractLawFirmFileImpliment private static DataFileSingleton? instance; private readonly string ComponentFileName = "Component.xml"; private readonly string OrderFileName = "Order.xml"; - private readonly string ProductFileName = "Product.xml"; + private readonly string DocumentFileName = "Document.xml"; public List Components { get; private set; } public List Orders { get; private set; } public List Documents { get; private set; } @@ -27,14 +27,14 @@ namespace AbstractLawFirmFileImpliment } public void SaveComponents() => SaveData(Components, ComponentFileName, "Components", x => x.GetXElement); - public void SaveDocuments() => SaveData(Documents, ProductFileName, + public void SaveDocuments() => SaveData(Documents, DocumentFileName, "Documents", x => x.GetXElement); public void SaveOrders() => SaveData(Orders, OrderFileName, "Orders", x => x.GetXElement); private DataFileSingleton() { Components = LoadData(ComponentFileName, "Component", x => Component.Create(x)!)!; - Documents = LoadData(ProductFileName, "Document", x => Document.Create(x)!)!; + Documents = LoadData(DocumentFileName, "Document", x => Document.Create(x)!)!; Orders = LoadData(OrderFileName, "Order", x => Order.Create(x)!)!; } diff --git a/LawFirm/LawFirm.sln b/LawFirm/LawFirm.sln index e41b11c..52338f1 100644 --- a/LawFirm/LawFirm.sln +++ b/LawFirm/LawFirm.sln @@ -13,7 +13,9 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "AbstractLawFirmBusinessLogi EndProject Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "AbstractLawFirmListImplement", "AbstractLawFirmListImplement\AbstractLawFirmListImplement.csproj", "{86D5FC6F-B262-44A0-9D30-970F9EA93E0A}" EndProject -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "AbstractLawFirmFileImplement", "AbstractLawFirmFileImpliment\AbstractLawFirmFileImplement.csproj", "{8AF960C2-208F-4B7B-9F8B-36B63446B6B7}" +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "AbstractLawFirmFileImplement", "AbstractLawFirmFileImpliment\AbstractLawFirmFileImplement.csproj", "{8AF960C2-208F-4B7B-9F8B-36B63446B6B7}" +EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "AbstractLawFirmDatabaseImplement", "AbstractLawFirmDatabaseImplement\AbstractLawFirmDatabaseImplement.csproj", "{BF41FCA1-C12C-4D56-B29C-8BF1D9AE69B1}" EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution @@ -45,6 +47,10 @@ Global {8AF960C2-208F-4B7B-9F8B-36B63446B6B7}.Debug|Any CPU.Build.0 = Debug|Any CPU {8AF960C2-208F-4B7B-9F8B-36B63446B6B7}.Release|Any CPU.ActiveCfg = Release|Any CPU {8AF960C2-208F-4B7B-9F8B-36B63446B6B7}.Release|Any CPU.Build.0 = Release|Any CPU + {BF41FCA1-C12C-4D56-B29C-8BF1D9AE69B1}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {BF41FCA1-C12C-4D56-B29C-8BF1D9AE69B1}.Debug|Any CPU.Build.0 = Debug|Any CPU + {BF41FCA1-C12C-4D56-B29C-8BF1D9AE69B1}.Release|Any CPU.ActiveCfg = Release|Any CPU + {BF41FCA1-C12C-4D56-B29C-8BF1D9AE69B1}.Release|Any CPU.Build.0 = Release|Any CPU EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE diff --git a/LawFirm/LawFirmView/LawFirmView.csproj b/LawFirm/LawFirmView/LawFirmView.csproj index c62edf7..f4a4211 100644 --- a/LawFirm/LawFirmView/LawFirmView.csproj +++ b/LawFirm/LawFirmView/LawFirmView.csproj @@ -9,12 +9,17 @@ + + all + runtime; build; native; contentfiles; analyzers; buildtransitive + + -- 2.25.1 From 41531f97614fbd163f51441266191e64e4070d73 Mon Sep 17 00:00:00 2001 From: GokaPek Date: Tue, 26 Mar 2024 00:07:11 +0400 Subject: [PATCH 2/3] =?UTF-8?q?=D1=84=D0=B8=D0=BD=D0=B0=D0=BB?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../AbstractLawFirmDataBase.cs | 2 +- .../Implements/ComponentStorage.cs | 101 +++++++++----- .../Implements/DocumentStorage.cs | 126 +++++++++++++----- .../Implements/OrderStorage.cs | 57 +++++++- .../20240325152423_InitialCreate.Designer.cs | 2 +- .../AbstractLawFirmDataBaseModelSnapshot.cs | 2 +- LawFirm/LawFirm.sln | 2 +- LawFirm/LawFirmView/LawFirmView.csproj | 2 +- LawFirm/LawFirmView/Program.cs | 2 +- 9 files changed, 223 insertions(+), 73 deletions(-) diff --git a/LawFirm/AbstractLawFirmDatabaseImplement/AbstractLawFirmDataBase.cs b/LawFirm/AbstractLawFirmDatabaseImplement/AbstractLawFirmDataBase.cs index df28dd3..d0f654f 100644 --- a/LawFirm/AbstractLawFirmDatabaseImplement/AbstractLawFirmDataBase.cs +++ b/LawFirm/AbstractLawFirmDatabaseImplement/AbstractLawFirmDataBase.cs @@ -14,7 +14,7 @@ namespace AbstractLawFirmDataBaseImplement { if (optionsBuilder.IsConfigured == false) { - optionsBuilder.UseSqlServer(@"Data Source=GOKA\SQLEXPRESS;Initial Catalog=AbstractLawFirmDataBase Full;Integrated Security=True;MultipleActiveResultSets=True;;TrustServerCertificate=True"); + optionsBuilder.UseSqlServer(@"Data Source=DESKTOP-N8BRIPR\SQLEXPRESS;Initial Catalog=AbstractLawFirmDataBaseFull;Integrated Security=True;MultipleActiveResultSets=True;;TrustServerCertificate=True"); } base.OnConfiguring(optionsBuilder); } diff --git a/LawFirm/AbstractLawFirmDatabaseImplement/Implements/ComponentStorage.cs b/LawFirm/AbstractLawFirmDatabaseImplement/Implements/ComponentStorage.cs index 8b18364..fc12fa6 100644 --- a/LawFirm/AbstractLawFirmDatabaseImplement/Implements/ComponentStorage.cs +++ b/LawFirm/AbstractLawFirmDatabaseImplement/Implements/ComponentStorage.cs @@ -2,8 +2,10 @@ using AbstractLawFirmContracts.SearchModels; using AbstractLawFirmContracts.StoragesContracts; using AbstractLawFirmContracts.ViewModels; +using AbstractLawFirmDataBaseImplement; +using AbstractLawFirmDataBaseImplement.Models; using System; -using System.Collections.Generic; +using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; @@ -11,35 +13,72 @@ using System.Threading.Tasks; namespace AbstractLawFirmDatabaseImplement.Implements { public class ComponentStorage : IComponentStorage - { - public ComponentViewModel? Delete(ComponentBindingModel model) - { - throw new NotImplementedException(); - } - - public ComponentViewModel? GetElement(ComponentSearchModel model) - { - throw new NotImplementedException(); - } - - public List GetFilteredList(ComponentSearchModel model) - { - throw new NotImplementedException(); - } - - public List GetFullList() - { - throw new NotImplementedException(); - } - - public ComponentViewModel? Insert(ComponentBindingModel model) - { - throw new NotImplementedException(); - } - - public ComponentViewModel? Update(ComponentBindingModel model) - { - throw new NotImplementedException(); - } + { + public List GetFullList() + { + using var context = new AbstractLawFirmDataBase(); + return context.Components + .Select(x => x.GetViewModel) + .ToList(); + } + public List GetFilteredList(ComponentSearchModel model) + { + if (string.IsNullOrEmpty(model.ComponentName)) + { + return new(); + } + using var context = new AbstractLawFirmDataBase(); + return context.Components + .Where(x => x.ComponentName.Contains(model.ComponentName)) + .Select(x => x.GetViewModel) + .ToList(); + } + public ComponentViewModel? GetElement(ComponentSearchModel model) + { + if (string.IsNullOrEmpty(model.ComponentName) && !model.Id.HasValue) + { + return null; + } + using var context = new AbstractLawFirmDataBase(); + return context.Components + .FirstOrDefault(x => + (!string.IsNullOrEmpty(model.ComponentName) && x.ComponentName == model.ComponentName) || (model.Id.HasValue && x.Id == model.Id)) ?.GetViewModel; + } + public ComponentViewModel? Insert(ComponentBindingModel model) + { + var newComponent = Component.Create(model); + if (newComponent == null) + { + return null; + } + using var context = new AbstractLawFirmDataBase(); + context.Components.Add(newComponent); + context.SaveChanges(); + return newComponent.GetViewModel; + } + public ComponentViewModel? Update(ComponentBindingModel model) + { + using var context = new AbstractLawFirmDataBase(); + var component = context.Components.FirstOrDefault(x => x.Id == model.Id); + if (component == null) + { + return null; + } + component.Update(model); + context.SaveChanges(); + return component.GetViewModel; + } + public ComponentViewModel? Delete(ComponentBindingModel model) + { + using var context = new AbstractLawFirmDataBase(); + var element = context.Components.FirstOrDefault(rec => rec.Id == model.Id); + if (element != null) + { + context.Components.Remove(element); + context.SaveChanges(); + return element.GetViewModel; + } + return null; + } } } diff --git a/LawFirm/AbstractLawFirmDatabaseImplement/Implements/DocumentStorage.cs b/LawFirm/AbstractLawFirmDatabaseImplement/Implements/DocumentStorage.cs index 4727a60..a916835 100644 --- a/LawFirm/AbstractLawFirmDatabaseImplement/Implements/DocumentStorage.cs +++ b/LawFirm/AbstractLawFirmDatabaseImplement/Implements/DocumentStorage.cs @@ -3,6 +3,9 @@ using AbstractLawFirmContracts.BindingModels.BindingModels; using AbstractLawFirmContracts.SearchModels; using AbstractLawFirmContracts.StoragesContracts; using AbstractLawFirmContracts.ViewModels; +using AbstractLawFirmDataBaseImplement; +using AbstractLawFirmDataBaseImplement.Models; +using Microsoft.EntityFrameworkCore; using System; using System.Collections.Generic; using System.Linq; @@ -12,35 +15,98 @@ using System.Threading.Tasks; namespace AbstractLawFirmDatabaseImplement.Implements { public class DocumentStorage : IDocumentStorage - { - public DocumentViewModel? Delete(DocumentBindingModel model) - { - throw new NotImplementedException(); - } - - public DocumentViewModel? GetElement(DocumentSearchModel model) - { - throw new NotImplementedException(); - } - - public List GetFilteredList(DocumentSearchModel model) - { - throw new NotImplementedException(); - } - - public List GetFullList() - { - throw new NotImplementedException(); - } - - public DocumentViewModel? Insert(DocumentBindingModel model) - { - throw new NotImplementedException(); - } - - public DocumentViewModel? Update(DocumentBindingModel model) - { - throw new NotImplementedException(); - } + { + public List GetFullList() + { + using var context = new AbstractLawFirmDataBase(); + return context.Documents + .Include(x => x.Components) + .ThenInclude(x => x.Component) + .ToList() + .Select(x => x.GetViewModel) + .ToList(); + } + public List GetFilteredList(DocumentSearchModel model) + { + if (string.IsNullOrEmpty(model.DocumentName)) + { + return new(); + } + using var context = new AbstractLawFirmDataBase(); + return context.Documents + .Include(x => x.Components) + .ThenInclude(x => x.Component) + .Where(x => x.DocumentName.Contains(model.DocumentName)) + .ToList() + .Select(x => x.GetViewModel) + .ToList(); + } + public DocumentViewModel? GetElement(DocumentSearchModel model) + { + if (string.IsNullOrEmpty(model.DocumentName) && + !model.Id.HasValue) + { + return null; + } + using var context = new AbstractLawFirmDataBase(); + return context.Documents + .Include(x => x.Components) + .ThenInclude(x => x.Component) + .FirstOrDefault(x => (!string.IsNullOrEmpty(model.DocumentName) && + x.DocumentName == model.DocumentName) || + (model.Id.HasValue && x.Id == + model.Id)) + ?.GetViewModel; + } + public DocumentViewModel? Insert(DocumentBindingModel model) + { + using var context = new AbstractLawFirmDataBase(); + var newDocument = Document.Create(context, model); + if (newDocument == null) + { + return null; + } + context.Documents.Add(newDocument); + context.SaveChanges(); + return newDocument.GetViewModel; + } + public DocumentViewModel? Update(DocumentBindingModel model) + { + using var context = new AbstractLawFirmDataBase(); + using var transaction = context.Database.BeginTransaction(); + try + { + var product = context.Documents.FirstOrDefault(rec => + rec.Id == model.Id); + if (product == null) + { + return null; + } + product.Update(model); + context.SaveChanges(); + product.UpdateComponents(context, model); + transaction.Commit(); + return product.GetViewModel; + } + catch + { + transaction.Rollback(); + throw; + } + } + public DocumentViewModel? Delete(DocumentBindingModel model) + { + using var context = new AbstractLawFirmDataBase(); + var element = context.Documents + .Include(x => x.Components) + .FirstOrDefault(rec => rec.Id == model.Id); + if (element != null) + { + context.Documents.Remove(element); + context.SaveChanges(); + return element.GetViewModel; + } + return null; + } } } diff --git a/LawFirm/AbstractLawFirmDatabaseImplement/Implements/OrderStorage.cs b/LawFirm/AbstractLawFirmDatabaseImplement/Implements/OrderStorage.cs index 036e6fc..52f2afa 100644 --- a/LawFirm/AbstractLawFirmDatabaseImplement/Implements/OrderStorage.cs +++ b/LawFirm/AbstractLawFirmDatabaseImplement/Implements/OrderStorage.cs @@ -2,11 +2,14 @@ using AbstractLawFirmContracts.SearchModels; using AbstractLawFirmContracts.ViewModels; using AbstractLawFirmContracts.StoragesContracts; +using AbstractLawFirmDataBaseImplement.Models; using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; +using AbstractLawFirmDataBaseImplement; +using Microsoft.EntityFrameworkCore; namespace AbstractLawFirmDatabaseImplement.Implements { @@ -14,32 +17,74 @@ namespace AbstractLawFirmDatabaseImplement.Implements { public OrderViewModel? Delete(OrderBindingModel model) { - throw new NotImplementedException(); + using var context = new AbstractLawFirmDataBase(); + var element = context.Orders.FirstOrDefault(rec => rec.Id == model.Id); + if (element != null) + { + context.Orders.Remove(element); + context.SaveChanges(); + return element.GetViewModel; + } + return null; } public OrderViewModel? GetElement(OrderSearchModel model) { - throw new NotImplementedException(); + if (!model.Id.HasValue) + { + return null; + } + using var context = new AbstractLawFirmDataBase(); + return context.Orders + .FirstOrDefault(x => + (model.Id.HasValue && x.Id == model.Id))?.GetViewModel; } public List GetFilteredList(OrderSearchModel model) { - throw new NotImplementedException(); + if (!model.Id.HasValue) + { + return new(); + } + using var context = new AbstractLawFirmDataBase(); + return context.Orders + .Where(x => x.Id == model.Id) + .Select(x => x.GetViewModel) + .ToList(); } public List GetFullList() { - throw new NotImplementedException(); + using var context = new AbstractLawFirmDataBase(); + return context.Orders + .Select(x => x.GetViewModel) + .ToList(); } public OrderViewModel? Insert(OrderBindingModel model) { - throw new NotImplementedException(); + var newOrder = Order.Create(model); + if (newOrder == null) + { + return null; + } + using var context = new AbstractLawFirmDataBase(); + context.Orders.Add(newOrder); + context.SaveChanges(); + return newOrder.GetViewModel; } public OrderViewModel? Update(OrderBindingModel model) { - throw new NotImplementedException(); + using var context = new AbstractLawFirmDataBase(); + var component = context.Orders.FirstOrDefault(x => x.Id == model.Id); + if (component == null) + { + return null; + } + component.Update(model); + context.SaveChanges(); + return component.GetViewModel; } } } diff --git a/LawFirm/AbstractLawFirmDatabaseImplement/Migrations/20240325152423_InitialCreate.Designer.cs b/LawFirm/AbstractLawFirmDatabaseImplement/Migrations/20240325152423_InitialCreate.Designer.cs index 14fd17b..7dedd3d 100644 --- a/LawFirm/AbstractLawFirmDatabaseImplement/Migrations/20240325152423_InitialCreate.Designer.cs +++ b/LawFirm/AbstractLawFirmDatabaseImplement/Migrations/20240325152423_InitialCreate.Designer.cs @@ -19,7 +19,7 @@ namespace AbstractLawFirmDatabaseImplement.Migrations { #pragma warning disable 612, 618 modelBuilder - .HasAnnotation("ProductVersion", "6.0.28") + .HasAnnotation("DocumentVersion", "6.0.28") .HasAnnotation("Relational:MaxIdentifierLength", 128); SqlServerModelBuilderExtensions.UseIdentityColumns(modelBuilder, 1L, 1); diff --git a/LawFirm/AbstractLawFirmDatabaseImplement/Migrations/AbstractLawFirmDataBaseModelSnapshot.cs b/LawFirm/AbstractLawFirmDatabaseImplement/Migrations/AbstractLawFirmDataBaseModelSnapshot.cs index c6d34ab..f356f2b 100644 --- a/LawFirm/AbstractLawFirmDatabaseImplement/Migrations/AbstractLawFirmDataBaseModelSnapshot.cs +++ b/LawFirm/AbstractLawFirmDatabaseImplement/Migrations/AbstractLawFirmDataBaseModelSnapshot.cs @@ -17,7 +17,7 @@ namespace AbstractLawFirmDatabaseImplement.Migrations { #pragma warning disable 612, 618 modelBuilder - .HasAnnotation("ProductVersion", "6.0.28") + .HasAnnotation("DocumentVersion", "6.0.28") .HasAnnotation("Relational:MaxIdentifierLength", 128); SqlServerModelBuilderExtensions.UseIdentityColumns(modelBuilder, 1L, 1); diff --git a/LawFirm/LawFirm.sln b/LawFirm/LawFirm.sln index 52338f1..45059dc 100644 --- a/LawFirm/LawFirm.sln +++ b/LawFirm/LawFirm.sln @@ -15,7 +15,7 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "AbstractLawFirmListImplemen EndProject Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "AbstractLawFirmFileImplement", "AbstractLawFirmFileImpliment\AbstractLawFirmFileImplement.csproj", "{8AF960C2-208F-4B7B-9F8B-36B63446B6B7}" EndProject -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "AbstractLawFirmDatabaseImplement", "AbstractLawFirmDatabaseImplement\AbstractLawFirmDatabaseImplement.csproj", "{BF41FCA1-C12C-4D56-B29C-8BF1D9AE69B1}" +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "AbstractLawFirmDataBaseImplement", "AbstractLawFirmDatabaseImplement\AbstractLawFirmDataBaseImplement.csproj", "{BF41FCA1-C12C-4D56-B29C-8BF1D9AE69B1}" EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution diff --git a/LawFirm/LawFirmView/LawFirmView.csproj b/LawFirm/LawFirmView/LawFirmView.csproj index f4a4211..697d6b7 100644 --- a/LawFirm/LawFirmView/LawFirmView.csproj +++ b/LawFirm/LawFirmView/LawFirmView.csproj @@ -19,7 +19,7 @@ - + diff --git a/LawFirm/LawFirmView/Program.cs b/LawFirm/LawFirmView/Program.cs index cffdc50..1986fb9 100644 --- a/LawFirm/LawFirmView/Program.cs +++ b/LawFirm/LawFirmView/Program.cs @@ -1,7 +1,7 @@ using AbstractLawFirmBusinessLogic.BusinessLogic; using AbstractLawFirmContracts.BusinessLogicsContracts; using AbstractLawFirmContracts.StoragesContracts; -using AbstractLawFirmFileImplement.Implements; +using AbstractLawFirmDatabaseImplement.Implements; using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.Logging; using NLog.Extensions.Logging; -- 2.25.1 From e184ca408d0a97e9f70eca08921c5dc0be36a050 Mon Sep 17 00:00:00 2001 From: GokaPek Date: Wed, 27 Mar 2024 10:54:50 +0400 Subject: [PATCH 3/3] =?UTF-8?q?=D1=84=D0=B8=D0=BD=D0=B0=D0=BB?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Implements/OrderStorage.cs | 17 +++++++---------- .../Models/Order.cs | 2 ++ 2 files changed, 9 insertions(+), 10 deletions(-) diff --git a/LawFirm/AbstractLawFirmDatabaseImplement/Implements/OrderStorage.cs b/LawFirm/AbstractLawFirmDatabaseImplement/Implements/OrderStorage.cs index 52f2afa..ae14a74 100644 --- a/LawFirm/AbstractLawFirmDatabaseImplement/Implements/OrderStorage.cs +++ b/LawFirm/AbstractLawFirmDatabaseImplement/Implements/OrderStorage.cs @@ -35,9 +35,7 @@ namespace AbstractLawFirmDatabaseImplement.Implements return null; } using var context = new AbstractLawFirmDataBase(); - return context.Orders - .FirstOrDefault(x => - (model.Id.HasValue && x.Id == model.Id))?.GetViewModel; + return context.Orders.Include(x => x.Document).FirstOrDefault(x => (model.Id.HasValue && x.Id == model.Id))?.GetViewModel; } public List GetFilteredList(OrderSearchModel model) @@ -49,16 +47,15 @@ namespace AbstractLawFirmDatabaseImplement.Implements using var context = new AbstractLawFirmDataBase(); return context.Orders .Where(x => x.Id == model.Id) - .Select(x => x.GetViewModel) - .ToList(); + .Include(x => x.Document) + .Select(x => x.GetViewModel) + .ToList(); } public List GetFullList() { using var context = new AbstractLawFirmDataBase(); - return context.Orders - .Select(x => x.GetViewModel) - .ToList(); + return context.Orders.Include(x => x.Document).Select(x => x.GetViewModel).ToList(); } public OrderViewModel? Insert(OrderBindingModel model) @@ -71,7 +68,7 @@ namespace AbstractLawFirmDatabaseImplement.Implements using var context = new AbstractLawFirmDataBase(); context.Orders.Add(newOrder); context.SaveChanges(); - return newOrder.GetViewModel; + return context.Orders.Include(x => x.Document).FirstOrDefault(x => x.Id == newOrder.Id)?.GetViewModel; } public OrderViewModel? Update(OrderBindingModel model) @@ -84,7 +81,7 @@ namespace AbstractLawFirmDatabaseImplement.Implements } component.Update(model); context.SaveChanges(); - return component.GetViewModel; + return context.Orders.Include(x => x.Document).FirstOrDefault(x => x.Id == model.Id)?.GetViewModel; } } } diff --git a/LawFirm/AbstractLawFirmDatabaseImplement/Models/Order.cs b/LawFirm/AbstractLawFirmDatabaseImplement/Models/Order.cs index f875f25..6a8b77a 100644 --- a/LawFirm/AbstractLawFirmDatabaseImplement/Models/Order.cs +++ b/LawFirm/AbstractLawFirmDatabaseImplement/Models/Order.cs @@ -14,6 +14,7 @@ namespace AbstractLawFirmDataBaseImplement.Models { public int Id { get; private set; } public int DocumentId { get; private set; } + public virtual Document? Document { get; private set; } public int Count { get; private set; } public double Sum { get; private set; } public OrderStatus Status { get; private set; } @@ -54,6 +55,7 @@ namespace AbstractLawFirmDataBaseImplement.Models { Id = Id, DocumentId = DocumentId, + DocumentName = Document.DocumentName, Count = Count, Sum = Sum, Status = Status, -- 2.25.1