From 70c477002df17448e1f1d24d19a08dad76fcea3e Mon Sep 17 00:00:00 2001 From: sardq Date: Fri, 19 Apr 2024 18:36:30 +0400 Subject: [PATCH] =?UTF-8?q?3=20=D1=83=D1=81=D0=BB=D0=BE=D0=B6=D0=BD=D0=B5?= =?UTF-8?q?=D0=BD=D0=BD=D0=B0=D1=8F=20=D0=BB=D0=B0=D0=B1=D0=BE=D1=80=D0=B0?= =?UTF-8?q?=D1=82=D0=BE=D1=80=D0=BD=D0=B0=D1=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- PlumbingRepair/PlumbingRepair.sln | 10 +- .../Implements/ShopStorage.cs | 143 ++++++++++++++++++ ... 20240410163831_InitialCreate.Designer.cs} | 81 +++++++++- ...ate.cs => 20240410163831_InitialCreate.cs} | 59 ++++++++ .../PlumbingRepairDatabaseModelSnapshot.cs | 77 ++++++++++ .../Models/Shop.cs | 109 +++++++++++++ .../Models/ShopWork.cs | 21 +++ .../PlumbingRepairDatabase.cs | 6 +- .../PlumbingRepairFileImplement.csproj | 4 - .../PlumbingRepairView.csproj | 4 +- 10 files changed, 500 insertions(+), 14 deletions(-) create mode 100644 PlumbingRepair/PlumbingRepairDatabaseImplement/Implements/ShopStorage.cs rename PlumbingRepair/PlumbingRepairDatabaseImplement/Migrations/{20240308152131_InitialCreate.Designer.cs => 20240410163831_InitialCreate.Designer.cs} (67%) rename PlumbingRepair/PlumbingRepairDatabaseImplement/Migrations/{20240308152131_InitialCreate.cs => 20240410163831_InitialCreate.cs} (66%) create mode 100644 PlumbingRepair/PlumbingRepairDatabaseImplement/Models/Shop.cs create mode 100644 PlumbingRepair/PlumbingRepairDatabaseImplement/Models/ShopWork.cs diff --git a/PlumbingRepair/PlumbingRepair.sln b/PlumbingRepair/PlumbingRepair.sln index 8c4b11f..061d307 100644 --- a/PlumbingRepair/PlumbingRepair.sln +++ b/PlumbingRepair/PlumbingRepair.sln @@ -13,7 +13,7 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "PlumbingRepairDataModels", EndProject Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "PlumbingRepairListImplement", "PlumbingRepairListImplement\PlumbingRepairListImplement.csproj", "{A5D22B59-19BC-4DB6-A234-24AEA47605C2}" EndProject -Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "PlumbingRepairFileImplement", "PlumbingRepairFileImplement\PlumbingRepairFileImplement.csproj", "{8BB0E6DF-704B-4660-8D5E-4D263CD40C98}" +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "PlumbingRepairFileImplement", "PlumbingRepairFileImplement\PlumbingRepairFileImplement.csproj", "{102B6C63-8EB6-4786-BFEA-88B7DB0DB3F0}" EndProject Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "PlumbingRepairDatabaseImplement", "PlumbingRepairDatabaseImplement\PlumbingRepairDatabaseImplement.csproj", "{6DDC0CCD-97E0-4CB7-8024-C27DB9AEF97B}" EndProject @@ -43,10 +43,10 @@ Global {A5D22B59-19BC-4DB6-A234-24AEA47605C2}.Debug|Any CPU.Build.0 = Debug|Any CPU {A5D22B59-19BC-4DB6-A234-24AEA47605C2}.Release|Any CPU.ActiveCfg = Release|Any CPU {A5D22B59-19BC-4DB6-A234-24AEA47605C2}.Release|Any CPU.Build.0 = Release|Any CPU - {8BB0E6DF-704B-4660-8D5E-4D263CD40C98}.Debug|Any CPU.ActiveCfg = Debug|Any CPU - {8BB0E6DF-704B-4660-8D5E-4D263CD40C98}.Debug|Any CPU.Build.0 = Debug|Any CPU - {8BB0E6DF-704B-4660-8D5E-4D263CD40C98}.Release|Any CPU.ActiveCfg = Release|Any CPU - {8BB0E6DF-704B-4660-8D5E-4D263CD40C98}.Release|Any CPU.Build.0 = Release|Any CPU + {102B6C63-8EB6-4786-BFEA-88B7DB0DB3F0}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {102B6C63-8EB6-4786-BFEA-88B7DB0DB3F0}.Debug|Any CPU.Build.0 = Debug|Any CPU + {102B6C63-8EB6-4786-BFEA-88B7DB0DB3F0}.Release|Any CPU.ActiveCfg = Release|Any CPU + {102B6C63-8EB6-4786-BFEA-88B7DB0DB3F0}.Release|Any CPU.Build.0 = Release|Any CPU {6DDC0CCD-97E0-4CB7-8024-C27DB9AEF97B}.Debug|Any CPU.ActiveCfg = Debug|Any CPU {6DDC0CCD-97E0-4CB7-8024-C27DB9AEF97B}.Debug|Any CPU.Build.0 = Debug|Any CPU {6DDC0CCD-97E0-4CB7-8024-C27DB9AEF97B}.Release|Any CPU.ActiveCfg = Release|Any CPU diff --git a/PlumbingRepair/PlumbingRepairDatabaseImplement/Implements/ShopStorage.cs b/PlumbingRepair/PlumbingRepairDatabaseImplement/Implements/ShopStorage.cs new file mode 100644 index 0000000..bfaedd5 --- /dev/null +++ b/PlumbingRepair/PlumbingRepairDatabaseImplement/Implements/ShopStorage.cs @@ -0,0 +1,143 @@ + +using Microsoft.EntityFrameworkCore; +using PlumbingRepairContracts.BindingModels; +using PlumbingRepairContracts.SearchModels; +using PlumbingRepairContracts.StoragesContracts; +using PlumbingRepairContracts.ViewModels; +using PlumbingRepairDatabaseImplement.Models; +using PlumbingRepairDataModels.Models; + +namespace PlumbingRepairDatabaseImplement.Implements +{ + public class ShopStorage : IShopStorage + { + public List GetFullList() + { + using var context = new PlumbingRepairDatabase(); + return context.Shops + .Include(x => x.Works) + .ThenInclude(x => x.Work) + .ToList() + .Select(x => x.GetViewModel) + .ToList(); + } + + public List GetFilteredList(ShopSearchModel model) + { + if (string.IsNullOrEmpty(model.ShopName)) + { + return new(); + } + using var context = new PlumbingRepairDatabase(); + return context.Shops + .Include(x => x.Works) + .ThenInclude(x => x.Work) + .Where(x => x.ShopName.Contains(model.ShopName)) + .ToList() + .Select(x => x.GetViewModel) + .ToList(); + } + + public ShopViewModel? GetElement(ShopSearchModel model) + { + if (string.IsNullOrEmpty(model.ShopName) && !model.Id.HasValue) + { + return null; + } + using var context = new PlumbingRepairDatabase(); + return context.Shops + .Include(x => x.Works) + .ThenInclude(x => x.Work) + .FirstOrDefault(x => (!string.IsNullOrEmpty(model.ShopName) && x.ShopName == model.ShopName) || + (model.Id.HasValue && x.Id == model.Id)) + ?.GetViewModel; + } + + public ShopViewModel? Insert(ShopBindingModel model) + { + using var context = new PlumbingRepairDatabase(); + var newShop = Shop.Create(context, model); + if (newShop == null) + { + return null; + } + context.Shops.Add(newShop); + context.SaveChanges(); + return newShop.GetViewModel; + } + + public ShopViewModel? Update(ShopBindingModel model) + { + using var context = new PlumbingRepairDatabase(); + using var transaction = context.Database.BeginTransaction(); + try + { + var shop = context.Shops.FirstOrDefault(rec => rec.Id == model.Id); + if (shop == null) + { + return null; + } + shop.Update(model); + context.SaveChanges(); + shop.UpdateWorks(context, model); + transaction.Commit(); + return shop.GetViewModel; + } + catch + { + transaction.Rollback(); + throw; + } + } + + public ShopViewModel? Delete(ShopBindingModel model) + { + using var context = new PlumbingRepairDatabase(); + var element = context.Shops + .Include(x => x.Works) + .FirstOrDefault(rec => rec.Id == model.Id); + if (element != null) + { + context.Shops.Remove(element); + context.SaveChanges(); + return element.GetViewModel; + } + return null; + } + + public bool SellWork(IWorkModel model, int count) + { + if (model == null) + return false; + using var context = new PlumbingRepairDatabase(); + using var transaction = context.Database.BeginTransaction(); + foreach (var shopWork in context.ShopWorks.Where(x => x.WorkId == model.Id)) + { + int min = Math.Min(shopWork.Count, count); + if (min == shopWork.Count) + { + context.ShopWorks.Remove(shopWork); + } + else + { + shopWork.Count -= min; + } + count -= min; + if (count <= 0) + { + break; + } + } + + if (count > 0) + { + transaction.Rollback(); + return false; + } + context.SaveChanges(); + transaction.Commit(); + return true; + + } + } +} diff --git a/PlumbingRepair/PlumbingRepairDatabaseImplement/Migrations/20240308152131_InitialCreate.Designer.cs b/PlumbingRepair/PlumbingRepairDatabaseImplement/Migrations/20240410163831_InitialCreate.Designer.cs similarity index 67% rename from PlumbingRepair/PlumbingRepairDatabaseImplement/Migrations/20240308152131_InitialCreate.Designer.cs rename to PlumbingRepair/PlumbingRepairDatabaseImplement/Migrations/20240410163831_InitialCreate.Designer.cs index 14eeef3..d183393 100644 --- a/PlumbingRepair/PlumbingRepairDatabaseImplement/Migrations/20240308152131_InitialCreate.Designer.cs +++ b/PlumbingRepair/PlumbingRepairDatabaseImplement/Migrations/20240410163831_InitialCreate.Designer.cs @@ -12,7 +12,7 @@ using PlumbingRepairDatabaseImplement; namespace PlumbingRepairDatabaseImplement.Migrations { [DbContext(typeof(PlumbingRepairDatabase))] - [Migration("20240308152131_InitialCreate")] + [Migration("20240410163831_InitialCreate")] partial class InitialCreate { protected override void BuildTargetModel(ModelBuilder modelBuilder) @@ -77,6 +77,59 @@ namespace PlumbingRepairDatabaseImplement.Migrations b.ToTable("Orders"); }); + modelBuilder.Entity("PlumbingRepairDatabaseImplement.Models.Shop", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("int"); + + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id"), 1L, 1); + + b.Property("Address") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.Property("DateOpening") + .HasColumnType("datetime2"); + + b.Property("ShopName") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.Property("maxCountWorks") + .HasColumnType("int"); + + b.HasKey("Id"); + + b.ToTable("Shops"); + }); + + modelBuilder.Entity("PlumbingRepairDatabaseImplement.Models.ShopWork", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("int"); + + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id"), 1L, 1); + + b.Property("Count") + .HasColumnType("int"); + + b.Property("ShopId") + .HasColumnType("int"); + + b.Property("WorkId") + .HasColumnType("int"); + + b.HasKey("Id"); + + b.HasIndex("ShopId"); + + b.HasIndex("WorkId"); + + b.ToTable("ShopWorks"); + }); + modelBuilder.Entity("PlumbingRepairDatabaseImplement.Models.Work", b => { b.Property("Id") @@ -125,12 +178,31 @@ namespace PlumbingRepairDatabaseImplement.Migrations modelBuilder.Entity("PlumbingRepairDatabaseImplement.Models.Order", b => { + b.HasOne("PlumbingRepairDatabaseImplement.Models.Work", "Work") + .WithMany("Orders") + .HasForeignKey("WorkId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.Navigation("Work"); + }); + + modelBuilder.Entity("PlumbingRepairDatabaseImplement.Models.ShopWork", b => + { + b.HasOne("PlumbingRepairDatabaseImplement.Models.Shop", "Shop") + .WithMany("Works") + .HasForeignKey("ShopId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + b.HasOne("PlumbingRepairDatabaseImplement.Models.Work", "Work") .WithMany() .HasForeignKey("WorkId") .OnDelete(DeleteBehavior.Cascade) .IsRequired(); + b.Navigation("Shop"); + b.Navigation("Work"); }); @@ -158,9 +230,16 @@ namespace PlumbingRepairDatabaseImplement.Migrations b.Navigation("WorkComponents"); }); + modelBuilder.Entity("PlumbingRepairDatabaseImplement.Models.Shop", b => + { + b.Navigation("Works"); + }); + modelBuilder.Entity("PlumbingRepairDatabaseImplement.Models.Work", b => { b.Navigation("Components"); + + b.Navigation("Orders"); }); #pragma warning restore 612, 618 } diff --git a/PlumbingRepair/PlumbingRepairDatabaseImplement/Migrations/20240308152131_InitialCreate.cs b/PlumbingRepair/PlumbingRepairDatabaseImplement/Migrations/20240410163831_InitialCreate.cs similarity index 66% rename from PlumbingRepair/PlumbingRepairDatabaseImplement/Migrations/20240308152131_InitialCreate.cs rename to PlumbingRepair/PlumbingRepairDatabaseImplement/Migrations/20240410163831_InitialCreate.cs index 3fda43f..484d7b3 100644 --- a/PlumbingRepair/PlumbingRepairDatabaseImplement/Migrations/20240308152131_InitialCreate.cs +++ b/PlumbingRepair/PlumbingRepairDatabaseImplement/Migrations/20240410163831_InitialCreate.cs @@ -23,6 +23,22 @@ namespace PlumbingRepairDatabaseImplement.Migrations table.PrimaryKey("PK_Components", x => x.Id); }); + migrationBuilder.CreateTable( + name: "Shops", + columns: table => new + { + Id = table.Column(type: "int", nullable: false) + .Annotation("SqlServer:Identity", "1, 1"), + ShopName = table.Column(type: "nvarchar(max)", nullable: false), + Address = table.Column(type: "nvarchar(max)", nullable: false), + DateOpening = table.Column(type: "datetime2", nullable: false), + maxCountWorks = table.Column(type: "int", nullable: false) + }, + constraints: table => + { + table.PrimaryKey("PK_Shops", x => x.Id); + }); + migrationBuilder.CreateTable( name: "Works", columns: table => new @@ -61,6 +77,33 @@ namespace PlumbingRepairDatabaseImplement.Migrations onDelete: ReferentialAction.Cascade); }); + migrationBuilder.CreateTable( + name: "ShopWorks", + columns: table => new + { + Id = table.Column(type: "int", nullable: false) + .Annotation("SqlServer:Identity", "1, 1"), + WorkId = table.Column(type: "int", nullable: false), + ShopId = table.Column(type: "int", nullable: false), + Count = table.Column(type: "int", nullable: false) + }, + constraints: table => + { + table.PrimaryKey("PK_ShopWorks", x => x.Id); + table.ForeignKey( + name: "FK_ShopWorks_Shops_ShopId", + column: x => x.ShopId, + principalTable: "Shops", + principalColumn: "Id", + onDelete: ReferentialAction.Cascade); + table.ForeignKey( + name: "FK_ShopWorks_Works_WorkId", + column: x => x.WorkId, + principalTable: "Works", + principalColumn: "Id", + onDelete: ReferentialAction.Cascade); + }); + migrationBuilder.CreateTable( name: "WorkComponents", columns: table => new @@ -93,6 +136,16 @@ namespace PlumbingRepairDatabaseImplement.Migrations table: "Orders", column: "WorkId"); + migrationBuilder.CreateIndex( + name: "IX_ShopWorks_ShopId", + table: "ShopWorks", + column: "ShopId"); + + migrationBuilder.CreateIndex( + name: "IX_ShopWorks_WorkId", + table: "ShopWorks", + column: "WorkId"); + migrationBuilder.CreateIndex( name: "IX_WorkComponents_ComponentId", table: "WorkComponents", @@ -109,9 +162,15 @@ namespace PlumbingRepairDatabaseImplement.Migrations migrationBuilder.DropTable( name: "Orders"); + migrationBuilder.DropTable( + name: "ShopWorks"); + migrationBuilder.DropTable( name: "WorkComponents"); + migrationBuilder.DropTable( + name: "Shops"); + migrationBuilder.DropTable( name: "Components"); diff --git a/PlumbingRepair/PlumbingRepairDatabaseImplement/Migrations/PlumbingRepairDatabaseModelSnapshot.cs b/PlumbingRepair/PlumbingRepairDatabaseImplement/Migrations/PlumbingRepairDatabaseModelSnapshot.cs index e5bbafd..36abf9d 100644 --- a/PlumbingRepair/PlumbingRepairDatabaseImplement/Migrations/PlumbingRepairDatabaseModelSnapshot.cs +++ b/PlumbingRepair/PlumbingRepairDatabaseImplement/Migrations/PlumbingRepairDatabaseModelSnapshot.cs @@ -75,6 +75,59 @@ namespace PlumbingRepairDatabaseImplement.Migrations b.ToTable("Orders"); }); + modelBuilder.Entity("PlumbingRepairDatabaseImplement.Models.Shop", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("int"); + + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id"), 1L, 1); + + b.Property("Address") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.Property("DateOpening") + .HasColumnType("datetime2"); + + b.Property("ShopName") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.Property("maxCountWorks") + .HasColumnType("int"); + + b.HasKey("Id"); + + b.ToTable("Shops"); + }); + + modelBuilder.Entity("PlumbingRepairDatabaseImplement.Models.ShopWork", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("int"); + + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id"), 1L, 1); + + b.Property("Count") + .HasColumnType("int"); + + b.Property("ShopId") + .HasColumnType("int"); + + b.Property("WorkId") + .HasColumnType("int"); + + b.HasKey("Id"); + + b.HasIndex("ShopId"); + + b.HasIndex("WorkId"); + + b.ToTable("ShopWorks"); + }); + modelBuilder.Entity("PlumbingRepairDatabaseImplement.Models.Work", b => { b.Property("Id") @@ -132,6 +185,25 @@ namespace PlumbingRepairDatabaseImplement.Migrations b.Navigation("Work"); }); + modelBuilder.Entity("PlumbingRepairDatabaseImplement.Models.ShopWork", b => + { + b.HasOne("PlumbingRepairDatabaseImplement.Models.Shop", "Shop") + .WithMany("Works") + .HasForeignKey("ShopId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.HasOne("PlumbingRepairDatabaseImplement.Models.Work", "Work") + .WithMany() + .HasForeignKey("WorkId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.Navigation("Shop"); + + b.Navigation("Work"); + }); + modelBuilder.Entity("PlumbingRepairDatabaseImplement.Models.WorkComponent", b => { b.HasOne("PlumbingRepairDatabaseImplement.Models.Component", "Component") @@ -156,6 +228,11 @@ namespace PlumbingRepairDatabaseImplement.Migrations b.Navigation("WorkComponents"); }); + modelBuilder.Entity("PlumbingRepairDatabaseImplement.Models.Shop", b => + { + b.Navigation("Works"); + }); + modelBuilder.Entity("PlumbingRepairDatabaseImplement.Models.Work", b => { b.Navigation("Components"); diff --git a/PlumbingRepair/PlumbingRepairDatabaseImplement/Models/Shop.cs b/PlumbingRepair/PlumbingRepairDatabaseImplement/Models/Shop.cs new file mode 100644 index 0000000..6be7a5a --- /dev/null +++ b/PlumbingRepair/PlumbingRepairDatabaseImplement/Models/Shop.cs @@ -0,0 +1,109 @@ + +using PlumbingRepairContracts.BindingModels; +using PlumbingRepairContracts.ViewModels; +using PlumbingRepairDataModels.Models; +using System.ComponentModel.DataAnnotations; +using System.ComponentModel.DataAnnotations.Schema; + +namespace PlumbingRepairDatabaseImplement.Models +{ + public class Shop + { + public int Id { get; set; } + + [Required] + public string ShopName { get; set; } = string.Empty; + [Required] + public string Address { get; set; } = string.Empty; + [Required] + public DateTime DateOpening { get; set; } + [Required] + public int maxCountWorks { get; set; } + + private Dictionary? _shopWorks = null; + + [NotMapped] + public Dictionary ShopWorks + { + get + { + if (_shopWorks == null) + { + _shopWorks = Works + .ToDictionary(recSW => recSW.WorkId, recSW => (recSW.Work as IWorkModel, recSW.Count)); + } + return _shopWorks; + } + } + + [ForeignKey("ShopId")] + public virtual List Works { get; set; } = new(); + + public static Shop? Create(PlumbingRepairDatabase context, ShopBindingModel? model) + { + if (model == null) + return null; + return new Shop() + { + Id = model.Id, + maxCountWorks = model.maxCountWorks, + Address = model.Address, + ShopName = model.ShopName, + DateOpening = model.DateOpening, + Works = model.ShopWorks.Select(x => new ShopWork + { + Work = context.Works.First(y => y.Id == x.Key), + Count = x.Value.Item2 + }).ToList() + }; + } + + public void Update(ShopBindingModel? model) + { + if (model == null) + return; + ShopName = model.ShopName; + Address = model.Address; + DateOpening = model.DateOpening; + maxCountWorks = model.maxCountWorks; + } + + public ShopViewModel GetViewModel => new() + { + ShopName = ShopName, + Address = Address, + DateOpening = DateOpening, + maxCountWorks = maxCountWorks, + Id = Id, + ShopWorks = ShopWorks + }; + public void UpdateWorks(PlumbingRepairDatabase context, ShopBindingModel model) + { + var shopWorks = context.ShopWorks.Where(rec => rec.ShopId == model.Id).ToList(); + if (shopWorks != null && shopWorks.Count > 0) + { + context.ShopWorks.RemoveRange(shopWorks.Where(rec => !model.ShopWorks.ContainsKey(rec.WorkId))); + context.SaveChanges(); + // обновили количество у существующих записей + foreach (var updateWork in shopWorks) + { + updateWork.Count = model.ShopWorks[updateWork.WorkId].Item2; + model.ShopWorks.Remove(updateWork.WorkId); + } + context.SaveChanges(); + } + var shop = context.Shops.First(x => x.Id == Id); + foreach (var pc in model.ShopWorks) + { + context.ShopWorks.Add(new ShopWork + { + Shop = shop, + Work = context.Works.First(x => x.Id == pc.Key), + Count = pc.Value.Item2 + }); + context.SaveChanges(); + } + _shopWorks = null; + } + } +} diff --git a/PlumbingRepair/PlumbingRepairDatabaseImplement/Models/ShopWork.cs b/PlumbingRepair/PlumbingRepairDatabaseImplement/Models/ShopWork.cs new file mode 100644 index 0000000..6b594d1 --- /dev/null +++ b/PlumbingRepair/PlumbingRepairDatabaseImplement/Models/ShopWork.cs @@ -0,0 +1,21 @@ +using System.ComponentModel.DataAnnotations; + +namespace PlumbingRepairDatabaseImplement.Models +{ + public class ShopWork + { + public int Id { get; set; } + + [Required] + public int WorkId { get; set; } + + [Required] + public int ShopId { get; set; } + + [Required] + public int Count { get; set; } + public virtual Work Work { get; set; } = new(); + public virtual Shop Shop { get; set; } = new(); + + } +} diff --git a/PlumbingRepair/PlumbingRepairDatabaseImplement/PlumbingRepairDatabase.cs b/PlumbingRepair/PlumbingRepairDatabaseImplement/PlumbingRepairDatabase.cs index 7d925e0..26b91b8 100644 --- a/PlumbingRepair/PlumbingRepairDatabaseImplement/PlumbingRepairDatabase.cs +++ b/PlumbingRepair/PlumbingRepairDatabaseImplement/PlumbingRepairDatabase.cs @@ -9,7 +9,7 @@ namespace PlumbingRepairDatabaseImplement { if (optionsBuilder.IsConfigured == false) { - optionsBuilder.UseSqlServer(@"Server=localhost\SQLEXPRESS;Database=master;Trusted_Connection=True;"); + optionsBuilder.UseSqlServer(@"Server=localhost\SQLEXPRESS;Database=PlumbingRepairHard;Trusted_Connection=True;"); } base.OnConfiguring(optionsBuilder); } @@ -21,5 +21,9 @@ namespace PlumbingRepairDatabaseImplement public virtual DbSet WorkComponents { set; get; } public virtual DbSet Orders { set; get; } + + public virtual DbSet Shops { set; get; } + + public virtual DbSet ShopWorks { set; get; } } } \ No newline at end of file diff --git a/PlumbingRepair/PlumbingRepairFileImplement/PlumbingRepairFileImplement.csproj b/PlumbingRepair/PlumbingRepairFileImplement/PlumbingRepairFileImplement.csproj index d2b8615..05f8377 100644 --- a/PlumbingRepair/PlumbingRepairFileImplement/PlumbingRepairFileImplement.csproj +++ b/PlumbingRepair/PlumbingRepairFileImplement/PlumbingRepairFileImplement.csproj @@ -11,8 +11,4 @@ - - - - diff --git a/PlumbingRepair/PlumbingRepairView/PlumbingRepairView.csproj b/PlumbingRepair/PlumbingRepairView/PlumbingRepairView.csproj index ba5fa93..7561c8e 100644 --- a/PlumbingRepair/PlumbingRepairView/PlumbingRepairView.csproj +++ b/PlumbingRepair/PlumbingRepairView/PlumbingRepairView.csproj @@ -14,10 +14,8 @@ -<<<<<<< HEAD -======= + ->>>>>>> laba_3