From 5e59750290b2cc319eaf45bba0fb76a5209ae7d9 Mon Sep 17 00:00:00 2001 From: devil_1nc Date: Sun, 16 Apr 2023 00:41:06 +0400 Subject: [PATCH 1/7] Brunch fix (3) --- ...tractSoftwareInstallationDatabaseImplement.csproj | 9 +++++++++ SoftwareInstallation/SoftwareInstallation.sln | 12 ++++++++++++ SoftwareInstallation/SoftwareInstallation/Program.cs | 2 +- .../SoftwareInstallationView.csproj | 1 + 4 files changed, 23 insertions(+), 1 deletion(-) create mode 100644 SoftwareInstallation/AbstractShopDatabaseImplement/AbstractSoftwareInstallationDatabaseImplement.csproj diff --git a/SoftwareInstallation/AbstractShopDatabaseImplement/AbstractSoftwareInstallationDatabaseImplement.csproj b/SoftwareInstallation/AbstractShopDatabaseImplement/AbstractSoftwareInstallationDatabaseImplement.csproj new file mode 100644 index 0000000..132c02c --- /dev/null +++ b/SoftwareInstallation/AbstractShopDatabaseImplement/AbstractSoftwareInstallationDatabaseImplement.csproj @@ -0,0 +1,9 @@ + + + + net6.0 + enable + enable + + + diff --git a/SoftwareInstallation/SoftwareInstallation.sln b/SoftwareInstallation/SoftwareInstallation.sln index 500f0a9..c4c8142 100644 --- a/SoftwareInstallation/SoftwareInstallation.sln +++ b/SoftwareInstallation/SoftwareInstallation.sln @@ -15,6 +15,10 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "AbstractSoftwareInstallatio EndProject Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "AbstractSoftwareInstallationFileImplement", "AbstractSoftwareInstallationFileImplement\AbstractSoftwareInstallationFileImplement.csproj", "{BEE13C3F-1BB8-46B4-BC87-CFC367E52A77}" EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "AbstractShopDatabaseImplement", "AbstractShopDatabaseImplement\AbstractShopDatabaseImplement.csproj", "{208C1A2E-1969-4842-BE32-13FE9A8802B0}" +EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "AbstractSoftwareInstallationDatabaseImplement", "AbstractSoftwareInstallationDatabaseImplement\AbstractSoftwareInstallationDatabaseImplement.csproj", "{7631EF04-BAD9-44D7-80C5-6017EDEA7E14}" +EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|Any CPU = Debug|Any CPU @@ -45,6 +49,14 @@ Global {BEE13C3F-1BB8-46B4-BC87-CFC367E52A77}.Debug|Any CPU.Build.0 = Debug|Any CPU {BEE13C3F-1BB8-46B4-BC87-CFC367E52A77}.Release|Any CPU.ActiveCfg = Release|Any CPU {BEE13C3F-1BB8-46B4-BC87-CFC367E52A77}.Release|Any CPU.Build.0 = Release|Any CPU + {208C1A2E-1969-4842-BE32-13FE9A8802B0}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {208C1A2E-1969-4842-BE32-13FE9A8802B0}.Debug|Any CPU.Build.0 = Debug|Any CPU + {208C1A2E-1969-4842-BE32-13FE9A8802B0}.Release|Any CPU.ActiveCfg = Release|Any CPU + {208C1A2E-1969-4842-BE32-13FE9A8802B0}.Release|Any CPU.Build.0 = Release|Any CPU + {7631EF04-BAD9-44D7-80C5-6017EDEA7E14}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {7631EF04-BAD9-44D7-80C5-6017EDEA7E14}.Debug|Any CPU.Build.0 = Debug|Any CPU + {7631EF04-BAD9-44D7-80C5-6017EDEA7E14}.Release|Any CPU.ActiveCfg = Release|Any CPU + {7631EF04-BAD9-44D7-80C5-6017EDEA7E14}.Release|Any CPU.Build.0 = Release|Any CPU EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE diff --git a/SoftwareInstallation/SoftwareInstallation/Program.cs b/SoftwareInstallation/SoftwareInstallation/Program.cs index 1b6b0b8..cf7b6fb 100644 --- a/SoftwareInstallation/SoftwareInstallation/Program.cs +++ b/SoftwareInstallation/SoftwareInstallation/Program.cs @@ -1,4 +1,4 @@ -using AbstractSoftwareInstallationFileImplement.Implements; +using AbstractSoftwareInstallationDatabaseImplement.Implements; using AbstractSoftwareInstallationBusinessLogic; using AbstractSoftwareInstallationBusinessLogic.BusinessLogic; using AbstractSoftwareInstallationContracts.BusinessLogicsContracts; diff --git a/SoftwareInstallation/SoftwareInstallation/SoftwareInstallationView.csproj b/SoftwareInstallation/SoftwareInstallation/SoftwareInstallationView.csproj index e5ca85c..9b0ae37 100644 --- a/SoftwareInstallation/SoftwareInstallation/SoftwareInstallationView.csproj +++ b/SoftwareInstallation/SoftwareInstallation/SoftwareInstallationView.csproj @@ -21,6 +21,7 @@ + From 4326593e9ce28add32340eef70ceae7deea057a4 Mon Sep 17 00:00:00 2001 From: devil_1nc Date: Wed, 19 Apr 2023 18:49:18 +0400 Subject: [PATCH 2/7] lab3 done --- .../BusinessLogic/OrderLogic.cs | 2 +- .../AbstractSoftwareInstallationDatabase.cs | 2 +- .../Implements/OrderStorage.cs | 34 +++--- .../Implements/PackageStorage.cs | 112 ++++++++---------- .../Implements/SoftwareStorage.cs | 37 +++--- ...ner.cs => 20230419141439_Init.Designer.cs} | 53 ++++----- ...0744_Initial.cs => 20230419141439_Init.cs} | 45 ++++--- ...ftwareInstallationDatabaseModelSnapshot.cs | 57 +++++---- .../Models/Order.cs | 7 +- .../Models/Package.cs | 59 ++++----- .../Models/Software.cs | 18 +-- SoftwareInstallation/SoftwareInstallation.sln | 8 +- .../FormCreateOrder.Designer.cs | 8 +- .../SoftwareInstallation/FormCreateOrder.cs | 2 +- .../SoftwareInstallation/FormMain.Designer.cs | 8 +- .../SoftwareInstallation/FormMain.cs | 2 +- .../FormPackage.Designer.cs | 8 +- .../SoftwareInstallation/FormPackage.cs | 2 +- .../FormPackageSoftware.Designer.cs | 8 +- .../FormPackageSoftware.cs | 2 +- .../FormPackages.Designer.cs | 8 +- .../SoftwareInstallation/FormPackages.cs | 2 +- .../FormSoftware.Designer.cs | 8 +- .../SoftwareInstallation/FormSoftware.cs | 2 +- .../FormSoftwares.Designer.cs | 8 +- .../SoftwareInstallation/FormSoftwares.cs | 2 +- 26 files changed, 239 insertions(+), 265 deletions(-) rename SoftwareInstallation/AbstractSoftwareInstallationDatabaseImplement/Migrations/{20230409100744_Initial.Designer.cs => 20230419141439_Init.Designer.cs} (74%) rename SoftwareInstallation/AbstractSoftwareInstallationDatabaseImplement/Migrations/{20230409100744_Initial.cs => 20230419141439_Init.cs} (64%) diff --git a/SoftwareInstallation/AbstractSoftwareInstallationBusinessLogic/BusinessLogic/OrderLogic.cs b/SoftwareInstallation/AbstractSoftwareInstallationBusinessLogic/BusinessLogic/OrderLogic.cs index e10fa1b..d815dd4 100644 --- a/SoftwareInstallation/AbstractSoftwareInstallationBusinessLogic/BusinessLogic/OrderLogic.cs +++ b/SoftwareInstallation/AbstractSoftwareInstallationBusinessLogic/BusinessLogic/OrderLogic.cs @@ -39,7 +39,7 @@ namespace AbstractSoftwareInstallationBusinessLogic.BusinessLogic { throw new ArgumentNullException("Сумма заказа должна быть больше 0", nameof(model.Sum)); } - _logger.LogInformation("Order. OrderID:{Id}. Sum:{ Sum}. SushiId: { SushiId}", model.Id, model.Sum, model.PackageId); + _logger.LogInformation("Order. OrderID:{Id}. Sum:{ Sum}. PackageId: { PackageId}", model.Id, model.Sum, model.PackageId); } public List? ReadList(OrderSearchModel? model) diff --git a/SoftwareInstallation/AbstractSoftwareInstallationDatabaseImplement/AbstractSoftwareInstallationDatabase.cs b/SoftwareInstallation/AbstractSoftwareInstallationDatabaseImplement/AbstractSoftwareInstallationDatabase.cs index 2f41e0f..d13a7e6 100644 --- a/SoftwareInstallation/AbstractSoftwareInstallationDatabaseImplement/AbstractSoftwareInstallationDatabase.cs +++ b/SoftwareInstallation/AbstractSoftwareInstallationDatabaseImplement/AbstractSoftwareInstallationDatabase.cs @@ -16,7 +16,7 @@ optionsBuilder) { if (optionsBuilder.IsConfigured == false) { - optionsBuilder.UseNpgsql("Host = localhost; Port = 5432; Database = SoftwareInstallation; Username = postgres; Password = postgres"); + optionsBuilder.UseSqlServer(@"Data Source=DESKTOP-QA8P9OJ;Initial Catalog=SogtwareInstallation;Integrated Security=True;MultipleActiveResultSets=True;TrustServerCertificate=True"); } base.OnConfiguring(optionsBuilder); } diff --git a/SoftwareInstallation/AbstractSoftwareInstallationDatabaseImplement/Implements/OrderStorage.cs b/SoftwareInstallation/AbstractSoftwareInstallationDatabaseImplement/Implements/OrderStorage.cs index 18adebc..97c0da9 100644 --- a/SoftwareInstallation/AbstractSoftwareInstallationDatabaseImplement/Implements/OrderStorage.cs +++ b/SoftwareInstallation/AbstractSoftwareInstallationDatabaseImplement/Implements/OrderStorage.cs @@ -14,6 +14,19 @@ namespace AbstractSoftwareInstallationDatabaseImplement.Implements { public class OrderStorage : IOrderStorage { + public OrderViewModel? Delete(OrderBindingModel model) + { + using var context = new AbstractSoftwareInstallationDatabase(); + 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) { if (!model.Id.HasValue) @@ -41,12 +54,16 @@ namespace AbstractSoftwareInstallationDatabaseImplement.Implements public List GetFullList() { using var context = new AbstractSoftwareInstallationDatabase(); - return context.Orders.Include(x => x.Package).Select(x => x.GetViewModel).ToList(); + return context.Orders + .Include(x => x.Package) + .Select(x => x.GetViewModel) + .ToList(); } public OrderViewModel? Insert(OrderBindingModel model) { var newOrder = Order.Create(model); + if (newOrder == null) { return null; @@ -55,6 +72,7 @@ namespace AbstractSoftwareInstallationDatabaseImplement.Implements context.Orders.Add(newOrder); context.SaveChanges(); return context.Orders.Include(x => x.Package).FirstOrDefault(x => x.Id == newOrder.Id)?.GetViewModel; + } public OrderViewModel? Update(OrderBindingModel model) @@ -67,19 +85,7 @@ namespace AbstractSoftwareInstallationDatabaseImplement.Implements } order.Update(model); context.SaveChanges(); - return context.Orders.Include(x => x.Package).FirstOrDefault(x => x.Id == model.Id)?.GetViewModel; - } - public OrderViewModel? Delete(OrderBindingModel model) - { - using var context = new AbstractSoftwareInstallationDatabase(); - var element = context.Orders.FirstOrDefault(rec => rec.Id == model.Id); - if (element != null) - { - context.Orders.Remove(element); - context.SaveChanges(); - return element.GetViewModel; - } - return null; + return context.Orders.Include(x => x.Package).FirstOrDefault(x => x.Id == order.Id)?.GetViewModel; } } } diff --git a/SoftwareInstallation/AbstractSoftwareInstallationDatabaseImplement/Implements/PackageStorage.cs b/SoftwareInstallation/AbstractSoftwareInstallationDatabaseImplement/Implements/PackageStorage.cs index fee68fa..f692d22 100644 --- a/SoftwareInstallation/AbstractSoftwareInstallationDatabaseImplement/Implements/PackageStorage.cs +++ b/SoftwareInstallation/AbstractSoftwareInstallationDatabaseImplement/Implements/PackageStorage.cs @@ -14,19 +14,15 @@ namespace AbstractSoftwareInstallationDatabaseImplement.Implements { public class PackageStorage : IPackageStorage { - public PackageViewModel? GetElement(PackageSearchModel model) + public List GetFullList() { - if (string.IsNullOrEmpty(model.PackageName) && !model.Id.HasValue) - { - return null; - } using var context = new AbstractSoftwareInstallationDatabase(); - return context.Packages.Include(x => x.Softwares) - .ThenInclude(x => x.Software) - .FirstOrDefault(x => (!string.IsNullOrEmpty(model.PackageName) && - x.PackageName == model.PackageName) || - (model.Id.HasValue && x.Id == model.Id)) - ?.GetViewModel; + return context.Packages + .Include(x => x.Softwares) + .ThenInclude(x => x.Software) + .ToList() + .Select(x => x.GetViewModel) + .ToList(); } public List GetFilteredList(PackageSearchModel model) @@ -37,86 +33,74 @@ namespace AbstractSoftwareInstallationDatabaseImplement.Implements } using var context = new AbstractSoftwareInstallationDatabase(); return context.Packages - .Include(x => x.Softwares) - .ThenInclude(x => x.Software) - .Where(x => x.PackageName.Contains(model.PackageName)) - .ToList() - .Select(x => x.GetViewModel) - .ToList(); + .Include(x => x.Softwares) + .ThenInclude(x => x.Software) + .Where(x => x.PackageName.Contains(model.PackageName)) + .ToList() + .Select(x => x.GetViewModel) + .ToList(); } - public List GetFullList() + public PackageViewModel? GetElement(PackageSearchModel model) { + if (string.IsNullOrEmpty(model.PackageName) && + !model.Id.HasValue) + { + return null; + } using var context = new AbstractSoftwareInstallationDatabase(); return context.Packages - .Include(x => x.Softwares) - .ThenInclude(x => x.Software) - .ToList() - .Select(x => x.GetViewModel) - .ToList(); + .Include(x => x.Softwares) + .ThenInclude(x => x.Software) + .FirstOrDefault(x => (!string.IsNullOrEmpty(model.PackageName) + && x.PackageName == model.PackageName) + || (model.Id.HasValue && x.Id == model.Id)) + ?.GetViewModel; } public PackageViewModel? Insert(PackageBindingModel model) { using var context = new AbstractSoftwareInstallationDatabase(); - using var transaction = context.Database.BeginTransaction(); + var newPackage = Package.Create(context, model); + if (newPackage == null) { - try - { - var newDoc = Package.Create(context, model); - if (newDoc == null) - { - transaction.Rollback(); - return null; - } - context.Packages.Add(newDoc); - - context.SaveChanges(); - context.Database.CommitTransaction(); - - return newDoc.GetViewModel; - } - catch (Exception) - { - transaction.Rollback(); - return null; - } + return null; } + context.Packages.Add(newPackage); + context.SaveChanges(); + return newPackage.GetViewModel; } public PackageViewModel? Update(PackageBindingModel model) { using var context = new AbstractSoftwareInstallationDatabase(); using var transaction = context.Database.BeginTransaction(); + try { - try + var Package = context.Packages.FirstOrDefault(rec => rec.Id == model.Id); + if (Package == null) { - var Package = context.Packages.FirstOrDefault(x => x.Id == model.Id); - if (Package == null) - { - transaction.Rollback(); - return null; - } - - Package.Update(model); - Package.UpdateSoftwares(context, model); - - context.SaveChanges(); - context.Database.CommitTransaction(); - - return Package.GetViewModel; - } - catch (Exception) - { - transaction.Rollback(); return null; } + Package.Update(model); + context.SaveChanges(); + Package.UpdateSoftwares(context, model); + transaction.Commit(); + return Package.GetViewModel; + } + catch + { + transaction.Rollback(); + throw; } } + public PackageViewModel? Delete(PackageBindingModel model) { using var context = new AbstractSoftwareInstallationDatabase(); - var element = context.Packages.FirstOrDefault(rec => rec.Id == model.Id); + var element = context.Packages + .Include(x => x.Softwares) + .FirstOrDefault(rec => rec.Id == model.Id); if (element != null) { context.Packages.Remove(element); diff --git a/SoftwareInstallation/AbstractSoftwareInstallationDatabaseImplement/Implements/SoftwareStorage.cs b/SoftwareInstallation/AbstractSoftwareInstallationDatabaseImplement/Implements/SoftwareStorage.cs index 1a34700..80d382f 100644 --- a/SoftwareInstallation/AbstractSoftwareInstallationDatabaseImplement/Implements/SoftwareStorage.cs +++ b/SoftwareInstallation/AbstractSoftwareInstallationDatabaseImplement/Implements/SoftwareStorage.cs @@ -13,17 +13,12 @@ namespace AbstractSoftwareInstallationDatabaseImplement.Implements { public class SoftwareStorage : ISoftwareStorage { - public SoftwareViewModel? GetElement(SoftwareSearchModel model) + public List GetFullList() { - if (string.IsNullOrEmpty(model.SoftwareName) && !model.Id.HasValue) - { - return null; - } using var context = new AbstractSoftwareInstallationDatabase(); - return context.Softwares.FirstOrDefault(x => - (!string.IsNullOrEmpty(model.SoftwareName) && x.SoftwareName == model.SoftwareName) - || (model.Id.HasValue && x.Id == model.Id))?.GetViewModel; - + return context.Softwares + .Select(x => x.GetViewModel) + .ToList(); } public List GetFilteredList(SoftwareSearchModel model) @@ -34,16 +29,23 @@ namespace AbstractSoftwareInstallationDatabaseImplement.Implements } using var context = new AbstractSoftwareInstallationDatabase(); return context.Softwares - .Where(x => x.SoftwareName.Contains(model.SoftwareName)) - .Select(x => x.GetViewModel) - .ToList(); - + .Where(x => x.SoftwareName.Contains(model.SoftwareName)) + .Select(x => x.GetViewModel) + .ToList(); } - public List GetFullList() + public SoftwareViewModel? GetElement(SoftwareSearchModel model) { + if (string.IsNullOrEmpty(model.SoftwareName) && !model.Id.HasValue) + { + return null; + } using var context = new AbstractSoftwareInstallationDatabase(); - return context.Softwares.Select(x => x.GetViewModel).ToList(); + return context.Softwares + .FirstOrDefault(x => (!string.IsNullOrEmpty(model.SoftwareName) + && x.SoftwareName == model.SoftwareName) + || (model.Id.HasValue && x.Id == model.Id)) + ?.GetViewModel; } public SoftwareViewModel? Insert(SoftwareBindingModel model) @@ -57,7 +59,6 @@ namespace AbstractSoftwareInstallationDatabaseImplement.Implements context.Softwares.Add(newSoftware); context.SaveChanges(); return newSoftware.GetViewModel; - } public SoftwareViewModel? Update(SoftwareBindingModel model) @@ -72,6 +73,7 @@ namespace AbstractSoftwareInstallationDatabaseImplement.Implements context.SaveChanges(); return Software.GetViewModel; } + public SoftwareViewModel? Delete(SoftwareBindingModel model) { using var context = new AbstractSoftwareInstallationDatabase(); @@ -83,9 +85,6 @@ namespace AbstractSoftwareInstallationDatabaseImplement.Implements return element.GetViewModel; } return null; - } - - } } diff --git a/SoftwareInstallation/AbstractSoftwareInstallationDatabaseImplement/Migrations/20230409100744_Initial.Designer.cs b/SoftwareInstallation/AbstractSoftwareInstallationDatabaseImplement/Migrations/20230419141439_Init.Designer.cs similarity index 74% rename from SoftwareInstallation/AbstractSoftwareInstallationDatabaseImplement/Migrations/20230409100744_Initial.Designer.cs rename to SoftwareInstallation/AbstractSoftwareInstallationDatabaseImplement/Migrations/20230419141439_Init.Designer.cs index b5332f9..ba3d063 100644 --- a/SoftwareInstallation/AbstractSoftwareInstallationDatabaseImplement/Migrations/20230409100744_Initial.Designer.cs +++ b/SoftwareInstallation/AbstractSoftwareInstallationDatabaseImplement/Migrations/20230419141439_Init.Designer.cs @@ -3,17 +3,17 @@ using System; using AbstractSoftwareInstallationDatabaseImplement; using Microsoft.EntityFrameworkCore; using Microsoft.EntityFrameworkCore.Infrastructure; +using Microsoft.EntityFrameworkCore.Metadata; using Microsoft.EntityFrameworkCore.Migrations; using Microsoft.EntityFrameworkCore.Storage.ValueConversion; -using Npgsql.EntityFrameworkCore.PostgreSQL.Metadata; #nullable disable namespace AbstractSoftwareInstallationDatabaseImplement.Migrations { [DbContext(typeof(AbstractSoftwareInstallationDatabase))] - [Migration("20230409100744_Initial")] - partial class Initial + [Migration("20230419141439_Init")] + partial class Init { /// protected override void BuildTargetModel(ModelBuilder modelBuilder) @@ -21,36 +21,35 @@ namespace AbstractSoftwareInstallationDatabaseImplement.Migrations #pragma warning disable 612, 618 modelBuilder .HasAnnotation("ProductVersion", "7.0.4") - .HasAnnotation("Relational:MaxIdentifierLength", 63); + .HasAnnotation("Relational:MaxIdentifierLength", 128); - NpgsqlModelBuilderExtensions.UseIdentityByDefaultColumns(modelBuilder); + SqlServerModelBuilderExtensions.UseIdentityColumns(modelBuilder); modelBuilder.Entity("AbstractPackageInstallationDatabaseImplement.Models.Order", b => { b.Property("Id") .ValueGeneratedOnAdd() - .HasColumnType("integer"); + .HasColumnType("int"); - NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property("Id")); + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); b.Property("Count") - .HasColumnType("integer"); + .HasColumnType("int"); b.Property("DateCreate") - .HasColumnType("timestamp with time zone"); + .HasColumnType("datetime2"); b.Property("DateImplement") - .IsRequired() - .HasColumnType("timestamp with time zone"); + .HasColumnType("datetime2"); b.Property("PackageId") - .HasColumnType("integer"); + .HasColumnType("int"); b.Property("Status") - .HasColumnType("integer"); + .HasColumnType("int"); b.Property("Sum") - .HasColumnType("double precision"); + .HasColumnType("float"); b.HasKey("Id"); @@ -63,16 +62,16 @@ namespace AbstractSoftwareInstallationDatabaseImplement.Migrations { b.Property("Id") .ValueGeneratedOnAdd() - .HasColumnType("integer"); + .HasColumnType("int"); - NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property("Id")); + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); b.Property("PackageName") .IsRequired() - .HasColumnType("text"); + .HasColumnType("nvarchar(max)"); b.Property("Price") - .HasColumnType("double precision"); + .HasColumnType("float"); b.HasKey("Id"); @@ -83,18 +82,18 @@ namespace AbstractSoftwareInstallationDatabaseImplement.Migrations { b.Property("Id") .ValueGeneratedOnAdd() - .HasColumnType("integer"); + .HasColumnType("int"); - NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property("Id")); + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); b.Property("Count") - .HasColumnType("integer"); + .HasColumnType("int"); b.Property("PackageId") - .HasColumnType("integer"); + .HasColumnType("int"); b.Property("SoftwareId") - .HasColumnType("integer"); + .HasColumnType("int"); b.HasKey("Id"); @@ -109,16 +108,16 @@ namespace AbstractSoftwareInstallationDatabaseImplement.Migrations { b.Property("Id") .ValueGeneratedOnAdd() - .HasColumnType("integer"); + .HasColumnType("int"); - NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property("Id")); + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); b.Property("Cost") - .HasColumnType("double precision"); + .HasColumnType("float"); b.Property("SoftwareName") .IsRequired() - .HasColumnType("text"); + .HasColumnType("nvarchar(max)"); b.HasKey("Id"); diff --git a/SoftwareInstallation/AbstractSoftwareInstallationDatabaseImplement/Migrations/20230409100744_Initial.cs b/SoftwareInstallation/AbstractSoftwareInstallationDatabaseImplement/Migrations/20230419141439_Init.cs similarity index 64% rename from SoftwareInstallation/AbstractSoftwareInstallationDatabaseImplement/Migrations/20230409100744_Initial.cs rename to SoftwareInstallation/AbstractSoftwareInstallationDatabaseImplement/Migrations/20230419141439_Init.cs index 669d2c6..28f3761 100644 --- a/SoftwareInstallation/AbstractSoftwareInstallationDatabaseImplement/Migrations/20230409100744_Initial.cs +++ b/SoftwareInstallation/AbstractSoftwareInstallationDatabaseImplement/Migrations/20230419141439_Init.cs @@ -1,13 +1,12 @@ using System; using Microsoft.EntityFrameworkCore.Migrations; -using Npgsql.EntityFrameworkCore.PostgreSQL.Metadata; #nullable disable namespace AbstractSoftwareInstallationDatabaseImplement.Migrations { /// - public partial class Initial : Migration + public partial class Init : Migration { /// protected override void Up(MigrationBuilder migrationBuilder) @@ -16,10 +15,10 @@ namespace AbstractSoftwareInstallationDatabaseImplement.Migrations name: "Packages", columns: table => new { - Id = table.Column(type: "integer", nullable: false) - .Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn), - PackageName = table.Column(type: "text", nullable: false), - Price = table.Column(type: "double precision", nullable: false) + Id = table.Column(type: "int", nullable: false) + .Annotation("SqlServer:Identity", "1, 1"), + PackageName = table.Column(type: "nvarchar(max)", nullable: false), + Price = table.Column(type: "float", nullable: false) }, constraints: table => { @@ -30,10 +29,10 @@ namespace AbstractSoftwareInstallationDatabaseImplement.Migrations name: "Softwares", columns: table => new { - Id = table.Column(type: "integer", nullable: false) - .Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn), - SoftwareName = table.Column(type: "text", nullable: false), - Cost = table.Column(type: "double precision", nullable: false) + Id = table.Column(type: "int", nullable: false) + .Annotation("SqlServer:Identity", "1, 1"), + SoftwareName = table.Column(type: "nvarchar(max)", nullable: false), + Cost = table.Column(type: "float", nullable: false) }, constraints: table => { @@ -44,14 +43,14 @@ namespace AbstractSoftwareInstallationDatabaseImplement.Migrations name: "Orders", columns: table => new { - Id = table.Column(type: "integer", nullable: false) - .Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn), - PackageId = table.Column(type: "integer", nullable: false), - Count = table.Column(type: "integer", nullable: false), - Sum = table.Column(type: "double precision", nullable: false), - Status = table.Column(type: "integer", nullable: false), - DateCreate = table.Column(type: "timestamp with time zone", nullable: false), - DateImplement = table.Column(type: "timestamp with time zone", nullable: false) + Id = table.Column(type: "int", nullable: false) + .Annotation("SqlServer:Identity", "1, 1"), + PackageId = 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 => { @@ -68,11 +67,11 @@ namespace AbstractSoftwareInstallationDatabaseImplement.Migrations name: "PackageSoftwares", columns: table => new { - Id = table.Column(type: "integer", nullable: false) - .Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn), - PackageId = table.Column(type: "integer", nullable: false), - SoftwareId = table.Column(type: "integer", nullable: false), - Count = table.Column(type: "integer", nullable: false) + Id = table.Column(type: "int", nullable: false) + .Annotation("SqlServer:Identity", "1, 1"), + PackageId = table.Column(type: "int", nullable: false), + SoftwareId = table.Column(type: "int", nullable: false), + Count = table.Column(type: "int", nullable: false) }, constraints: table => { diff --git a/SoftwareInstallation/AbstractSoftwareInstallationDatabaseImplement/Migrations/AbstractSoftwareInstallationDatabaseModelSnapshot.cs b/SoftwareInstallation/AbstractSoftwareInstallationDatabaseImplement/Migrations/AbstractSoftwareInstallationDatabaseModelSnapshot.cs index 9f9f358..211c487 100644 --- a/SoftwareInstallation/AbstractSoftwareInstallationDatabaseImplement/Migrations/AbstractSoftwareInstallationDatabaseModelSnapshot.cs +++ b/SoftwareInstallation/AbstractSoftwareInstallationDatabaseImplement/Migrations/AbstractSoftwareInstallationDatabaseModelSnapshot.cs @@ -3,8 +3,8 @@ using System; using AbstractSoftwareInstallationDatabaseImplement; using Microsoft.EntityFrameworkCore; using Microsoft.EntityFrameworkCore.Infrastructure; +using Microsoft.EntityFrameworkCore.Metadata; using Microsoft.EntityFrameworkCore.Storage.ValueConversion; -using Npgsql.EntityFrameworkCore.PostgreSQL.Metadata; #nullable disable @@ -18,80 +18,79 @@ namespace AbstractSoftwareInstallationDatabaseImplement.Migrations #pragma warning disable 612, 618 modelBuilder .HasAnnotation("ProductVersion", "7.0.4") - .HasAnnotation("Relational:MaxIdentifierLength", 63); + .HasAnnotation("Relational:MaxIdentifierLength", 128); - NpgsqlModelBuilderExtensions.UseIdentityByDefaultColumns(modelBuilder); + SqlServerModelBuilderExtensions.UseIdentityColumns(modelBuilder); modelBuilder.Entity("AbstractPackageInstallationDatabaseImplement.Models.Order", b => { b.Property("Id") .ValueGeneratedOnAdd() - .HasColumnType("integer"); + .HasColumnType("int"); - NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property("Id")); + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); b.Property("Count") - .HasColumnType("integer"); + .HasColumnType("int"); b.Property("DateCreate") - .HasColumnType("timestamp with time zone"); + .HasColumnType("datetime2"); b.Property("DateImplement") - .IsRequired() - .HasColumnType("timestamp with time zone"); + .HasColumnType("datetime2"); b.Property("PackageId") - .HasColumnType("integer"); + .HasColumnType("int"); b.Property("Status") - .HasColumnType("integer"); + .HasColumnType("int"); b.Property("Sum") - .HasColumnType("double precision"); + .HasColumnType("float"); b.HasKey("Id"); b.HasIndex("PackageId"); - b.ToTable("Orders", (string)null); + b.ToTable("Orders"); }); modelBuilder.Entity("AbstractSoftwareInstallationDatabaseImplement.Models.Package", b => { b.Property("Id") .ValueGeneratedOnAdd() - .HasColumnType("integer"); + .HasColumnType("int"); - NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property("Id")); + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); b.Property("PackageName") .IsRequired() - .HasColumnType("text"); + .HasColumnType("nvarchar(max)"); b.Property("Price") - .HasColumnType("double precision"); + .HasColumnType("float"); b.HasKey("Id"); - b.ToTable("Packages", (string)null); + b.ToTable("Packages"); }); modelBuilder.Entity("AbstractSoftwareInstallationDatabaseImplement.Models.PackageSoftware", b => { b.Property("Id") .ValueGeneratedOnAdd() - .HasColumnType("integer"); + .HasColumnType("int"); - NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property("Id")); + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); b.Property("Count") - .HasColumnType("integer"); + .HasColumnType("int"); b.Property("PackageId") - .HasColumnType("integer"); + .HasColumnType("int"); b.Property("SoftwareId") - .HasColumnType("integer"); + .HasColumnType("int"); b.HasKey("Id"); @@ -99,27 +98,27 @@ namespace AbstractSoftwareInstallationDatabaseImplement.Migrations b.HasIndex("SoftwareId"); - b.ToTable("PackageSoftwares", (string)null); + b.ToTable("PackageSoftwares"); }); modelBuilder.Entity("AbstractSoftwareInstallationDatabaseImplement.Models.Software", b => { b.Property("Id") .ValueGeneratedOnAdd() - .HasColumnType("integer"); + .HasColumnType("int"); - NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property("Id")); + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); b.Property("Cost") - .HasColumnType("double precision"); + .HasColumnType("float"); b.Property("SoftwareName") .IsRequired() - .HasColumnType("text"); + .HasColumnType("nvarchar(max)"); b.HasKey("Id"); - b.ToTable("Softwares", (string)null); + b.ToTable("Softwares"); }); modelBuilder.Entity("AbstractPackageInstallationDatabaseImplement.Models.Order", b => diff --git a/SoftwareInstallation/AbstractSoftwareInstallationDatabaseImplement/Models/Order.cs b/SoftwareInstallation/AbstractSoftwareInstallationDatabaseImplement/Models/Order.cs index 941b087..86f0e7f 100644 --- a/SoftwareInstallation/AbstractSoftwareInstallationDatabaseImplement/Models/Order.cs +++ b/SoftwareInstallation/AbstractSoftwareInstallationDatabaseImplement/Models/Order.cs @@ -1,5 +1,6 @@ using AbstractSoftwareInstallationContracts.BindingModels; using AbstractSoftwareInstallationContracts.ViewModels; +using AbstractSoftwareInstallationDatabaseImplement; using AbstractSoftwareInstallationDatabaseImplement.Models; using AbstractSoftwareInstallationDataModels; using AbstractSoftwareInstallationDataModels.Models; @@ -43,7 +44,7 @@ namespace AbstractPackageInstallationDatabaseImplement.Models Status = model.Status, DateCreate = model.DateCreate, DateImplement = model.DateImplement, - Id = model.Id, + Id = model.Id }; } @@ -59,13 +60,13 @@ namespace AbstractPackageInstallationDatabaseImplement.Models public OrderViewModel GetViewModel => new() { + Id = Id, PackageId = PackageId, Count = Count, Sum = Sum, + Status = Status, DateCreate = DateCreate, DateImplement = DateImplement, - Id = Id, - Status = Status, PackageName = Package.PackageName }; } diff --git a/SoftwareInstallation/AbstractSoftwareInstallationDatabaseImplement/Models/Package.cs b/SoftwareInstallation/AbstractSoftwareInstallationDatabaseImplement/Models/Package.cs index 5879a81..e2578bb 100644 --- a/SoftwareInstallation/AbstractSoftwareInstallationDatabaseImplement/Models/Package.cs +++ b/SoftwareInstallation/AbstractSoftwareInstallationDatabaseImplement/Models/Package.cs @@ -1,6 +1,8 @@ using AbstractPackageInstallationDatabaseImplement.Models; using AbstractSoftwareInstallationContracts.BindingModels; using AbstractSoftwareInstallationContracts.ViewModels; +using AbstractSoftwareInstallationDatabaseImplement.Models; +using AbstractSoftwareInstallationDataModels; using AbstractSoftwareInstallationDataModels.Models; using System; using System.Collections.Generic; @@ -14,47 +16,50 @@ namespace AbstractSoftwareInstallationDatabaseImplement.Models { public class Package : IPackageModel { - public int Id { get; set; } + public int Id { get; private set; } [Required] - public string PackageName { get; set; } = string.Empty; + public string PackageName { get; private set; } = string.Empty; [Required] - public double Price { get; set; } - private Dictionary? _PackageSoftwares = - null; + public double Price { get; private set; } + + private Dictionary? _packageSoftwares = null; + [NotMapped] public Dictionary PackageSoftware { get { - if (_PackageSoftwares == null) + if (_packageSoftwares == null) { - _PackageSoftwares = Softwares - .ToDictionary(recPC => recPC.SoftwareId, recPC => - (recPC.Software as ISoftwareModel, recPC.Count)); + _packageSoftwares = Softwares.ToDictionary(recPC => recPC.SoftwareId, recPC => (recPC.Software as ISoftwareModel, recPC.Count)); } - return _PackageSoftwares; + return _packageSoftwares; } } + [ForeignKey("PackageId")] public virtual List Softwares { get; set; } = new(); [ForeignKey("PackageId")] public virtual List Orders { get; set; } = new(); - public static Package Create(AbstractSoftwareInstallationDatabase context, - PackageBindingModel model) + + + public static Package? Create(AbstractSoftwareInstallationDatabase context, PackageBindingModel model) { + var Softwares = context.Softwares; + return new Package() { Id = model.Id, PackageName = model.PackageName, Price = model.Price, - Softwares = model.PackageSoftware.Select(x => new - PackageSoftware + Softwares = model.PackageSoftware.Select(x => new PackageSoftware { Software = context.Softwares.First(y => y.Id == x.Key), Count = x.Value.Item2 }).ToList() }; } + public void Update(PackageBindingModel model) { PackageName = model.PackageName; @@ -67,37 +72,35 @@ namespace AbstractSoftwareInstallationDatabaseImplement.Models Price = Price, PackageSoftware = PackageSoftware }; - public void UpdateSoftwares(AbstractSoftwareInstallationDatabase context, - PackageBindingModel model) + + public void UpdateSoftwares(AbstractSoftwareInstallationDatabase context, PackageBindingModel model) { - var PackageSoftwares = context.PackageSoftwares.Where(rec => - rec.PackageId == model.Id).ToList(); - if (PackageSoftwares != null && PackageSoftwares.Count > 0) - { // удалили те, которых нет в модели - context.PackageSoftwares.RemoveRange(PackageSoftwares.Where(rec - => !model.PackageSoftware.ContainsKey(rec.SoftwareId))); + var packageSoftwares = context.PackageSoftwares + .Where(rec => rec.PackageId == model.Id).ToList(); + if (packageSoftwares != null && packageSoftwares.Count > 0) + { // удалили те, которых нет в модели + context.PackageSoftwares.RemoveRange(packageSoftwares.Where(rec => !model.PackageSoftware.ContainsKey(rec.SoftwareId))); context.SaveChanges(); // обновили количество у существующих записей - foreach (var updateSoftware in PackageSoftwares) + foreach (var updateSoftware in packageSoftwares) { - updateSoftware.Count = - model.PackageSoftware[updateSoftware.SoftwareId].Item2; + updateSoftware.Count = model.PackageSoftware[updateSoftware.SoftwareId].Item2; model.PackageSoftware.Remove(updateSoftware.SoftwareId); } context.SaveChanges(); } - var Package = context.Packages.First(x => x.Id == Id); + var package = context.Packages.First(x => x.Id == Id); foreach (var pc in model.PackageSoftware) { context.PackageSoftwares.Add(new PackageSoftware { - Package = Package, + Package = package, Software = context.Softwares.First(x => x.Id == pc.Key), Count = pc.Value.Item2 }); context.SaveChanges(); } - _PackageSoftwares = null; + _packageSoftwares = null; } } diff --git a/SoftwareInstallation/AbstractSoftwareInstallationDatabaseImplement/Models/Software.cs b/SoftwareInstallation/AbstractSoftwareInstallationDatabaseImplement/Models/Software.cs index be64827..d7e9151 100644 --- a/SoftwareInstallation/AbstractSoftwareInstallationDatabaseImplement/Models/Software.cs +++ b/SoftwareInstallation/AbstractSoftwareInstallationDatabaseImplement/Models/Software.cs @@ -15,13 +15,12 @@ namespace AbstractSoftwareInstallationDatabaseImplement.Models { public int Id { get; private set; } [Required] - public string SoftwareName { get; private set; } = string.Empty; + public string SoftwareName { get; private set; } = String.Empty; [Required] public double Cost { get; set; } [ForeignKey("SoftwareId")] - public virtual List PackageSoftwares { get; set; } = - new(); - public static Software? Create(SoftwareBindingModel model) + public virtual List PackageSoftwares { get; set; } = new(); + public static Software? Create(SoftwareBindingModel? model) { if (model == null) { @@ -34,16 +33,7 @@ namespace AbstractSoftwareInstallationDatabaseImplement.Models Cost = model.Cost }; } - public static Software Create(SoftwareViewModel model) - { - return new Software - { - Id = model.Id, - SoftwareName = model.SoftwareName, - Cost = model.Cost - }; - } - public void Update(SoftwareBindingModel model) + public void Update(SoftwareBindingModel? model) { if (model == null) { diff --git a/SoftwareInstallation/SoftwareInstallation.sln b/SoftwareInstallation/SoftwareInstallation.sln index c4c8142..059cf38 100644 --- a/SoftwareInstallation/SoftwareInstallation.sln +++ b/SoftwareInstallation/SoftwareInstallation.sln @@ -15,9 +15,7 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "AbstractSoftwareInstallatio EndProject Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "AbstractSoftwareInstallationFileImplement", "AbstractSoftwareInstallationFileImplement\AbstractSoftwareInstallationFileImplement.csproj", "{BEE13C3F-1BB8-46B4-BC87-CFC367E52A77}" EndProject -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "AbstractShopDatabaseImplement", "AbstractShopDatabaseImplement\AbstractShopDatabaseImplement.csproj", "{208C1A2E-1969-4842-BE32-13FE9A8802B0}" -EndProject -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "AbstractSoftwareInstallationDatabaseImplement", "AbstractSoftwareInstallationDatabaseImplement\AbstractSoftwareInstallationDatabaseImplement.csproj", "{7631EF04-BAD9-44D7-80C5-6017EDEA7E14}" +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "AbstractSoftwareInstallationDatabaseImplement", "AbstractSoftwareInstallationDatabaseImplement\AbstractSoftwareInstallationDatabaseImplement.csproj", "{7631EF04-BAD9-44D7-80C5-6017EDEA7E14}" EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution @@ -49,10 +47,6 @@ Global {BEE13C3F-1BB8-46B4-BC87-CFC367E52A77}.Debug|Any CPU.Build.0 = Debug|Any CPU {BEE13C3F-1BB8-46B4-BC87-CFC367E52A77}.Release|Any CPU.ActiveCfg = Release|Any CPU {BEE13C3F-1BB8-46B4-BC87-CFC367E52A77}.Release|Any CPU.Build.0 = Release|Any CPU - {208C1A2E-1969-4842-BE32-13FE9A8802B0}.Debug|Any CPU.ActiveCfg = Debug|Any CPU - {208C1A2E-1969-4842-BE32-13FE9A8802B0}.Debug|Any CPU.Build.0 = Debug|Any CPU - {208C1A2E-1969-4842-BE32-13FE9A8802B0}.Release|Any CPU.ActiveCfg = Release|Any CPU - {208C1A2E-1969-4842-BE32-13FE9A8802B0}.Release|Any CPU.Build.0 = Release|Any CPU {7631EF04-BAD9-44D7-80C5-6017EDEA7E14}.Debug|Any CPU.ActiveCfg = Debug|Any CPU {7631EF04-BAD9-44D7-80C5-6017EDEA7E14}.Debug|Any CPU.Build.0 = Debug|Any CPU {7631EF04-BAD9-44D7-80C5-6017EDEA7E14}.Release|Any CPU.ActiveCfg = Release|Any CPU diff --git a/SoftwareInstallation/SoftwareInstallation/FormCreateOrder.Designer.cs b/SoftwareInstallation/SoftwareInstallation/FormCreateOrder.Designer.cs index 585201a..e1a69d6 100644 --- a/SoftwareInstallation/SoftwareInstallation/FormCreateOrder.Designer.cs +++ b/SoftwareInstallation/SoftwareInstallation/FormCreateOrder.Designer.cs @@ -5,7 +5,7 @@ /// /// Required designer variable. /// - private System.ComponentModel.IContainer components = null; + private System.ComponentModel.IContainer Softwares = null; /// /// Clean up any resources being used. @@ -13,9 +13,9 @@ /// true if managed resources should be disposed; otherwise, false. protected override void Dispose(bool disposing) { - if (disposing && (components != null)) + if (disposing && (Softwares != null)) { - components.Dispose(); + Softwares.Dispose(); } base.Dispose(disposing); } @@ -26,7 +26,7 @@ /// Required method for Designer support - do not modify /// the contents of this method with the code editor. /// - private void InitializeComponent() + private void InitializeSoftware() { this.comboBoxPackage = new System.Windows.Forms.ComboBox(); this.textBoxCount = new System.Windows.Forms.TextBox(); diff --git a/SoftwareInstallation/SoftwareInstallation/FormCreateOrder.cs b/SoftwareInstallation/SoftwareInstallation/FormCreateOrder.cs index 7767d69..b7ac619 100644 --- a/SoftwareInstallation/SoftwareInstallation/FormCreateOrder.cs +++ b/SoftwareInstallation/SoftwareInstallation/FormCreateOrder.cs @@ -12,7 +12,7 @@ namespace SoftwareInstallationView private readonly IOrderLogic _logicO; public FormCreateOrder(ILogger logger, IPackageLogic logicP, IOrderLogic logicO) { - InitializeComponent(); + InitializeSoftware(); _logger = logger; _logicP = logicP; _logicO = logicO; diff --git a/SoftwareInstallation/SoftwareInstallation/FormMain.Designer.cs b/SoftwareInstallation/SoftwareInstallation/FormMain.Designer.cs index bf25c66..a850436 100644 --- a/SoftwareInstallation/SoftwareInstallation/FormMain.Designer.cs +++ b/SoftwareInstallation/SoftwareInstallation/FormMain.Designer.cs @@ -5,7 +5,7 @@ /// /// Required designer variable. /// - private System.ComponentModel.IContainer components = null; + private System.ComponentModel.IContainer Softwares = null; /// /// Clean up any resources being used. @@ -13,9 +13,9 @@ /// true if managed resources should be disposed; otherwise, false. protected override void Dispose(bool disposing) { - if (disposing && (components != null)) + if (disposing && (Softwares != null)) { - components.Dispose(); + Softwares.Dispose(); } base.Dispose(disposing); } @@ -26,7 +26,7 @@ /// Required method for Designer support - do not modify /// the contents of this method with the code editor. /// - private void InitializeComponent() + private void InitializeSoftware() { this.dataGridView = new System.Windows.Forms.DataGridView(); this.buttonCreateOrder = new System.Windows.Forms.Button(); diff --git a/SoftwareInstallation/SoftwareInstallation/FormMain.cs b/SoftwareInstallation/SoftwareInstallation/FormMain.cs index 7151148..0113608 100644 --- a/SoftwareInstallation/SoftwareInstallation/FormMain.cs +++ b/SoftwareInstallation/SoftwareInstallation/FormMain.cs @@ -21,7 +21,7 @@ namespace SoftwareInstallationView public FormMain(ILogger logger, IOrderLogic orderLogic) { - InitializeComponent(); + InitializeSoftware(); _logger = logger; _orderLogic = orderLogic; } diff --git a/SoftwareInstallation/SoftwareInstallation/FormPackage.Designer.cs b/SoftwareInstallation/SoftwareInstallation/FormPackage.Designer.cs index edd7ce3..c67eeb1 100644 --- a/SoftwareInstallation/SoftwareInstallation/FormPackage.Designer.cs +++ b/SoftwareInstallation/SoftwareInstallation/FormPackage.Designer.cs @@ -5,7 +5,7 @@ /// /// Required designer variable. /// - private System.ComponentModel.IContainer components = null; + private System.ComponentModel.IContainer Softwares = null; /// /// Clean up any resources being used. @@ -13,9 +13,9 @@ /// true if managed resources should be disposed; otherwise, false. protected override void Dispose(bool disposing) { - if (disposing && (components != null)) + if (disposing && (Softwares != null)) { - components.Dispose(); + Softwares.Dispose(); } base.Dispose(disposing); } @@ -26,7 +26,7 @@ /// Required method for Designer support - do not modify /// the contents of this method with the code editor. /// - private void InitializeComponent() + private void InitializeSoftware() { this.textBoxName = new System.Windows.Forms.TextBox(); this.textBoxPrice = new System.Windows.Forms.TextBox(); diff --git a/SoftwareInstallation/SoftwareInstallation/FormPackage.cs b/SoftwareInstallation/SoftwareInstallation/FormPackage.cs index 0bc945a..367872b 100644 --- a/SoftwareInstallation/SoftwareInstallation/FormPackage.cs +++ b/SoftwareInstallation/SoftwareInstallation/FormPackage.cs @@ -17,7 +17,7 @@ namespace SoftwareInstallationView public FormPackage(ILogger logger, IPackageLogic logic) { - InitializeComponent(); + InitializeSoftware(); _logger = logger; _logic = logic; _packageSoftwares = new Dictionary(); diff --git a/SoftwareInstallation/SoftwareInstallation/FormPackageSoftware.Designer.cs b/SoftwareInstallation/SoftwareInstallation/FormPackageSoftware.Designer.cs index e6e5ead..129e20e 100644 --- a/SoftwareInstallation/SoftwareInstallation/FormPackageSoftware.Designer.cs +++ b/SoftwareInstallation/SoftwareInstallation/FormPackageSoftware.Designer.cs @@ -5,7 +5,7 @@ /// /// Required designer variable. /// - private System.ComponentModel.IContainer components = null; + private System.ComponentModel.IContainer Softwares = null; /// /// Clean up any resources being used. @@ -13,9 +13,9 @@ /// true if managed resources should be disposed; otherwise, false. protected override void Dispose(bool disposing) { - if (disposing && (components != null)) + if (disposing && (Softwares != null)) { - components.Dispose(); + Softwares.Dispose(); } base.Dispose(disposing); } @@ -26,7 +26,7 @@ /// Required method for Designer support - do not modify /// the contents of this method with the code editor. /// - private void InitializeComponent() + private void InitializeSoftware() { this.textBox1 = new System.Windows.Forms.TextBox(); this.comboBoxSoftware = new System.Windows.Forms.ComboBox(); diff --git a/SoftwareInstallation/SoftwareInstallation/FormPackageSoftware.cs b/SoftwareInstallation/SoftwareInstallation/FormPackageSoftware.cs index 0374af1..9ae7451 100644 --- a/SoftwareInstallation/SoftwareInstallation/FormPackageSoftware.cs +++ b/SoftwareInstallation/SoftwareInstallation/FormPackageSoftware.cs @@ -46,7 +46,7 @@ namespace SoftwareInstallationView public FormPackageSoftware(ISoftwareLogic logic) { - InitializeComponent(); + InitializeSoftware(); _list = logic.ReadList(null); if (_list != null) { diff --git a/SoftwareInstallation/SoftwareInstallation/FormPackages.Designer.cs b/SoftwareInstallation/SoftwareInstallation/FormPackages.Designer.cs index e1bb352..66e6372 100644 --- a/SoftwareInstallation/SoftwareInstallation/FormPackages.Designer.cs +++ b/SoftwareInstallation/SoftwareInstallation/FormPackages.Designer.cs @@ -5,7 +5,7 @@ /// /// Required designer variable. /// - private System.ComponentModel.IContainer components = null; + private System.ComponentModel.IContainer Softwares = null; /// /// Clean up any resources being used. @@ -13,9 +13,9 @@ /// true if managed resources should be disposed; otherwise, false. protected override void Dispose(bool disposing) { - if (disposing && (components != null)) + if (disposing && (Softwares != null)) { - components.Dispose(); + Softwares.Dispose(); } base.Dispose(disposing); } @@ -26,7 +26,7 @@ /// Required method for Designer support - do not modify /// the contents of this method with the code editor. /// - private void InitializeComponent() + private void InitializeSoftware() { this.dataGridView = new System.Windows.Forms.DataGridView(); this.ColumnId = new System.Windows.Forms.DataGridViewTextBoxColumn(); diff --git a/SoftwareInstallation/SoftwareInstallation/FormPackages.cs b/SoftwareInstallation/SoftwareInstallation/FormPackages.cs index acf6220..25e04ed 100644 --- a/SoftwareInstallation/SoftwareInstallation/FormPackages.cs +++ b/SoftwareInstallation/SoftwareInstallation/FormPackages.cs @@ -11,7 +11,7 @@ namespace SoftwareInstallationView private readonly IPackageLogic _logic; public FormPackages(ILogger logger, IPackageLogic logic) { - InitializeComponent(); + InitializeSoftware(); _logger = logger; _logic = logic; LoadData(); diff --git a/SoftwareInstallation/SoftwareInstallation/FormSoftware.Designer.cs b/SoftwareInstallation/SoftwareInstallation/FormSoftware.Designer.cs index 3fba4c6..34da41f 100644 --- a/SoftwareInstallation/SoftwareInstallation/FormSoftware.Designer.cs +++ b/SoftwareInstallation/SoftwareInstallation/FormSoftware.Designer.cs @@ -5,7 +5,7 @@ /// /// Required designer variable. /// - private System.ComponentModel.IContainer components = null; + private System.ComponentModel.IContainer Softwares = null; /// /// Clean up any resources being used. @@ -13,9 +13,9 @@ /// true if managed resources should be disposed; otherwise, false. protected override void Dispose(bool disposing) { - if (disposing && (components != null)) + if (disposing && (Softwares != null)) { - components.Dispose(); + Softwares.Dispose(); } base.Dispose(disposing); } @@ -26,7 +26,7 @@ /// Required method for Designer support - do not modify /// the contents of this method with the code editor. /// - private void InitializeComponent() + private void InitializeSoftware() { this.textBoxName = new System.Windows.Forms.TextBox(); this.textBoxCost = new System.Windows.Forms.TextBox(); diff --git a/SoftwareInstallation/SoftwareInstallation/FormSoftware.cs b/SoftwareInstallation/SoftwareInstallation/FormSoftware.cs index 95bf8d3..1e1b2cc 100644 --- a/SoftwareInstallation/SoftwareInstallation/FormSoftware.cs +++ b/SoftwareInstallation/SoftwareInstallation/FormSoftware.cs @@ -13,7 +13,7 @@ namespace SoftwareInstallation public int Id { set { _id = value; } } public FormSoftware(ILogger logger, ISoftwareLogic logic) { - InitializeComponent(); + InitializeSoftware(); _logger = logger; _logic = logic; } diff --git a/SoftwareInstallation/SoftwareInstallation/FormSoftwares.Designer.cs b/SoftwareInstallation/SoftwareInstallation/FormSoftwares.Designer.cs index a1a85ce..043b06e 100644 --- a/SoftwareInstallation/SoftwareInstallation/FormSoftwares.Designer.cs +++ b/SoftwareInstallation/SoftwareInstallation/FormSoftwares.Designer.cs @@ -5,7 +5,7 @@ /// /// Required designer variable. /// - private System.ComponentModel.IContainer components = null; + private System.ComponentModel.IContainer Softwares = null; /// /// Clean up any resources being used. @@ -13,9 +13,9 @@ /// true if managed resources should be disposed; otherwise, false. protected override void Dispose(bool disposing) { - if (disposing && (components != null)) + if (disposing && (Softwares != null)) { - components.Dispose(); + Softwares.Dispose(); } base.Dispose(disposing); } @@ -26,7 +26,7 @@ /// Required method for Designer support - do not modify /// the contents of this method with the code editor. /// - private void InitializeComponent() + private void InitializeSoftware() { this.buttonAdd = new System.Windows.Forms.Button(); this.buttonEdit = new System.Windows.Forms.Button(); diff --git a/SoftwareInstallation/SoftwareInstallation/FormSoftwares.cs b/SoftwareInstallation/SoftwareInstallation/FormSoftwares.cs index cffd2b8..c7d456f 100644 --- a/SoftwareInstallation/SoftwareInstallation/FormSoftwares.cs +++ b/SoftwareInstallation/SoftwareInstallation/FormSoftwares.cs @@ -9,7 +9,7 @@ namespace SoftwareInstallationView { public FormSoftwares(ILogger logger, ISoftwareLogic logic) { - InitializeComponent(); + InitializeSoftware(); _logger = logger; _logic = logic; LoadData(); From 37e3caa3435af9e392c87b39bd4a740b56f8f2d5 Mon Sep 17 00:00:00 2001 From: devil_1nc Date: Fri, 21 Apr 2023 01:24:38 +0400 Subject: [PATCH 3/7] final fix --- .../BindingModels/PackageBindingModel.cs | 1 - SoftwareInstallation/SoftwareInstallation/FormPackage.cs | 1 + 2 files changed, 1 insertion(+), 1 deletion(-) diff --git a/SoftwareInstallation/AbstractSoftwareInstallationContracts/BindingModels/PackageBindingModel.cs b/SoftwareInstallation/AbstractSoftwareInstallationContracts/BindingModels/PackageBindingModel.cs index 3b2f746..eb4df65 100644 --- a/SoftwareInstallation/AbstractSoftwareInstallationContracts/BindingModels/PackageBindingModel.cs +++ b/SoftwareInstallation/AbstractSoftwareInstallationContracts/BindingModels/PackageBindingModel.cs @@ -13,6 +13,5 @@ namespace AbstractSoftwareInstallationContracts.BindingModels public string PackageName { get; set; } = string.Empty; public double Price { get; set; } public Dictionary PackageSoftware{get;set;} = new(); - public object PackageSoftwares { get; set; } } } diff --git a/SoftwareInstallation/SoftwareInstallation/FormPackage.cs b/SoftwareInstallation/SoftwareInstallation/FormPackage.cs index 367872b..64ed87d 100644 --- a/SoftwareInstallation/SoftwareInstallation/FormPackage.cs +++ b/SoftwareInstallation/SoftwareInstallation/FormPackage.cs @@ -189,6 +189,7 @@ namespace SoftwareInstallationView Id = _id ?? 0, PackageName = textBoxName.Text, Price = Convert.ToDouble(textBoxPrice.Text), + PackageSoftware = _packageSoftwares }; var operationResult = _id.HasValue ? _logic.Update(model) : _logic.Create(model); From 216781295fd417df1c20b0bb22f78318e7fb382b Mon Sep 17 00:00:00 2001 From: Katerina881 Date: Fri, 21 Apr 2023 09:47:25 +0400 Subject: [PATCH 4/7] FormPackage fix --- .../SoftwareInstallation/FormPackage.Designer.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/SoftwareInstallation/SoftwareInstallation/FormPackage.Designer.cs b/SoftwareInstallation/SoftwareInstallation/FormPackage.Designer.cs index c67eeb1..db57d10 100644 --- a/SoftwareInstallation/SoftwareInstallation/FormPackage.Designer.cs +++ b/SoftwareInstallation/SoftwareInstallation/FormPackage.Designer.cs @@ -201,7 +201,7 @@ this.groupBoxSoftware.ResumeLayout(false); this.ResumeLayout(false); this.PerformLayout(); - + this.Load += new System.EventHandler(this.FormPackage_Load); } #endregion From 438f3f24affdad1ab40486361ace32efe2513483 Mon Sep 17 00:00:00 2001 From: devil_1nc Date: Mon, 22 May 2023 21:24:53 +0400 Subject: [PATCH 5/7] fix --- .../AbstractSoftwareInstallationDatabaseImplement.csproj | 9 --------- .../BindingModels/PackageBindingModel.cs | 1 - .../SoftwareInstallation/FormPackage.Designer.cs | 2 +- SoftwareInstallation/SoftwareInstallation/FormPackage.cs | 1 + 4 files changed, 2 insertions(+), 11 deletions(-) delete mode 100644 SoftwareInstallation/AbstractShopDatabaseImplement/AbstractSoftwareInstallationDatabaseImplement.csproj diff --git a/SoftwareInstallation/AbstractShopDatabaseImplement/AbstractSoftwareInstallationDatabaseImplement.csproj b/SoftwareInstallation/AbstractShopDatabaseImplement/AbstractSoftwareInstallationDatabaseImplement.csproj deleted file mode 100644 index 132c02c..0000000 --- a/SoftwareInstallation/AbstractShopDatabaseImplement/AbstractSoftwareInstallationDatabaseImplement.csproj +++ /dev/null @@ -1,9 +0,0 @@ - - - - net6.0 - enable - enable - - - diff --git a/SoftwareInstallation/AbstractSoftwareInstallationContracts/BindingModels/PackageBindingModel.cs b/SoftwareInstallation/AbstractSoftwareInstallationContracts/BindingModels/PackageBindingModel.cs index 3b2f746..eb4df65 100644 --- a/SoftwareInstallation/AbstractSoftwareInstallationContracts/BindingModels/PackageBindingModel.cs +++ b/SoftwareInstallation/AbstractSoftwareInstallationContracts/BindingModels/PackageBindingModel.cs @@ -13,6 +13,5 @@ namespace AbstractSoftwareInstallationContracts.BindingModels public string PackageName { get; set; } = string.Empty; public double Price { get; set; } public Dictionary PackageSoftware{get;set;} = new(); - public object PackageSoftwares { get; set; } } } diff --git a/SoftwareInstallation/SoftwareInstallation/FormPackage.Designer.cs b/SoftwareInstallation/SoftwareInstallation/FormPackage.Designer.cs index c67eeb1..db57d10 100644 --- a/SoftwareInstallation/SoftwareInstallation/FormPackage.Designer.cs +++ b/SoftwareInstallation/SoftwareInstallation/FormPackage.Designer.cs @@ -201,7 +201,7 @@ this.groupBoxSoftware.ResumeLayout(false); this.ResumeLayout(false); this.PerformLayout(); - + this.Load += new System.EventHandler(this.FormPackage_Load); } #endregion diff --git a/SoftwareInstallation/SoftwareInstallation/FormPackage.cs b/SoftwareInstallation/SoftwareInstallation/FormPackage.cs index 367872b..64ed87d 100644 --- a/SoftwareInstallation/SoftwareInstallation/FormPackage.cs +++ b/SoftwareInstallation/SoftwareInstallation/FormPackage.cs @@ -189,6 +189,7 @@ namespace SoftwareInstallationView Id = _id ?? 0, PackageName = textBoxName.Text, Price = Convert.ToDouble(textBoxPrice.Text), + PackageSoftware = _packageSoftwares }; var operationResult = _id.HasValue ? _logic.Update(model) : _logic.Create(model); From 37468b24eb2f894fa784f80c266f88f5f0717737 Mon Sep 17 00:00:00 2001 From: devil_1nc Date: Mon, 22 May 2023 21:30:17 +0400 Subject: [PATCH 6/7] conflict fix act 1 --- .../AbstractSoftwareInstallationDatabase.cs | 28 --- ...ftwareInstallationDatabaseImplement.csproj | 24 --- .../Implements/OrderStorage.cs | 91 ---------- .../Implements/PackageStorage.cs | 113 ------------ .../Implements/SoftwareStorage.cs | 90 --------- .../20230419141439_Init.Designer.cs | 171 ------------------ .../Migrations/20230419141439_Init.cs | 125 ------------- ...ftwareInstallationDatabaseModelSnapshot.cs | 168 ----------------- .../Models/Order.cs | 73 -------- .../Models/Package.cs | 107 ----------- .../Models/PackageSoftware.cs | 22 --- .../Models/Software.cs | 53 ------ 12 files changed, 1065 deletions(-) delete mode 100644 SoftwareInstallation/AbstractSoftwareInstallationDatabaseImplement/AbstractSoftwareInstallationDatabase.cs delete mode 100644 SoftwareInstallation/AbstractSoftwareInstallationDatabaseImplement/AbstractSoftwareInstallationDatabaseImplement.csproj delete mode 100644 SoftwareInstallation/AbstractSoftwareInstallationDatabaseImplement/Implements/OrderStorage.cs delete mode 100644 SoftwareInstallation/AbstractSoftwareInstallationDatabaseImplement/Implements/PackageStorage.cs delete mode 100644 SoftwareInstallation/AbstractSoftwareInstallationDatabaseImplement/Implements/SoftwareStorage.cs delete mode 100644 SoftwareInstallation/AbstractSoftwareInstallationDatabaseImplement/Migrations/20230419141439_Init.Designer.cs delete mode 100644 SoftwareInstallation/AbstractSoftwareInstallationDatabaseImplement/Migrations/20230419141439_Init.cs delete mode 100644 SoftwareInstallation/AbstractSoftwareInstallationDatabaseImplement/Migrations/AbstractSoftwareInstallationDatabaseModelSnapshot.cs delete mode 100644 SoftwareInstallation/AbstractSoftwareInstallationDatabaseImplement/Models/Order.cs delete mode 100644 SoftwareInstallation/AbstractSoftwareInstallationDatabaseImplement/Models/Package.cs delete mode 100644 SoftwareInstallation/AbstractSoftwareInstallationDatabaseImplement/Models/PackageSoftware.cs delete mode 100644 SoftwareInstallation/AbstractSoftwareInstallationDatabaseImplement/Models/Software.cs diff --git a/SoftwareInstallation/AbstractSoftwareInstallationDatabaseImplement/AbstractSoftwareInstallationDatabase.cs b/SoftwareInstallation/AbstractSoftwareInstallationDatabaseImplement/AbstractSoftwareInstallationDatabase.cs deleted file mode 100644 index d13a7e6..0000000 --- a/SoftwareInstallation/AbstractSoftwareInstallationDatabaseImplement/AbstractSoftwareInstallationDatabase.cs +++ /dev/null @@ -1,28 +0,0 @@ -using AbstractPackageInstallationDatabaseImplement.Models; -using AbstractSoftwareInstallationDatabaseImplement.Models; -using Microsoft.EntityFrameworkCore; -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; - -namespace AbstractSoftwareInstallationDatabaseImplement -{ - public class AbstractSoftwareInstallationDatabase : DbContext - { - protected override void OnConfiguring(DbContextOptionsBuilder -optionsBuilder) - { - if (optionsBuilder.IsConfigured == false) - { - optionsBuilder.UseSqlServer(@"Data Source=DESKTOP-QA8P9OJ;Initial Catalog=SogtwareInstallation;Integrated Security=True;MultipleActiveResultSets=True;TrustServerCertificate=True"); - } - base.OnConfiguring(optionsBuilder); - } - public virtual DbSet Softwares { set; get; } - public virtual DbSet Packages { set; get; } - public virtual DbSet PackageSoftwares { set; get; } - public virtual DbSet Orders { set; get; } - } -} diff --git a/SoftwareInstallation/AbstractSoftwareInstallationDatabaseImplement/AbstractSoftwareInstallationDatabaseImplement.csproj b/SoftwareInstallation/AbstractSoftwareInstallationDatabaseImplement/AbstractSoftwareInstallationDatabaseImplement.csproj deleted file mode 100644 index 1f9db50..0000000 --- a/SoftwareInstallation/AbstractSoftwareInstallationDatabaseImplement/AbstractSoftwareInstallationDatabaseImplement.csproj +++ /dev/null @@ -1,24 +0,0 @@ - - - - net6.0 - enable - enable - - - - - - - all - runtime; build; native; contentfiles; analyzers; buildtransitive - - - - - - - - - - diff --git a/SoftwareInstallation/AbstractSoftwareInstallationDatabaseImplement/Implements/OrderStorage.cs b/SoftwareInstallation/AbstractSoftwareInstallationDatabaseImplement/Implements/OrderStorage.cs deleted file mode 100644 index 97c0da9..0000000 --- a/SoftwareInstallation/AbstractSoftwareInstallationDatabaseImplement/Implements/OrderStorage.cs +++ /dev/null @@ -1,91 +0,0 @@ -using AbstractPackageInstallationDatabaseImplement.Models; -using AbstractSoftwareInstallationContracts.BindingModels; -using AbstractSoftwareInstallationContracts.SearchModels; -using AbstractSoftwareInstallationContracts.StoragesContracts; -using AbstractSoftwareInstallationContracts.ViewModels; -using Microsoft.EntityFrameworkCore; -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; - -namespace AbstractSoftwareInstallationDatabaseImplement.Implements -{ - public class OrderStorage : IOrderStorage - { - public OrderViewModel? Delete(OrderBindingModel model) - { - using var context = new AbstractSoftwareInstallationDatabase(); - 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) - { - if (!model.Id.HasValue) - { - return null; - } - using var context = new AbstractSoftwareInstallationDatabase(); - return context.Orders.Include(x => x.Package).FirstOrDefault(x => (model.Id.HasValue && x.Id == model.Id))?.GetViewModel; - } - - public List GetFilteredList(OrderSearchModel model) - { - if (!model.Id.HasValue) - { - return new(); - } - using var context = new AbstractSoftwareInstallationDatabase(); - return context.Orders - .Where(x => x.Id == model.Id) - .Include(x => x.Package) - .Select(x => x.GetViewModel) - .ToList(); - } - - public List GetFullList() - { - using var context = new AbstractSoftwareInstallationDatabase(); - return context.Orders - .Include(x => x.Package) - .Select(x => x.GetViewModel) - .ToList(); - } - - public OrderViewModel? Insert(OrderBindingModel model) - { - var newOrder = Order.Create(model); - - if (newOrder == null) - { - return null; - } - using var context = new AbstractSoftwareInstallationDatabase(); - context.Orders.Add(newOrder); - context.SaveChanges(); - return context.Orders.Include(x => x.Package).FirstOrDefault(x => x.Id == newOrder.Id)?.GetViewModel; - - } - - public OrderViewModel? Update(OrderBindingModel model) - { - using var context = new AbstractSoftwareInstallationDatabase(); - var order = context.Orders.FirstOrDefault(x => x.Id == model.Id); - if (order == null) - { - return null; - } - order.Update(model); - context.SaveChanges(); - return context.Orders.Include(x => x.Package).FirstOrDefault(x => x.Id == order.Id)?.GetViewModel; - } - } -} diff --git a/SoftwareInstallation/AbstractSoftwareInstallationDatabaseImplement/Implements/PackageStorage.cs b/SoftwareInstallation/AbstractSoftwareInstallationDatabaseImplement/Implements/PackageStorage.cs deleted file mode 100644 index f692d22..0000000 --- a/SoftwareInstallation/AbstractSoftwareInstallationDatabaseImplement/Implements/PackageStorage.cs +++ /dev/null @@ -1,113 +0,0 @@ -using AbstractSoftwareInstallationContracts.BindingModels; -using AbstractSoftwareInstallationContracts.SearchModels; -using AbstractSoftwareInstallationContracts.StoragesContracts; -using AbstractSoftwareInstallationContracts.ViewModels; -using AbstractSoftwareInstallationDatabaseImplement.Models; -using Microsoft.EntityFrameworkCore; -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; - -namespace AbstractSoftwareInstallationDatabaseImplement.Implements -{ - public class PackageStorage : IPackageStorage - { - public List GetFullList() - { - using var context = new AbstractSoftwareInstallationDatabase(); - return context.Packages - .Include(x => x.Softwares) - .ThenInclude(x => x.Software) - .ToList() - .Select(x => x.GetViewModel) - .ToList(); - } - - public List GetFilteredList(PackageSearchModel model) - { - if (string.IsNullOrEmpty(model.PackageName)) - { - return new(); - } - using var context = new AbstractSoftwareInstallationDatabase(); - return context.Packages - .Include(x => x.Softwares) - .ThenInclude(x => x.Software) - .Where(x => x.PackageName.Contains(model.PackageName)) - .ToList() - .Select(x => x.GetViewModel) - .ToList(); - } - - public PackageViewModel? GetElement(PackageSearchModel model) - { - if (string.IsNullOrEmpty(model.PackageName) && - !model.Id.HasValue) - { - return null; - } - using var context = new AbstractSoftwareInstallationDatabase(); - return context.Packages - .Include(x => x.Softwares) - .ThenInclude(x => x.Software) - .FirstOrDefault(x => (!string.IsNullOrEmpty(model.PackageName) - && x.PackageName == model.PackageName) - || (model.Id.HasValue && x.Id == model.Id)) - ?.GetViewModel; - } - - public PackageViewModel? Insert(PackageBindingModel model) - { - using var context = new AbstractSoftwareInstallationDatabase(); - var newPackage = Package.Create(context, model); - if (newPackage == null) - { - return null; - } - context.Packages.Add(newPackage); - context.SaveChanges(); - return newPackage.GetViewModel; - } - - public PackageViewModel? Update(PackageBindingModel model) - { - using var context = new AbstractSoftwareInstallationDatabase(); - using var transaction = context.Database.BeginTransaction(); - try - { - var Package = context.Packages.FirstOrDefault(rec => rec.Id == model.Id); - if (Package == null) - { - return null; - } - Package.Update(model); - context.SaveChanges(); - Package.UpdateSoftwares(context, model); - transaction.Commit(); - return Package.GetViewModel; - } - catch - { - transaction.Rollback(); - throw; - } - } - - public PackageViewModel? Delete(PackageBindingModel model) - { - using var context = new AbstractSoftwareInstallationDatabase(); - var element = context.Packages - .Include(x => x.Softwares) - .FirstOrDefault(rec => rec.Id == model.Id); - if (element != null) - { - context.Packages.Remove(element); - context.SaveChanges(); - return element.GetViewModel; - } - return null; - } - } -} diff --git a/SoftwareInstallation/AbstractSoftwareInstallationDatabaseImplement/Implements/SoftwareStorage.cs b/SoftwareInstallation/AbstractSoftwareInstallationDatabaseImplement/Implements/SoftwareStorage.cs deleted file mode 100644 index 80d382f..0000000 --- a/SoftwareInstallation/AbstractSoftwareInstallationDatabaseImplement/Implements/SoftwareStorage.cs +++ /dev/null @@ -1,90 +0,0 @@ -using AbstractSoftwareInstallationContracts.BindingModels; -using AbstractSoftwareInstallationContracts.SearchModels; -using AbstractSoftwareInstallationContracts.StoragesContracts; -using AbstractSoftwareInstallationContracts.ViewModels; -using AbstractSoftwareInstallationDatabaseImplement.Models; -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; - -namespace AbstractSoftwareInstallationDatabaseImplement.Implements -{ - public class SoftwareStorage : ISoftwareStorage - { - public List GetFullList() - { - using var context = new AbstractSoftwareInstallationDatabase(); - return context.Softwares - .Select(x => x.GetViewModel) - .ToList(); - } - - public List GetFilteredList(SoftwareSearchModel model) - { - if (string.IsNullOrEmpty(model.SoftwareName)) - { - return new(); - } - using var context = new AbstractSoftwareInstallationDatabase(); - return context.Softwares - .Where(x => x.SoftwareName.Contains(model.SoftwareName)) - .Select(x => x.GetViewModel) - .ToList(); - } - - public SoftwareViewModel? GetElement(SoftwareSearchModel model) - { - if (string.IsNullOrEmpty(model.SoftwareName) && !model.Id.HasValue) - { - return null; - } - using var context = new AbstractSoftwareInstallationDatabase(); - return context.Softwares - .FirstOrDefault(x => (!string.IsNullOrEmpty(model.SoftwareName) - && x.SoftwareName == model.SoftwareName) - || (model.Id.HasValue && x.Id == model.Id)) - ?.GetViewModel; - } - - public SoftwareViewModel? Insert(SoftwareBindingModel model) - { - var newSoftware = Software.Create(model); - if (newSoftware == null) - { - return null; - } - using var context = new AbstractSoftwareInstallationDatabase(); - context.Softwares.Add(newSoftware); - context.SaveChanges(); - return newSoftware.GetViewModel; - } - - public SoftwareViewModel? Update(SoftwareBindingModel model) - { - using var context = new AbstractSoftwareInstallationDatabase(); - var Software = context.Softwares.FirstOrDefault(x => x.Id == model.Id); - if (Software == null) - { - return null; - } - Software.Update(model); - context.SaveChanges(); - return Software.GetViewModel; - } - - public SoftwareViewModel? Delete(SoftwareBindingModel model) - { - using var context = new AbstractSoftwareInstallationDatabase(); - var element = context.Softwares.FirstOrDefault(rec => rec.Id == model.Id); - if (element != null) - { - context.Softwares.Remove(element); - context.SaveChanges(); - return element.GetViewModel; - } - return null; - } - } -} diff --git a/SoftwareInstallation/AbstractSoftwareInstallationDatabaseImplement/Migrations/20230419141439_Init.Designer.cs b/SoftwareInstallation/AbstractSoftwareInstallationDatabaseImplement/Migrations/20230419141439_Init.Designer.cs deleted file mode 100644 index ba3d063..0000000 --- a/SoftwareInstallation/AbstractSoftwareInstallationDatabaseImplement/Migrations/20230419141439_Init.Designer.cs +++ /dev/null @@ -1,171 +0,0 @@ -// -using System; -using AbstractSoftwareInstallationDatabaseImplement; -using Microsoft.EntityFrameworkCore; -using Microsoft.EntityFrameworkCore.Infrastructure; -using Microsoft.EntityFrameworkCore.Metadata; -using Microsoft.EntityFrameworkCore.Migrations; -using Microsoft.EntityFrameworkCore.Storage.ValueConversion; - -#nullable disable - -namespace AbstractSoftwareInstallationDatabaseImplement.Migrations -{ - [DbContext(typeof(AbstractSoftwareInstallationDatabase))] - [Migration("20230419141439_Init")] - partial class Init - { - /// - protected override void BuildTargetModel(ModelBuilder modelBuilder) - { -#pragma warning disable 612, 618 - modelBuilder - .HasAnnotation("ProductVersion", "7.0.4") - .HasAnnotation("Relational:MaxIdentifierLength", 128); - - SqlServerModelBuilderExtensions.UseIdentityColumns(modelBuilder); - - modelBuilder.Entity("AbstractPackageInstallationDatabaseImplement.Models.Order", b => - { - b.Property("Id") - .ValueGeneratedOnAdd() - .HasColumnType("int"); - - SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); - - b.Property("Count") - .HasColumnType("int"); - - b.Property("DateCreate") - .HasColumnType("datetime2"); - - b.Property("DateImplement") - .HasColumnType("datetime2"); - - b.Property("PackageId") - .HasColumnType("int"); - - b.Property("Status") - .HasColumnType("int"); - - b.Property("Sum") - .HasColumnType("float"); - - b.HasKey("Id"); - - b.HasIndex("PackageId"); - - b.ToTable("Orders"); - }); - - modelBuilder.Entity("AbstractSoftwareInstallationDatabaseImplement.Models.Package", b => - { - b.Property("Id") - .ValueGeneratedOnAdd() - .HasColumnType("int"); - - SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); - - b.Property("PackageName") - .IsRequired() - .HasColumnType("nvarchar(max)"); - - b.Property("Price") - .HasColumnType("float"); - - b.HasKey("Id"); - - b.ToTable("Packages"); - }); - - modelBuilder.Entity("AbstractSoftwareInstallationDatabaseImplement.Models.PackageSoftware", b => - { - b.Property("Id") - .ValueGeneratedOnAdd() - .HasColumnType("int"); - - SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); - - b.Property("Count") - .HasColumnType("int"); - - b.Property("PackageId") - .HasColumnType("int"); - - b.Property("SoftwareId") - .HasColumnType("int"); - - b.HasKey("Id"); - - b.HasIndex("PackageId"); - - b.HasIndex("SoftwareId"); - - b.ToTable("PackageSoftwares"); - }); - - modelBuilder.Entity("AbstractSoftwareInstallationDatabaseImplement.Models.Software", b => - { - b.Property("Id") - .ValueGeneratedOnAdd() - .HasColumnType("int"); - - SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); - - b.Property("Cost") - .HasColumnType("float"); - - b.Property("SoftwareName") - .IsRequired() - .HasColumnType("nvarchar(max)"); - - b.HasKey("Id"); - - b.ToTable("Softwares"); - }); - - modelBuilder.Entity("AbstractPackageInstallationDatabaseImplement.Models.Order", b => - { - b.HasOne("AbstractSoftwareInstallationDatabaseImplement.Models.Package", "Package") - .WithMany("Orders") - .HasForeignKey("PackageId") - .OnDelete(DeleteBehavior.Cascade) - .IsRequired(); - - b.Navigation("Package"); - }); - - modelBuilder.Entity("AbstractSoftwareInstallationDatabaseImplement.Models.PackageSoftware", b => - { - b.HasOne("AbstractSoftwareInstallationDatabaseImplement.Models.Package", "Package") - .WithMany("Softwares") - .HasForeignKey("PackageId") - .OnDelete(DeleteBehavior.Cascade) - .IsRequired(); - - b.HasOne("AbstractSoftwareInstallationDatabaseImplement.Models.Software", "Software") - .WithMany("PackageSoftwares") - .HasForeignKey("SoftwareId") - .OnDelete(DeleteBehavior.Cascade) - .IsRequired(); - - b.Navigation("Package"); - - b.Navigation("Software"); - }); - - modelBuilder.Entity("AbstractSoftwareInstallationDatabaseImplement.Models.Package", b => - { - b.Navigation("Orders"); - - b.Navigation("Softwares"); - }); - - modelBuilder.Entity("AbstractSoftwareInstallationDatabaseImplement.Models.Software", b => - { - b.Navigation("PackageSoftwares"); - }); -#pragma warning restore 612, 618 - } - } -} diff --git a/SoftwareInstallation/AbstractSoftwareInstallationDatabaseImplement/Migrations/20230419141439_Init.cs b/SoftwareInstallation/AbstractSoftwareInstallationDatabaseImplement/Migrations/20230419141439_Init.cs deleted file mode 100644 index 28f3761..0000000 --- a/SoftwareInstallation/AbstractSoftwareInstallationDatabaseImplement/Migrations/20230419141439_Init.cs +++ /dev/null @@ -1,125 +0,0 @@ -using System; -using Microsoft.EntityFrameworkCore.Migrations; - -#nullable disable - -namespace AbstractSoftwareInstallationDatabaseImplement.Migrations -{ - /// - public partial class Init : Migration - { - /// - protected override void Up(MigrationBuilder migrationBuilder) - { - migrationBuilder.CreateTable( - name: "Packages", - columns: table => new - { - Id = table.Column(type: "int", nullable: false) - .Annotation("SqlServer:Identity", "1, 1"), - PackageName = table.Column(type: "nvarchar(max)", nullable: false), - Price = table.Column(type: "float", nullable: false) - }, - constraints: table => - { - table.PrimaryKey("PK_Packages", x => x.Id); - }); - - migrationBuilder.CreateTable( - name: "Softwares", - columns: table => new - { - Id = table.Column(type: "int", nullable: false) - .Annotation("SqlServer:Identity", "1, 1"), - SoftwareName = table.Column(type: "nvarchar(max)", nullable: false), - Cost = table.Column(type: "float", nullable: false) - }, - constraints: table => - { - table.PrimaryKey("PK_Softwares", x => x.Id); - }); - - migrationBuilder.CreateTable( - name: "Orders", - columns: table => new - { - Id = table.Column(type: "int", nullable: false) - .Annotation("SqlServer:Identity", "1, 1"), - PackageId = 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_Packages_PackageId", - column: x => x.PackageId, - principalTable: "Packages", - principalColumn: "Id", - onDelete: ReferentialAction.Cascade); - }); - - migrationBuilder.CreateTable( - name: "PackageSoftwares", - columns: table => new - { - Id = table.Column(type: "int", nullable: false) - .Annotation("SqlServer:Identity", "1, 1"), - PackageId = table.Column(type: "int", nullable: false), - SoftwareId = table.Column(type: "int", nullable: false), - Count = table.Column(type: "int", nullable: false) - }, - constraints: table => - { - table.PrimaryKey("PK_PackageSoftwares", x => x.Id); - table.ForeignKey( - name: "FK_PackageSoftwares_Packages_PackageId", - column: x => x.PackageId, - principalTable: "Packages", - principalColumn: "Id", - onDelete: ReferentialAction.Cascade); - table.ForeignKey( - name: "FK_PackageSoftwares_Softwares_SoftwareId", - column: x => x.SoftwareId, - principalTable: "Softwares", - principalColumn: "Id", - onDelete: ReferentialAction.Cascade); - }); - - migrationBuilder.CreateIndex( - name: "IX_Orders_PackageId", - table: "Orders", - column: "PackageId"); - - migrationBuilder.CreateIndex( - name: "IX_PackageSoftwares_PackageId", - table: "PackageSoftwares", - column: "PackageId"); - - migrationBuilder.CreateIndex( - name: "IX_PackageSoftwares_SoftwareId", - table: "PackageSoftwares", - column: "SoftwareId"); - } - - /// - protected override void Down(MigrationBuilder migrationBuilder) - { - migrationBuilder.DropTable( - name: "Orders"); - - migrationBuilder.DropTable( - name: "PackageSoftwares"); - - migrationBuilder.DropTable( - name: "Packages"); - - migrationBuilder.DropTable( - name: "Softwares"); - } - } -} diff --git a/SoftwareInstallation/AbstractSoftwareInstallationDatabaseImplement/Migrations/AbstractSoftwareInstallationDatabaseModelSnapshot.cs b/SoftwareInstallation/AbstractSoftwareInstallationDatabaseImplement/Migrations/AbstractSoftwareInstallationDatabaseModelSnapshot.cs deleted file mode 100644 index 211c487..0000000 --- a/SoftwareInstallation/AbstractSoftwareInstallationDatabaseImplement/Migrations/AbstractSoftwareInstallationDatabaseModelSnapshot.cs +++ /dev/null @@ -1,168 +0,0 @@ -// -using System; -using AbstractSoftwareInstallationDatabaseImplement; -using Microsoft.EntityFrameworkCore; -using Microsoft.EntityFrameworkCore.Infrastructure; -using Microsoft.EntityFrameworkCore.Metadata; -using Microsoft.EntityFrameworkCore.Storage.ValueConversion; - -#nullable disable - -namespace AbstractSoftwareInstallationDatabaseImplement.Migrations -{ - [DbContext(typeof(AbstractSoftwareInstallationDatabase))] - partial class AbstractSoftwareInstallationDatabaseModelSnapshot : ModelSnapshot - { - protected override void BuildModel(ModelBuilder modelBuilder) - { -#pragma warning disable 612, 618 - modelBuilder - .HasAnnotation("ProductVersion", "7.0.4") - .HasAnnotation("Relational:MaxIdentifierLength", 128); - - SqlServerModelBuilderExtensions.UseIdentityColumns(modelBuilder); - - modelBuilder.Entity("AbstractPackageInstallationDatabaseImplement.Models.Order", b => - { - b.Property("Id") - .ValueGeneratedOnAdd() - .HasColumnType("int"); - - SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); - - b.Property("Count") - .HasColumnType("int"); - - b.Property("DateCreate") - .HasColumnType("datetime2"); - - b.Property("DateImplement") - .HasColumnType("datetime2"); - - b.Property("PackageId") - .HasColumnType("int"); - - b.Property("Status") - .HasColumnType("int"); - - b.Property("Sum") - .HasColumnType("float"); - - b.HasKey("Id"); - - b.HasIndex("PackageId"); - - b.ToTable("Orders"); - }); - - modelBuilder.Entity("AbstractSoftwareInstallationDatabaseImplement.Models.Package", b => - { - b.Property("Id") - .ValueGeneratedOnAdd() - .HasColumnType("int"); - - SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); - - b.Property("PackageName") - .IsRequired() - .HasColumnType("nvarchar(max)"); - - b.Property("Price") - .HasColumnType("float"); - - b.HasKey("Id"); - - b.ToTable("Packages"); - }); - - modelBuilder.Entity("AbstractSoftwareInstallationDatabaseImplement.Models.PackageSoftware", b => - { - b.Property("Id") - .ValueGeneratedOnAdd() - .HasColumnType("int"); - - SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); - - b.Property("Count") - .HasColumnType("int"); - - b.Property("PackageId") - .HasColumnType("int"); - - b.Property("SoftwareId") - .HasColumnType("int"); - - b.HasKey("Id"); - - b.HasIndex("PackageId"); - - b.HasIndex("SoftwareId"); - - b.ToTable("PackageSoftwares"); - }); - - modelBuilder.Entity("AbstractSoftwareInstallationDatabaseImplement.Models.Software", b => - { - b.Property("Id") - .ValueGeneratedOnAdd() - .HasColumnType("int"); - - SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); - - b.Property("Cost") - .HasColumnType("float"); - - b.Property("SoftwareName") - .IsRequired() - .HasColumnType("nvarchar(max)"); - - b.HasKey("Id"); - - b.ToTable("Softwares"); - }); - - modelBuilder.Entity("AbstractPackageInstallationDatabaseImplement.Models.Order", b => - { - b.HasOne("AbstractSoftwareInstallationDatabaseImplement.Models.Package", "Package") - .WithMany("Orders") - .HasForeignKey("PackageId") - .OnDelete(DeleteBehavior.Cascade) - .IsRequired(); - - b.Navigation("Package"); - }); - - modelBuilder.Entity("AbstractSoftwareInstallationDatabaseImplement.Models.PackageSoftware", b => - { - b.HasOne("AbstractSoftwareInstallationDatabaseImplement.Models.Package", "Package") - .WithMany("Softwares") - .HasForeignKey("PackageId") - .OnDelete(DeleteBehavior.Cascade) - .IsRequired(); - - b.HasOne("AbstractSoftwareInstallationDatabaseImplement.Models.Software", "Software") - .WithMany("PackageSoftwares") - .HasForeignKey("SoftwareId") - .OnDelete(DeleteBehavior.Cascade) - .IsRequired(); - - b.Navigation("Package"); - - b.Navigation("Software"); - }); - - modelBuilder.Entity("AbstractSoftwareInstallationDatabaseImplement.Models.Package", b => - { - b.Navigation("Orders"); - - b.Navigation("Softwares"); - }); - - modelBuilder.Entity("AbstractSoftwareInstallationDatabaseImplement.Models.Software", b => - { - b.Navigation("PackageSoftwares"); - }); -#pragma warning restore 612, 618 - } - } -} diff --git a/SoftwareInstallation/AbstractSoftwareInstallationDatabaseImplement/Models/Order.cs b/SoftwareInstallation/AbstractSoftwareInstallationDatabaseImplement/Models/Order.cs deleted file mode 100644 index 86f0e7f..0000000 --- a/SoftwareInstallation/AbstractSoftwareInstallationDatabaseImplement/Models/Order.cs +++ /dev/null @@ -1,73 +0,0 @@ -using AbstractSoftwareInstallationContracts.BindingModels; -using AbstractSoftwareInstallationContracts.ViewModels; -using AbstractSoftwareInstallationDatabaseImplement; -using AbstractSoftwareInstallationDatabaseImplement.Models; -using AbstractSoftwareInstallationDataModels; -using AbstractSoftwareInstallationDataModels.Models; -using System; -using System.Collections.Generic; -using System.ComponentModel.DataAnnotations; -using System.Linq; -using System.Text; -using System.Threading.Tasks; - -namespace AbstractPackageInstallationDatabaseImplement.Models -{ - public class Order : IOrderModel - { - public int Id { get; private set; } - [Required] - public int PackageId { get; private set; } - [Required] - public int Count { get; private set; } - [Required] - public double Sum { get; private set; } - [Required] - public OrderStatus Status { get; private set; } = OrderStatus.Неизвестен; - [Required] - public DateTime DateCreate { get; private set; } = DateTime.Now; - - public DateTime? DateImplement { get; private set; } - public virtual Package Package { get; set; } - - public static Order? Create(OrderBindingModel? model) - { - if (model == null) - { - return null; - } - return new Order - { - PackageId = model.PackageId, - Count = model.Count, - Sum = model.Sum, - Status = model.Status, - DateCreate = model.DateCreate, - DateImplement = model.DateImplement, - Id = model.Id - }; - } - - public void Update(OrderBindingModel? model) - { - if (model == null) - { - return; - } - Status = model.Status; - DateImplement = model.DateImplement; - } - - public OrderViewModel GetViewModel => new() - { - Id = Id, - PackageId = PackageId, - Count = Count, - Sum = Sum, - Status = Status, - DateCreate = DateCreate, - DateImplement = DateImplement, - PackageName = Package.PackageName - }; - } -} diff --git a/SoftwareInstallation/AbstractSoftwareInstallationDatabaseImplement/Models/Package.cs b/SoftwareInstallation/AbstractSoftwareInstallationDatabaseImplement/Models/Package.cs deleted file mode 100644 index e2578bb..0000000 --- a/SoftwareInstallation/AbstractSoftwareInstallationDatabaseImplement/Models/Package.cs +++ /dev/null @@ -1,107 +0,0 @@ -using AbstractPackageInstallationDatabaseImplement.Models; -using AbstractSoftwareInstallationContracts.BindingModels; -using AbstractSoftwareInstallationContracts.ViewModels; -using AbstractSoftwareInstallationDatabaseImplement.Models; -using AbstractSoftwareInstallationDataModels; -using AbstractSoftwareInstallationDataModels.Models; -using System; -using System.Collections.Generic; -using System.ComponentModel.DataAnnotations; -using System.ComponentModel.DataAnnotations.Schema; -using System.Linq; -using System.Text; -using System.Threading.Tasks; - -namespace AbstractSoftwareInstallationDatabaseImplement.Models -{ - public class Package : IPackageModel - { - public int Id { get; private set; } - [Required] - public string PackageName { get; private set; } = string.Empty; - [Required] - public double Price { get; private set; } - - private Dictionary? _packageSoftwares = null; - - [NotMapped] - public Dictionary PackageSoftware - { - get - { - if (_packageSoftwares == null) - { - _packageSoftwares = Softwares.ToDictionary(recPC => recPC.SoftwareId, recPC => (recPC.Software as ISoftwareModel, recPC.Count)); - } - return _packageSoftwares; - } - } - - [ForeignKey("PackageId")] - public virtual List Softwares { get; set; } = new(); - [ForeignKey("PackageId")] - public virtual List Orders { get; set; } = new(); - - - public static Package? Create(AbstractSoftwareInstallationDatabase context, PackageBindingModel model) - { - var Softwares = context.Softwares; - - return new Package() - { - Id = model.Id, - PackageName = model.PackageName, - Price = model.Price, - Softwares = model.PackageSoftware.Select(x => new PackageSoftware - { - Software = context.Softwares.First(y => y.Id == x.Key), - Count = x.Value.Item2 - }).ToList() - }; - } - - public void Update(PackageBindingModel model) - { - PackageName = model.PackageName; - Price = model.Price; - } - public PackageViewModel GetViewModel => new() - { - Id = Id, - PackageName = PackageName, - Price = Price, - PackageSoftware = PackageSoftware - }; - - public void UpdateSoftwares(AbstractSoftwareInstallationDatabase context, PackageBindingModel model) - { - var packageSoftwares = context.PackageSoftwares - .Where(rec => rec.PackageId == model.Id).ToList(); - if (packageSoftwares != null && packageSoftwares.Count > 0) - { // удалили те, которых нет в модели - context.PackageSoftwares.RemoveRange(packageSoftwares.Where(rec => !model.PackageSoftware.ContainsKey(rec.SoftwareId))); - context.SaveChanges(); - // обновили количество у существующих записей - foreach (var updateSoftware in packageSoftwares) - { - updateSoftware.Count = model.PackageSoftware[updateSoftware.SoftwareId].Item2; - model.PackageSoftware.Remove(updateSoftware.SoftwareId); - } - context.SaveChanges(); - } - var package = context.Packages.First(x => x.Id == Id); - foreach (var pc in model.PackageSoftware) - { - context.PackageSoftwares.Add(new PackageSoftware - { - Package = package, - Software = context.Softwares.First(x => x.Id == pc.Key), - Count = pc.Value.Item2 - }); - context.SaveChanges(); - } - _packageSoftwares = null; - } - - } -} diff --git a/SoftwareInstallation/AbstractSoftwareInstallationDatabaseImplement/Models/PackageSoftware.cs b/SoftwareInstallation/AbstractSoftwareInstallationDatabaseImplement/Models/PackageSoftware.cs deleted file mode 100644 index eeca146..0000000 --- a/SoftwareInstallation/AbstractSoftwareInstallationDatabaseImplement/Models/PackageSoftware.cs +++ /dev/null @@ -1,22 +0,0 @@ -using System; -using System.Collections.Generic; -using System.ComponentModel.DataAnnotations; -using System.Linq; -using System.Text; -using System.Threading.Tasks; - -namespace AbstractSoftwareInstallationDatabaseImplement.Models -{ - public class PackageSoftware - { - public int Id { get; set; } - [Required] - public int PackageId { get; set; } - [Required] - public int SoftwareId { get; set; } - [Required] - public int Count { get; set; } - public virtual Software Software { get; set; } = new(); - public virtual Package Package { get; set; } = new(); - } -} diff --git a/SoftwareInstallation/AbstractSoftwareInstallationDatabaseImplement/Models/Software.cs b/SoftwareInstallation/AbstractSoftwareInstallationDatabaseImplement/Models/Software.cs deleted file mode 100644 index d7e9151..0000000 --- a/SoftwareInstallation/AbstractSoftwareInstallationDatabaseImplement/Models/Software.cs +++ /dev/null @@ -1,53 +0,0 @@ -using AbstractSoftwareInstallationContracts.BindingModels; -using AbstractSoftwareInstallationContracts.ViewModels; -using AbstractSoftwareInstallationDataModels.Models; -using System; -using System.Collections.Generic; -using System.ComponentModel.DataAnnotations; -using System.ComponentModel.DataAnnotations.Schema; -using System.Linq; -using System.Text; -using System.Threading.Tasks; - -namespace AbstractSoftwareInstallationDatabaseImplement.Models -{ - public class Software : ISoftwareModel - { - public int Id { get; private set; } - [Required] - public string SoftwareName { get; private set; } = String.Empty; - [Required] - public double Cost { get; set; } - [ForeignKey("SoftwareId")] - public virtual List PackageSoftwares { get; set; } = new(); - public static Software? Create(SoftwareBindingModel? model) - { - if (model == null) - { - return null; - } - return new Software() - { - Id = model.Id, - SoftwareName = model.SoftwareName, - Cost = model.Cost - }; - } - public void Update(SoftwareBindingModel? model) - { - if (model == null) - { - return; - } - SoftwareName = model.SoftwareName; - Cost = model.Cost; - } - public SoftwareViewModel GetViewModel => new() - { - Id = Id, - SoftwareName = SoftwareName, - Cost = Cost - }; - - } -} From de4dd92f2f2e090f1fde6f012d371d39ff124c19 Mon Sep 17 00:00:00 2001 From: devil_1nc Date: Mon, 22 May 2023 21:31:08 +0400 Subject: [PATCH 7/7] conflict fix act 2 --- .../AbstractSoftwareInstallationDatabase.cs | 30 ++ ...ftwareInstallationDatabaseImplement.csproj | 24 ++ .../Implements/ClientStorage.cs | 89 ++++++ .../Implements/ImplementerStorage.cs | 84 ++++++ .../Implements/OrderStorage.cs | 100 +++++++ .../Implements/PackageStorage.cs | 113 ++++++++ .../Implements/SoftwareStorage.cs | 90 ++++++ .../20230419141439_Init.Designer.cs | 171 ++++++++++++ .../Migrations/20230419141439_Init.cs | 125 +++++++++ .../20230422195123_Client.Designer.cs | 214 +++++++++++++++ .../Migrations/20230422195123_Client.cs | 68 +++++ .../20230423193329_Implementer.Designer.cs | 255 +++++++++++++++++ .../Migrations/20230423193329_Implementer.cs | 67 +++++ .../20230423205115_OrderUPDATE.Designer.cs | 259 ++++++++++++++++++ .../Migrations/20230423205115_OrderUPDATE.cs | 59 ++++ ...ftwareInstallationDatabaseModelSnapshot.cs | 256 +++++++++++++++++ .../Models/Client.cs | 59 ++++ .../Models/Implementer.cs | 64 +++++ .../Models/Order.cs | 84 ++++++ .../Models/Package.cs | 107 ++++++++ .../Models/PackageSoftware.cs | 22 ++ .../Models/Software.cs | 53 ++++ 22 files changed, 2393 insertions(+) create mode 100644 SoftwareInstallation/AbstractSoftwareInstallationDatabaseImplement/AbstractSoftwareInstallationDatabase.cs create mode 100644 SoftwareInstallation/AbstractSoftwareInstallationDatabaseImplement/AbstractSoftwareInstallationDatabaseImplement.csproj create mode 100644 SoftwareInstallation/AbstractSoftwareInstallationDatabaseImplement/Implements/ClientStorage.cs create mode 100644 SoftwareInstallation/AbstractSoftwareInstallationDatabaseImplement/Implements/ImplementerStorage.cs create mode 100644 SoftwareInstallation/AbstractSoftwareInstallationDatabaseImplement/Implements/OrderStorage.cs create mode 100644 SoftwareInstallation/AbstractSoftwareInstallationDatabaseImplement/Implements/PackageStorage.cs create mode 100644 SoftwareInstallation/AbstractSoftwareInstallationDatabaseImplement/Implements/SoftwareStorage.cs create mode 100644 SoftwareInstallation/AbstractSoftwareInstallationDatabaseImplement/Migrations/20230419141439_Init.Designer.cs create mode 100644 SoftwareInstallation/AbstractSoftwareInstallationDatabaseImplement/Migrations/20230419141439_Init.cs create mode 100644 SoftwareInstallation/AbstractSoftwareInstallationDatabaseImplement/Migrations/20230422195123_Client.Designer.cs create mode 100644 SoftwareInstallation/AbstractSoftwareInstallationDatabaseImplement/Migrations/20230422195123_Client.cs create mode 100644 SoftwareInstallation/AbstractSoftwareInstallationDatabaseImplement/Migrations/20230423193329_Implementer.Designer.cs create mode 100644 SoftwareInstallation/AbstractSoftwareInstallationDatabaseImplement/Migrations/20230423193329_Implementer.cs create mode 100644 SoftwareInstallation/AbstractSoftwareInstallationDatabaseImplement/Migrations/20230423205115_OrderUPDATE.Designer.cs create mode 100644 SoftwareInstallation/AbstractSoftwareInstallationDatabaseImplement/Migrations/20230423205115_OrderUPDATE.cs create mode 100644 SoftwareInstallation/AbstractSoftwareInstallationDatabaseImplement/Migrations/AbstractSoftwareInstallationDatabaseModelSnapshot.cs create mode 100644 SoftwareInstallation/AbstractSoftwareInstallationDatabaseImplement/Models/Client.cs create mode 100644 SoftwareInstallation/AbstractSoftwareInstallationDatabaseImplement/Models/Implementer.cs create mode 100644 SoftwareInstallation/AbstractSoftwareInstallationDatabaseImplement/Models/Order.cs create mode 100644 SoftwareInstallation/AbstractSoftwareInstallationDatabaseImplement/Models/Package.cs create mode 100644 SoftwareInstallation/AbstractSoftwareInstallationDatabaseImplement/Models/PackageSoftware.cs create mode 100644 SoftwareInstallation/AbstractSoftwareInstallationDatabaseImplement/Models/Software.cs diff --git a/SoftwareInstallation/AbstractSoftwareInstallationDatabaseImplement/AbstractSoftwareInstallationDatabase.cs b/SoftwareInstallation/AbstractSoftwareInstallationDatabaseImplement/AbstractSoftwareInstallationDatabase.cs new file mode 100644 index 0000000..b9e561b --- /dev/null +++ b/SoftwareInstallation/AbstractSoftwareInstallationDatabaseImplement/AbstractSoftwareInstallationDatabase.cs @@ -0,0 +1,30 @@ +using AbstractPackageInstallationDatabaseImplement.Models; +using AbstractSoftwareInstallationDatabaseImplement.Models; +using Microsoft.EntityFrameworkCore; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace AbstractSoftwareInstallationDatabaseImplement +{ + public class AbstractSoftwareInstallationDatabase : DbContext + { + protected override void OnConfiguring(DbContextOptionsBuilder +optionsBuilder) + { + if (optionsBuilder.IsConfigured == false) + { + optionsBuilder.UseSqlServer(@"Data Source=DESKTOP-QA8P9OJ;Initial Catalog=SoftwareInstallation;Integrated Security=True;MultipleActiveResultSets=True;TrustServerCertificate=True"); + } + base.OnConfiguring(optionsBuilder); + } + public virtual DbSet Softwares { set; get; } + public virtual DbSet Packages { set; get; } + public virtual DbSet PackageSoftwares { set; get; } + public virtual DbSet Orders { set; get; } + public virtual DbSet Clients { set; get; } + public virtual DbSet Implementers { set; get; } + } +} diff --git a/SoftwareInstallation/AbstractSoftwareInstallationDatabaseImplement/AbstractSoftwareInstallationDatabaseImplement.csproj b/SoftwareInstallation/AbstractSoftwareInstallationDatabaseImplement/AbstractSoftwareInstallationDatabaseImplement.csproj new file mode 100644 index 0000000..1f9db50 --- /dev/null +++ b/SoftwareInstallation/AbstractSoftwareInstallationDatabaseImplement/AbstractSoftwareInstallationDatabaseImplement.csproj @@ -0,0 +1,24 @@ + + + + net6.0 + enable + enable + + + + + + + all + runtime; build; native; contentfiles; analyzers; buildtransitive + + + + + + + + + + diff --git a/SoftwareInstallation/AbstractSoftwareInstallationDatabaseImplement/Implements/ClientStorage.cs b/SoftwareInstallation/AbstractSoftwareInstallationDatabaseImplement/Implements/ClientStorage.cs new file mode 100644 index 0000000..a7496be --- /dev/null +++ b/SoftwareInstallation/AbstractSoftwareInstallationDatabaseImplement/Implements/ClientStorage.cs @@ -0,0 +1,89 @@ +using AbstractSoftwareInstallationContracts.BindingModels; +using AbstractSoftwareInstallationContracts.SearchModels; +using AbstractSoftwareInstallationContracts.StoragesContracts; +using AbstractSoftwareInstallationContracts.ViewModels; +using AbstractSoftwareInstallationDatabaseImplement.Models; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace AbstractSoftwareInstallationDatabaseImplement.Implements +{ + public class ClientStorage : IClientStorage + { + public ClientViewModel? GetElement(ClientSearchModel model) + { + if (string.IsNullOrEmpty(model.Email) && !model.Id.HasValue) + { + return null; + } + using var context = new AbstractSoftwareInstallationDatabase(); + return context.Clients + .FirstOrDefault(x => (!string.IsNullOrEmpty(model.Email) + && x.Email == model.Email) + || (model.Id.HasValue && x.Id == model.Id)) + ?.GetViewModel; + } + + public List GetFilteredList(ClientSearchModel model) + { + if (string.IsNullOrEmpty(model.Email)) + { + return new(); + } + using var context = new AbstractSoftwareInstallationDatabase(); + return context.Clients + .Where(x => x.Email.Contains(model.Email)) + .Select(x => x.GetViewModel) + .ToList(); + } + + public List GetFullList() + { + using var context = new AbstractSoftwareInstallationDatabase(); + return context.Clients + .Select(x => x.GetViewModel) + .ToList(); + } + + public ClientViewModel? Insert(ClientBindingModel model) + { + var newClient = Client.Create(model); + if (newClient == null) + { + return null; + } + using var context = new AbstractSoftwareInstallationDatabase(); + context.Clients.Add(newClient); + context.SaveChanges(); + return newClient.GetViewModel; + } + + public ClientViewModel? Update(ClientBindingModel model) + { + using var context = new AbstractSoftwareInstallationDatabase(); + var Client = context.Clients.FirstOrDefault(x => x.Id == model.Id); + if (Client == null) + { + return null; + } + Client.Update(model); + context.SaveChanges(); + return Client.GetViewModel; + } + public ClientViewModel? Delete(ClientBindingModel model) + { + using var context = new AbstractSoftwareInstallationDatabase(); + var element = context.Clients.FirstOrDefault(rec => rec.Id == model.Id); + if (element != null) + { + context.Clients.Remove(element); + context.SaveChanges(); + return element.GetViewModel; + } + return null; + } + } +} diff --git a/SoftwareInstallation/AbstractSoftwareInstallationDatabaseImplement/Implements/ImplementerStorage.cs b/SoftwareInstallation/AbstractSoftwareInstallationDatabaseImplement/Implements/ImplementerStorage.cs new file mode 100644 index 0000000..e010416 --- /dev/null +++ b/SoftwareInstallation/AbstractSoftwareInstallationDatabaseImplement/Implements/ImplementerStorage.cs @@ -0,0 +1,84 @@ +using AbstractSoftwareInstallationContracts.BindingModels; +using AbstractSoftwareInstallationContracts.SearchModels; +using AbstractSoftwareInstallationContracts.StoragesContracts; +using AbstractSoftwareInstallationContracts.ViewModels; +using AbstractSoftwareInstallationDatabaseImplement.Models; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace AbstractSoftwareInstallationDatabaseImplement.Implements +{ + public class ImplementerStorage : IImplementerStorage + { + + public ImplementerViewModel? GetElement(ImplementerSearchModel model) + { + using var context = new AbstractSoftwareInstallationDatabase(); + if (model.Id.HasValue) return context.Implementers.FirstOrDefault(x => x.Id == model.Id)?.GetViewModel; + if (model.ImplementerFIO != null && model.Password != null) return context.Implementers.FirstOrDefault(x => x.ImplementerFIO.Equals(model.ImplementerFIO) && x.Password.Equals(model.Password))?.GetViewModel; + if (model.ImplementerFIO != null) return context.Implementers.FirstOrDefault(x => x.ImplementerFIO.Equals(model.ImplementerFIO))?.GetViewModel; + return null; + } + + public List GetFilteredList(ImplementerSearchModel model) + { + if (model == null) + { + return new(); + } + if (model.ImplementerFIO != null) + { + using var context = new AbstractSoftwareInstallationDatabase(); + return context.Implementers + .Where(x => x.ImplementerFIO.Contains(model.ImplementerFIO)) + .Select(x => x.GetViewModel) + .ToList(); + } + return new(); + } + + public List GetFullList() + { + using var context = new AbstractSoftwareInstallationDatabase(); + return context.Implementers.Select(x => x.GetViewModel).ToList(); + } + + public ImplementerViewModel? Insert(ImplementerBindingModel model) + { + using var context = new AbstractSoftwareInstallationDatabase(); + var res = Implementer.Create(model); + if (res != null) + { + context.Implementers.Add(res); + context.SaveChanges(); + } + return res?.GetViewModel; + } + + public ImplementerViewModel? Update(ImplementerBindingModel model) + { + using var context = new AbstractSoftwareInstallationDatabase(); + var res = context.Implementers.FirstOrDefault(x => x.Id == model.Id); + if (res != null) + { + res.Update(model); + context.SaveChanges(); + } + return res?.GetViewModel; + } + public ImplementerViewModel? Delete(ImplementerBindingModel model) + { + using var context = new AbstractSoftwareInstallationDatabase(); + var res = context.Implementers.FirstOrDefault(x => x.Id == model.Id); + if (res != null) + { + context.Implementers.Remove(res); + context.SaveChanges(); + } + return res?.GetViewModel; + } + } +} diff --git a/SoftwareInstallation/AbstractSoftwareInstallationDatabaseImplement/Implements/OrderStorage.cs b/SoftwareInstallation/AbstractSoftwareInstallationDatabaseImplement/Implements/OrderStorage.cs new file mode 100644 index 0000000..8203f74 --- /dev/null +++ b/SoftwareInstallation/AbstractSoftwareInstallationDatabaseImplement/Implements/OrderStorage.cs @@ -0,0 +1,100 @@ +using AbstractPackageInstallationDatabaseImplement.Models; +using AbstractSoftwareInstallationContracts.BindingModels; +using AbstractSoftwareInstallationContracts.SearchModels; +using AbstractSoftwareInstallationContracts.StoragesContracts; +using AbstractSoftwareInstallationContracts.ViewModels; +using Microsoft.EntityFrameworkCore; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace AbstractSoftwareInstallationDatabaseImplement.Implements +{ + public class OrderStorage : IOrderStorage + { + public OrderViewModel? Delete(OrderBindingModel model) + { + using var context = new AbstractSoftwareInstallationDatabase(); + 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) + { + if (!model.Id.HasValue) + { + return null; + } + using var context = new AbstractSoftwareInstallationDatabase(); + return context.Orders.Include(x => x.Package).Include(x => x.Client).Include(x => x.Implementer).FirstOrDefault(x => (model.Id.HasValue && x.Id == model.Id))?.GetViewModel; + } + + public List GetFilteredList(OrderSearchModel model) + { + using var context = new AbstractSoftwareInstallationDatabase(); + + if (model.ClientId.HasValue) + { + return context.Orders + .Include(x => x.Package) + .Include(x => x.Client) + .Include(x => x.Implementer) + .Where(x => x.ClientId == model.ClientId) + .Select(x => x.GetViewModel) + .ToList(); + } + + return context.Orders + .Where(x => x.DateCreate >= model.DateFrom && x.DateCreate <= model.DateTo) + .Include(x => x.Package).Include(x => x.Client).Include(x => x.Implementer) + .Select(x => x.GetViewModel) + .ToList(); + + } + + public List GetFullList() + { + using var context = new AbstractSoftwareInstallationDatabase(); + return context.Orders + .Include(x => x.Package).Include(x => x.Client).Include(x => x.Implementer) + .Select(x => x.GetViewModel) + .ToList(); + } + + public OrderViewModel? Insert(OrderBindingModel model) + { + var newOrder = Order.Create(model); + + if (newOrder == null) + { + return null; + } + using var context = new AbstractSoftwareInstallationDatabase(); + context.Orders.Add(newOrder); + context.SaveChanges(); + return context.Orders.Include(x => x.Package).Include(x => x.Client).Include(x => x.Implementer).FirstOrDefault(x => x.Id == newOrder.Id)?.GetViewModel; + + } + + public OrderViewModel? Update(OrderBindingModel model) + { + using var context = new AbstractSoftwareInstallationDatabase(); + var order = context.Orders.FirstOrDefault(x => x.Id == model.Id); + if (order == null) + { + return null; + } + order.Update(model); + context.SaveChanges(); + return context.Orders.Include(x => x.Package).Include(x => x.Client).Include(x => x.Implementer).FirstOrDefault(x => x.Id == order.Id)?.GetViewModel; + } + } +} diff --git a/SoftwareInstallation/AbstractSoftwareInstallationDatabaseImplement/Implements/PackageStorage.cs b/SoftwareInstallation/AbstractSoftwareInstallationDatabaseImplement/Implements/PackageStorage.cs new file mode 100644 index 0000000..f692d22 --- /dev/null +++ b/SoftwareInstallation/AbstractSoftwareInstallationDatabaseImplement/Implements/PackageStorage.cs @@ -0,0 +1,113 @@ +using AbstractSoftwareInstallationContracts.BindingModels; +using AbstractSoftwareInstallationContracts.SearchModels; +using AbstractSoftwareInstallationContracts.StoragesContracts; +using AbstractSoftwareInstallationContracts.ViewModels; +using AbstractSoftwareInstallationDatabaseImplement.Models; +using Microsoft.EntityFrameworkCore; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace AbstractSoftwareInstallationDatabaseImplement.Implements +{ + public class PackageStorage : IPackageStorage + { + public List GetFullList() + { + using var context = new AbstractSoftwareInstallationDatabase(); + return context.Packages + .Include(x => x.Softwares) + .ThenInclude(x => x.Software) + .ToList() + .Select(x => x.GetViewModel) + .ToList(); + } + + public List GetFilteredList(PackageSearchModel model) + { + if (string.IsNullOrEmpty(model.PackageName)) + { + return new(); + } + using var context = new AbstractSoftwareInstallationDatabase(); + return context.Packages + .Include(x => x.Softwares) + .ThenInclude(x => x.Software) + .Where(x => x.PackageName.Contains(model.PackageName)) + .ToList() + .Select(x => x.GetViewModel) + .ToList(); + } + + public PackageViewModel? GetElement(PackageSearchModel model) + { + if (string.IsNullOrEmpty(model.PackageName) && + !model.Id.HasValue) + { + return null; + } + using var context = new AbstractSoftwareInstallationDatabase(); + return context.Packages + .Include(x => x.Softwares) + .ThenInclude(x => x.Software) + .FirstOrDefault(x => (!string.IsNullOrEmpty(model.PackageName) + && x.PackageName == model.PackageName) + || (model.Id.HasValue && x.Id == model.Id)) + ?.GetViewModel; + } + + public PackageViewModel? Insert(PackageBindingModel model) + { + using var context = new AbstractSoftwareInstallationDatabase(); + var newPackage = Package.Create(context, model); + if (newPackage == null) + { + return null; + } + context.Packages.Add(newPackage); + context.SaveChanges(); + return newPackage.GetViewModel; + } + + public PackageViewModel? Update(PackageBindingModel model) + { + using var context = new AbstractSoftwareInstallationDatabase(); + using var transaction = context.Database.BeginTransaction(); + try + { + var Package = context.Packages.FirstOrDefault(rec => rec.Id == model.Id); + if (Package == null) + { + return null; + } + Package.Update(model); + context.SaveChanges(); + Package.UpdateSoftwares(context, model); + transaction.Commit(); + return Package.GetViewModel; + } + catch + { + transaction.Rollback(); + throw; + } + } + + public PackageViewModel? Delete(PackageBindingModel model) + { + using var context = new AbstractSoftwareInstallationDatabase(); + var element = context.Packages + .Include(x => x.Softwares) + .FirstOrDefault(rec => rec.Id == model.Id); + if (element != null) + { + context.Packages.Remove(element); + context.SaveChanges(); + return element.GetViewModel; + } + return null; + } + } +} diff --git a/SoftwareInstallation/AbstractSoftwareInstallationDatabaseImplement/Implements/SoftwareStorage.cs b/SoftwareInstallation/AbstractSoftwareInstallationDatabaseImplement/Implements/SoftwareStorage.cs new file mode 100644 index 0000000..80d382f --- /dev/null +++ b/SoftwareInstallation/AbstractSoftwareInstallationDatabaseImplement/Implements/SoftwareStorage.cs @@ -0,0 +1,90 @@ +using AbstractSoftwareInstallationContracts.BindingModels; +using AbstractSoftwareInstallationContracts.SearchModels; +using AbstractSoftwareInstallationContracts.StoragesContracts; +using AbstractSoftwareInstallationContracts.ViewModels; +using AbstractSoftwareInstallationDatabaseImplement.Models; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace AbstractSoftwareInstallationDatabaseImplement.Implements +{ + public class SoftwareStorage : ISoftwareStorage + { + public List GetFullList() + { + using var context = new AbstractSoftwareInstallationDatabase(); + return context.Softwares + .Select(x => x.GetViewModel) + .ToList(); + } + + public List GetFilteredList(SoftwareSearchModel model) + { + if (string.IsNullOrEmpty(model.SoftwareName)) + { + return new(); + } + using var context = new AbstractSoftwareInstallationDatabase(); + return context.Softwares + .Where(x => x.SoftwareName.Contains(model.SoftwareName)) + .Select(x => x.GetViewModel) + .ToList(); + } + + public SoftwareViewModel? GetElement(SoftwareSearchModel model) + { + if (string.IsNullOrEmpty(model.SoftwareName) && !model.Id.HasValue) + { + return null; + } + using var context = new AbstractSoftwareInstallationDatabase(); + return context.Softwares + .FirstOrDefault(x => (!string.IsNullOrEmpty(model.SoftwareName) + && x.SoftwareName == model.SoftwareName) + || (model.Id.HasValue && x.Id == model.Id)) + ?.GetViewModel; + } + + public SoftwareViewModel? Insert(SoftwareBindingModel model) + { + var newSoftware = Software.Create(model); + if (newSoftware == null) + { + return null; + } + using var context = new AbstractSoftwareInstallationDatabase(); + context.Softwares.Add(newSoftware); + context.SaveChanges(); + return newSoftware.GetViewModel; + } + + public SoftwareViewModel? Update(SoftwareBindingModel model) + { + using var context = new AbstractSoftwareInstallationDatabase(); + var Software = context.Softwares.FirstOrDefault(x => x.Id == model.Id); + if (Software == null) + { + return null; + } + Software.Update(model); + context.SaveChanges(); + return Software.GetViewModel; + } + + public SoftwareViewModel? Delete(SoftwareBindingModel model) + { + using var context = new AbstractSoftwareInstallationDatabase(); + var element = context.Softwares.FirstOrDefault(rec => rec.Id == model.Id); + if (element != null) + { + context.Softwares.Remove(element); + context.SaveChanges(); + return element.GetViewModel; + } + return null; + } + } +} diff --git a/SoftwareInstallation/AbstractSoftwareInstallationDatabaseImplement/Migrations/20230419141439_Init.Designer.cs b/SoftwareInstallation/AbstractSoftwareInstallationDatabaseImplement/Migrations/20230419141439_Init.Designer.cs new file mode 100644 index 0000000..ba3d063 --- /dev/null +++ b/SoftwareInstallation/AbstractSoftwareInstallationDatabaseImplement/Migrations/20230419141439_Init.Designer.cs @@ -0,0 +1,171 @@ +// +using System; +using AbstractSoftwareInstallationDatabaseImplement; +using Microsoft.EntityFrameworkCore; +using Microsoft.EntityFrameworkCore.Infrastructure; +using Microsoft.EntityFrameworkCore.Metadata; +using Microsoft.EntityFrameworkCore.Migrations; +using Microsoft.EntityFrameworkCore.Storage.ValueConversion; + +#nullable disable + +namespace AbstractSoftwareInstallationDatabaseImplement.Migrations +{ + [DbContext(typeof(AbstractSoftwareInstallationDatabase))] + [Migration("20230419141439_Init")] + partial class Init + { + /// + protected override void BuildTargetModel(ModelBuilder modelBuilder) + { +#pragma warning disable 612, 618 + modelBuilder + .HasAnnotation("ProductVersion", "7.0.4") + .HasAnnotation("Relational:MaxIdentifierLength", 128); + + SqlServerModelBuilderExtensions.UseIdentityColumns(modelBuilder); + + modelBuilder.Entity("AbstractPackageInstallationDatabaseImplement.Models.Order", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("int"); + + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); + + b.Property("Count") + .HasColumnType("int"); + + b.Property("DateCreate") + .HasColumnType("datetime2"); + + b.Property("DateImplement") + .HasColumnType("datetime2"); + + b.Property("PackageId") + .HasColumnType("int"); + + b.Property("Status") + .HasColumnType("int"); + + b.Property("Sum") + .HasColumnType("float"); + + b.HasKey("Id"); + + b.HasIndex("PackageId"); + + b.ToTable("Orders"); + }); + + modelBuilder.Entity("AbstractSoftwareInstallationDatabaseImplement.Models.Package", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("int"); + + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); + + b.Property("PackageName") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.Property("Price") + .HasColumnType("float"); + + b.HasKey("Id"); + + b.ToTable("Packages"); + }); + + modelBuilder.Entity("AbstractSoftwareInstallationDatabaseImplement.Models.PackageSoftware", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("int"); + + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); + + b.Property("Count") + .HasColumnType("int"); + + b.Property("PackageId") + .HasColumnType("int"); + + b.Property("SoftwareId") + .HasColumnType("int"); + + b.HasKey("Id"); + + b.HasIndex("PackageId"); + + b.HasIndex("SoftwareId"); + + b.ToTable("PackageSoftwares"); + }); + + modelBuilder.Entity("AbstractSoftwareInstallationDatabaseImplement.Models.Software", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("int"); + + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); + + b.Property("Cost") + .HasColumnType("float"); + + b.Property("SoftwareName") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.HasKey("Id"); + + b.ToTable("Softwares"); + }); + + modelBuilder.Entity("AbstractPackageInstallationDatabaseImplement.Models.Order", b => + { + b.HasOne("AbstractSoftwareInstallationDatabaseImplement.Models.Package", "Package") + .WithMany("Orders") + .HasForeignKey("PackageId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.Navigation("Package"); + }); + + modelBuilder.Entity("AbstractSoftwareInstallationDatabaseImplement.Models.PackageSoftware", b => + { + b.HasOne("AbstractSoftwareInstallationDatabaseImplement.Models.Package", "Package") + .WithMany("Softwares") + .HasForeignKey("PackageId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.HasOne("AbstractSoftwareInstallationDatabaseImplement.Models.Software", "Software") + .WithMany("PackageSoftwares") + .HasForeignKey("SoftwareId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.Navigation("Package"); + + b.Navigation("Software"); + }); + + modelBuilder.Entity("AbstractSoftwareInstallationDatabaseImplement.Models.Package", b => + { + b.Navigation("Orders"); + + b.Navigation("Softwares"); + }); + + modelBuilder.Entity("AbstractSoftwareInstallationDatabaseImplement.Models.Software", b => + { + b.Navigation("PackageSoftwares"); + }); +#pragma warning restore 612, 618 + } + } +} diff --git a/SoftwareInstallation/AbstractSoftwareInstallationDatabaseImplement/Migrations/20230419141439_Init.cs b/SoftwareInstallation/AbstractSoftwareInstallationDatabaseImplement/Migrations/20230419141439_Init.cs new file mode 100644 index 0000000..28f3761 --- /dev/null +++ b/SoftwareInstallation/AbstractSoftwareInstallationDatabaseImplement/Migrations/20230419141439_Init.cs @@ -0,0 +1,125 @@ +using System; +using Microsoft.EntityFrameworkCore.Migrations; + +#nullable disable + +namespace AbstractSoftwareInstallationDatabaseImplement.Migrations +{ + /// + public partial class Init : Migration + { + /// + protected override void Up(MigrationBuilder migrationBuilder) + { + migrationBuilder.CreateTable( + name: "Packages", + columns: table => new + { + Id = table.Column(type: "int", nullable: false) + .Annotation("SqlServer:Identity", "1, 1"), + PackageName = table.Column(type: "nvarchar(max)", nullable: false), + Price = table.Column(type: "float", nullable: false) + }, + constraints: table => + { + table.PrimaryKey("PK_Packages", x => x.Id); + }); + + migrationBuilder.CreateTable( + name: "Softwares", + columns: table => new + { + Id = table.Column(type: "int", nullable: false) + .Annotation("SqlServer:Identity", "1, 1"), + SoftwareName = table.Column(type: "nvarchar(max)", nullable: false), + Cost = table.Column(type: "float", nullable: false) + }, + constraints: table => + { + table.PrimaryKey("PK_Softwares", x => x.Id); + }); + + migrationBuilder.CreateTable( + name: "Orders", + columns: table => new + { + Id = table.Column(type: "int", nullable: false) + .Annotation("SqlServer:Identity", "1, 1"), + PackageId = 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_Packages_PackageId", + column: x => x.PackageId, + principalTable: "Packages", + principalColumn: "Id", + onDelete: ReferentialAction.Cascade); + }); + + migrationBuilder.CreateTable( + name: "PackageSoftwares", + columns: table => new + { + Id = table.Column(type: "int", nullable: false) + .Annotation("SqlServer:Identity", "1, 1"), + PackageId = table.Column(type: "int", nullable: false), + SoftwareId = table.Column(type: "int", nullable: false), + Count = table.Column(type: "int", nullable: false) + }, + constraints: table => + { + table.PrimaryKey("PK_PackageSoftwares", x => x.Id); + table.ForeignKey( + name: "FK_PackageSoftwares_Packages_PackageId", + column: x => x.PackageId, + principalTable: "Packages", + principalColumn: "Id", + onDelete: ReferentialAction.Cascade); + table.ForeignKey( + name: "FK_PackageSoftwares_Softwares_SoftwareId", + column: x => x.SoftwareId, + principalTable: "Softwares", + principalColumn: "Id", + onDelete: ReferentialAction.Cascade); + }); + + migrationBuilder.CreateIndex( + name: "IX_Orders_PackageId", + table: "Orders", + column: "PackageId"); + + migrationBuilder.CreateIndex( + name: "IX_PackageSoftwares_PackageId", + table: "PackageSoftwares", + column: "PackageId"); + + migrationBuilder.CreateIndex( + name: "IX_PackageSoftwares_SoftwareId", + table: "PackageSoftwares", + column: "SoftwareId"); + } + + /// + protected override void Down(MigrationBuilder migrationBuilder) + { + migrationBuilder.DropTable( + name: "Orders"); + + migrationBuilder.DropTable( + name: "PackageSoftwares"); + + migrationBuilder.DropTable( + name: "Packages"); + + migrationBuilder.DropTable( + name: "Softwares"); + } + } +} diff --git a/SoftwareInstallation/AbstractSoftwareInstallationDatabaseImplement/Migrations/20230422195123_Client.Designer.cs b/SoftwareInstallation/AbstractSoftwareInstallationDatabaseImplement/Migrations/20230422195123_Client.Designer.cs new file mode 100644 index 0000000..4f61cbf --- /dev/null +++ b/SoftwareInstallation/AbstractSoftwareInstallationDatabaseImplement/Migrations/20230422195123_Client.Designer.cs @@ -0,0 +1,214 @@ +// +using System; +using AbstractSoftwareInstallationDatabaseImplement; +using Microsoft.EntityFrameworkCore; +using Microsoft.EntityFrameworkCore.Infrastructure; +using Microsoft.EntityFrameworkCore.Metadata; +using Microsoft.EntityFrameworkCore.Migrations; +using Microsoft.EntityFrameworkCore.Storage.ValueConversion; + +#nullable disable + +namespace AbstractSoftwareInstallationDatabaseImplement.Migrations +{ + [DbContext(typeof(AbstractSoftwareInstallationDatabase))] + [Migration("20230422195123_Client")] + partial class Client + { + /// + protected override void BuildTargetModel(ModelBuilder modelBuilder) + { +#pragma warning disable 612, 618 + modelBuilder + .HasAnnotation("ProductVersion", "7.0.4") + .HasAnnotation("Relational:MaxIdentifierLength", 128); + + SqlServerModelBuilderExtensions.UseIdentityColumns(modelBuilder); + + modelBuilder.Entity("AbstractPackageInstallationDatabaseImplement.Models.Order", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("int"); + + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); + + b.Property("ClientId") + .HasColumnType("int"); + + b.Property("Count") + .HasColumnType("int"); + + b.Property("DateCreate") + .HasColumnType("datetime2"); + + b.Property("DateImplement") + .HasColumnType("datetime2"); + + b.Property("PackageId") + .HasColumnType("int"); + + b.Property("Status") + .HasColumnType("int"); + + b.Property("Sum") + .HasColumnType("float"); + + b.HasKey("Id"); + + b.HasIndex("ClientId"); + + b.HasIndex("PackageId"); + + b.ToTable("Orders"); + }); + + modelBuilder.Entity("AbstractSoftwareInstallationDatabaseImplement.Models.Client", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("int"); + + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); + + b.Property("ClientFIO") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.Property("Email") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.Property("Password") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.HasKey("Id"); + + b.ToTable("Clients"); + }); + + modelBuilder.Entity("AbstractSoftwareInstallationDatabaseImplement.Models.Package", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("int"); + + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); + + b.Property("PackageName") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.Property("Price") + .HasColumnType("float"); + + b.HasKey("Id"); + + b.ToTable("Packages"); + }); + + modelBuilder.Entity("AbstractSoftwareInstallationDatabaseImplement.Models.PackageSoftware", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("int"); + + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); + + b.Property("Count") + .HasColumnType("int"); + + b.Property("PackageId") + .HasColumnType("int"); + + b.Property("SoftwareId") + .HasColumnType("int"); + + b.HasKey("Id"); + + b.HasIndex("PackageId"); + + b.HasIndex("SoftwareId"); + + b.ToTable("PackageSoftwares"); + }); + + modelBuilder.Entity("AbstractSoftwareInstallationDatabaseImplement.Models.Software", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("int"); + + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); + + b.Property("Cost") + .HasColumnType("float"); + + b.Property("SoftwareName") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.HasKey("Id"); + + b.ToTable("Softwares"); + }); + + modelBuilder.Entity("AbstractPackageInstallationDatabaseImplement.Models.Order", b => + { + b.HasOne("AbstractSoftwareInstallationDatabaseImplement.Models.Client", "Client") + .WithMany("Orders") + .HasForeignKey("ClientId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.HasOne("AbstractSoftwareInstallationDatabaseImplement.Models.Package", "Package") + .WithMany("Orders") + .HasForeignKey("PackageId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.Navigation("Client"); + + b.Navigation("Package"); + }); + + modelBuilder.Entity("AbstractSoftwareInstallationDatabaseImplement.Models.PackageSoftware", b => + { + b.HasOne("AbstractSoftwareInstallationDatabaseImplement.Models.Package", "Package") + .WithMany("Softwares") + .HasForeignKey("PackageId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.HasOne("AbstractSoftwareInstallationDatabaseImplement.Models.Software", "Software") + .WithMany("PackageSoftwares") + .HasForeignKey("SoftwareId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.Navigation("Package"); + + b.Navigation("Software"); + }); + + modelBuilder.Entity("AbstractSoftwareInstallationDatabaseImplement.Models.Client", b => + { + b.Navigation("Orders"); + }); + + modelBuilder.Entity("AbstractSoftwareInstallationDatabaseImplement.Models.Package", b => + { + b.Navigation("Orders"); + + b.Navigation("Softwares"); + }); + + modelBuilder.Entity("AbstractSoftwareInstallationDatabaseImplement.Models.Software", b => + { + b.Navigation("PackageSoftwares"); + }); +#pragma warning restore 612, 618 + } + } +} diff --git a/SoftwareInstallation/AbstractSoftwareInstallationDatabaseImplement/Migrations/20230422195123_Client.cs b/SoftwareInstallation/AbstractSoftwareInstallationDatabaseImplement/Migrations/20230422195123_Client.cs new file mode 100644 index 0000000..1e199b5 --- /dev/null +++ b/SoftwareInstallation/AbstractSoftwareInstallationDatabaseImplement/Migrations/20230422195123_Client.cs @@ -0,0 +1,68 @@ +using Microsoft.EntityFrameworkCore.Migrations; + +#nullable disable + +namespace AbstractSoftwareInstallationDatabaseImplement.Migrations +{ + /// + public partial class Client : Migration + { + /// + protected override void Up(MigrationBuilder migrationBuilder) + { + migrationBuilder.AddColumn( + name: "ClientId", + table: "Orders", + type: "int", + nullable: false, + defaultValue: 0); + + migrationBuilder.CreateTable( + name: "Clients", + columns: table => new + { + Id = table.Column(type: "int", nullable: false) + .Annotation("SqlServer:Identity", "1, 1"), + ClientFIO = table.Column(type: "nvarchar(max)", nullable: false), + Email = table.Column(type: "nvarchar(max)", nullable: false), + Password = table.Column(type: "nvarchar(max)", nullable: false) + }, + constraints: table => + { + table.PrimaryKey("PK_Clients", x => x.Id); + }); + + migrationBuilder.CreateIndex( + name: "IX_Orders_ClientId", + table: "Orders", + column: "ClientId"); + + migrationBuilder.AddForeignKey( + name: "FK_Orders_Clients_ClientId", + table: "Orders", + column: "ClientId", + principalTable: "Clients", + principalColumn: "Id", + onDelete: ReferentialAction.Cascade); + } + + /// + protected override void Down(MigrationBuilder migrationBuilder) + { + migrationBuilder.DropForeignKey( + name: "FK_Orders_Clients_ClientId", + table: "Orders"); + + migrationBuilder.DropTable( + name: "Clients"); + + migrationBuilder.DropIndex( + name: "IX_Orders_ClientId", + table: "Orders"); + + migrationBuilder.DropColumn( + name: "ClientId", + table: "Orders"); + } + } +} diff --git a/SoftwareInstallation/AbstractSoftwareInstallationDatabaseImplement/Migrations/20230423193329_Implementer.Designer.cs b/SoftwareInstallation/AbstractSoftwareInstallationDatabaseImplement/Migrations/20230423193329_Implementer.Designer.cs new file mode 100644 index 0000000..f5b9aae --- /dev/null +++ b/SoftwareInstallation/AbstractSoftwareInstallationDatabaseImplement/Migrations/20230423193329_Implementer.Designer.cs @@ -0,0 +1,255 @@ +// +using System; +using AbstractSoftwareInstallationDatabaseImplement; +using Microsoft.EntityFrameworkCore; +using Microsoft.EntityFrameworkCore.Infrastructure; +using Microsoft.EntityFrameworkCore.Metadata; +using Microsoft.EntityFrameworkCore.Migrations; +using Microsoft.EntityFrameworkCore.Storage.ValueConversion; + +#nullable disable + +namespace AbstractSoftwareInstallationDatabaseImplement.Migrations +{ + [DbContext(typeof(AbstractSoftwareInstallationDatabase))] + [Migration("20230423193329_Implementer")] + partial class Implementer + { + /// + protected override void BuildTargetModel(ModelBuilder modelBuilder) + { +#pragma warning disable 612, 618 + modelBuilder + .HasAnnotation("ProductVersion", "7.0.4") + .HasAnnotation("Relational:MaxIdentifierLength", 128); + + SqlServerModelBuilderExtensions.UseIdentityColumns(modelBuilder); + + modelBuilder.Entity("AbstractPackageInstallationDatabaseImplement.Models.Order", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("int"); + + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); + + b.Property("ClientId") + .HasColumnType("int"); + + b.Property("Count") + .HasColumnType("int"); + + b.Property("DateCreate") + .HasColumnType("datetime2"); + + b.Property("DateImplement") + .HasColumnType("datetime2"); + + b.Property("ImplementerId") + .HasColumnType("int"); + + b.Property("PackageId") + .HasColumnType("int"); + + b.Property("Status") + .HasColumnType("int"); + + b.Property("Sum") + .HasColumnType("float"); + + b.HasKey("Id"); + + b.HasIndex("ClientId"); + + b.HasIndex("ImplementerId"); + + b.HasIndex("PackageId"); + + b.ToTable("Orders"); + }); + + modelBuilder.Entity("AbstractSoftwareInstallationDatabaseImplement.Models.Client", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("int"); + + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); + + b.Property("ClientFIO") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.Property("Email") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.Property("Password") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.HasKey("Id"); + + b.ToTable("Clients"); + }); + + modelBuilder.Entity("AbstractSoftwareInstallationDatabaseImplement.Models.Implementer", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("int"); + + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); + + b.Property("ImplementerFIO") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.Property("Password") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.Property("Qualification") + .HasColumnType("int"); + + b.Property("WorkExperience") + .HasColumnType("int"); + + b.HasKey("Id"); + + b.ToTable("Implementers"); + }); + + modelBuilder.Entity("AbstractSoftwareInstallationDatabaseImplement.Models.Package", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("int"); + + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); + + b.Property("PackageName") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.Property("Price") + .HasColumnType("float"); + + b.HasKey("Id"); + + b.ToTable("Packages"); + }); + + modelBuilder.Entity("AbstractSoftwareInstallationDatabaseImplement.Models.PackageSoftware", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("int"); + + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); + + b.Property("Count") + .HasColumnType("int"); + + b.Property("PackageId") + .HasColumnType("int"); + + b.Property("SoftwareId") + .HasColumnType("int"); + + b.HasKey("Id"); + + b.HasIndex("PackageId"); + + b.HasIndex("SoftwareId"); + + b.ToTable("PackageSoftwares"); + }); + + modelBuilder.Entity("AbstractSoftwareInstallationDatabaseImplement.Models.Software", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("int"); + + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); + + b.Property("Cost") + .HasColumnType("float"); + + b.Property("SoftwareName") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.HasKey("Id"); + + b.ToTable("Softwares"); + }); + + modelBuilder.Entity("AbstractPackageInstallationDatabaseImplement.Models.Order", b => + { + b.HasOne("AbstractSoftwareInstallationDatabaseImplement.Models.Client", "Client") + .WithMany("Orders") + .HasForeignKey("ClientId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.HasOne("AbstractSoftwareInstallationDatabaseImplement.Models.Implementer", null) + .WithMany("Orders") + .HasForeignKey("ImplementerId"); + + b.HasOne("AbstractSoftwareInstallationDatabaseImplement.Models.Package", "Package") + .WithMany("Orders") + .HasForeignKey("PackageId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.Navigation("Client"); + + b.Navigation("Package"); + }); + + modelBuilder.Entity("AbstractSoftwareInstallationDatabaseImplement.Models.PackageSoftware", b => + { + b.HasOne("AbstractSoftwareInstallationDatabaseImplement.Models.Package", "Package") + .WithMany("Softwares") + .HasForeignKey("PackageId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.HasOne("AbstractSoftwareInstallationDatabaseImplement.Models.Software", "Software") + .WithMany("PackageSoftwares") + .HasForeignKey("SoftwareId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.Navigation("Package"); + + b.Navigation("Software"); + }); + + modelBuilder.Entity("AbstractSoftwareInstallationDatabaseImplement.Models.Client", b => + { + b.Navigation("Orders"); + }); + + modelBuilder.Entity("AbstractSoftwareInstallationDatabaseImplement.Models.Implementer", b => + { + b.Navigation("Orders"); + }); + + modelBuilder.Entity("AbstractSoftwareInstallationDatabaseImplement.Models.Package", b => + { + b.Navigation("Orders"); + + b.Navigation("Softwares"); + }); + + modelBuilder.Entity("AbstractSoftwareInstallationDatabaseImplement.Models.Software", b => + { + b.Navigation("PackageSoftwares"); + }); +#pragma warning restore 612, 618 + } + } +} diff --git a/SoftwareInstallation/AbstractSoftwareInstallationDatabaseImplement/Migrations/20230423193329_Implementer.cs b/SoftwareInstallation/AbstractSoftwareInstallationDatabaseImplement/Migrations/20230423193329_Implementer.cs new file mode 100644 index 0000000..9c24aaf --- /dev/null +++ b/SoftwareInstallation/AbstractSoftwareInstallationDatabaseImplement/Migrations/20230423193329_Implementer.cs @@ -0,0 +1,67 @@ +using Microsoft.EntityFrameworkCore.Migrations; + +#nullable disable + +namespace AbstractSoftwareInstallationDatabaseImplement.Migrations +{ + /// + public partial class Implementer : Migration + { + /// + protected override void Up(MigrationBuilder migrationBuilder) + { + migrationBuilder.AddColumn( + name: "ImplementerId", + table: "Orders", + type: "int", + nullable: true); + + migrationBuilder.CreateTable( + name: "Implementers", + columns: table => new + { + Id = table.Column(type: "int", nullable: false) + .Annotation("SqlServer:Identity", "1, 1"), + Qualification = table.Column(type: "int", nullable: false), + ImplementerFIO = table.Column(type: "nvarchar(max)", nullable: false), + WorkExperience = table.Column(type: "int", nullable: false), + Password = table.Column(type: "nvarchar(max)", nullable: false) + }, + constraints: table => + { + table.PrimaryKey("PK_Implementers", x => x.Id); + }); + + migrationBuilder.CreateIndex( + name: "IX_Orders_ImplementerId", + table: "Orders", + column: "ImplementerId"); + + migrationBuilder.AddForeignKey( + name: "FK_Orders_Implementers_ImplementerId", + table: "Orders", + column: "ImplementerId", + principalTable: "Implementers", + principalColumn: "Id"); + } + + /// + protected override void Down(MigrationBuilder migrationBuilder) + { + migrationBuilder.DropForeignKey( + name: "FK_Orders_Implementers_ImplementerId", + table: "Orders"); + + migrationBuilder.DropTable( + name: "Implementers"); + + migrationBuilder.DropIndex( + name: "IX_Orders_ImplementerId", + table: "Orders"); + + migrationBuilder.DropColumn( + name: "ImplementerId", + table: "Orders"); + } + } +} diff --git a/SoftwareInstallation/AbstractSoftwareInstallationDatabaseImplement/Migrations/20230423205115_OrderUPDATE.Designer.cs b/SoftwareInstallation/AbstractSoftwareInstallationDatabaseImplement/Migrations/20230423205115_OrderUPDATE.Designer.cs new file mode 100644 index 0000000..3e8fb73 --- /dev/null +++ b/SoftwareInstallation/AbstractSoftwareInstallationDatabaseImplement/Migrations/20230423205115_OrderUPDATE.Designer.cs @@ -0,0 +1,259 @@ +// +using System; +using AbstractSoftwareInstallationDatabaseImplement; +using Microsoft.EntityFrameworkCore; +using Microsoft.EntityFrameworkCore.Infrastructure; +using Microsoft.EntityFrameworkCore.Metadata; +using Microsoft.EntityFrameworkCore.Migrations; +using Microsoft.EntityFrameworkCore.Storage.ValueConversion; + +#nullable disable + +namespace AbstractSoftwareInstallationDatabaseImplement.Migrations +{ + [DbContext(typeof(AbstractSoftwareInstallationDatabase))] + [Migration("20230423205115_OrderUPDATE")] + partial class OrderUPDATE + { + /// + protected override void BuildTargetModel(ModelBuilder modelBuilder) + { +#pragma warning disable 612, 618 + modelBuilder + .HasAnnotation("ProductVersion", "7.0.4") + .HasAnnotation("Relational:MaxIdentifierLength", 128); + + SqlServerModelBuilderExtensions.UseIdentityColumns(modelBuilder); + + modelBuilder.Entity("AbstractPackageInstallationDatabaseImplement.Models.Order", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("int"); + + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); + + b.Property("ClientId") + .HasColumnType("int"); + + b.Property("Count") + .HasColumnType("int"); + + b.Property("DateCreate") + .HasColumnType("datetime2"); + + b.Property("DateImplement") + .HasColumnType("datetime2"); + + b.Property("ImplementerId") + .HasColumnType("int"); + + b.Property("PackageId") + .HasColumnType("int"); + + b.Property("Status") + .HasColumnType("int"); + + b.Property("Sum") + .HasColumnType("float"); + + b.HasKey("Id"); + + b.HasIndex("ClientId"); + + b.HasIndex("ImplementerId"); + + b.HasIndex("PackageId"); + + b.ToTable("Orders"); + }); + + modelBuilder.Entity("AbstractSoftwareInstallationDatabaseImplement.Models.Client", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("int"); + + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); + + b.Property("ClientFIO") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.Property("Email") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.Property("Password") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.HasKey("Id"); + + b.ToTable("Clients"); + }); + + modelBuilder.Entity("AbstractSoftwareInstallationDatabaseImplement.Models.Implementer", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("int"); + + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); + + b.Property("ImplementerFIO") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.Property("Password") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.Property("Qualification") + .HasColumnType("int"); + + b.Property("WorkExperience") + .HasColumnType("int"); + + b.HasKey("Id"); + + b.ToTable("Implementers"); + }); + + modelBuilder.Entity("AbstractSoftwareInstallationDatabaseImplement.Models.Package", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("int"); + + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); + + b.Property("PackageName") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.Property("Price") + .HasColumnType("float"); + + b.HasKey("Id"); + + b.ToTable("Packages"); + }); + + modelBuilder.Entity("AbstractSoftwareInstallationDatabaseImplement.Models.PackageSoftware", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("int"); + + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); + + b.Property("Count") + .HasColumnType("int"); + + b.Property("PackageId") + .HasColumnType("int"); + + b.Property("SoftwareId") + .HasColumnType("int"); + + b.HasKey("Id"); + + b.HasIndex("PackageId"); + + b.HasIndex("SoftwareId"); + + b.ToTable("PackageSoftwares"); + }); + + modelBuilder.Entity("AbstractSoftwareInstallationDatabaseImplement.Models.Software", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("int"); + + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); + + b.Property("Cost") + .HasColumnType("float"); + + b.Property("SoftwareName") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.HasKey("Id"); + + b.ToTable("Softwares"); + }); + + modelBuilder.Entity("AbstractPackageInstallationDatabaseImplement.Models.Order", b => + { + b.HasOne("AbstractSoftwareInstallationDatabaseImplement.Models.Client", "Client") + .WithMany("Orders") + .HasForeignKey("ClientId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.HasOne("AbstractSoftwareInstallationDatabaseImplement.Models.Implementer", "Implementer") + .WithMany("Orders") + .HasForeignKey("ImplementerId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.HasOne("AbstractSoftwareInstallationDatabaseImplement.Models.Package", "Package") + .WithMany("Orders") + .HasForeignKey("PackageId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.Navigation("Client"); + + b.Navigation("Implementer"); + + b.Navigation("Package"); + }); + + modelBuilder.Entity("AbstractSoftwareInstallationDatabaseImplement.Models.PackageSoftware", b => + { + b.HasOne("AbstractSoftwareInstallationDatabaseImplement.Models.Package", "Package") + .WithMany("Softwares") + .HasForeignKey("PackageId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.HasOne("AbstractSoftwareInstallationDatabaseImplement.Models.Software", "Software") + .WithMany("PackageSoftwares") + .HasForeignKey("SoftwareId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.Navigation("Package"); + + b.Navigation("Software"); + }); + + modelBuilder.Entity("AbstractSoftwareInstallationDatabaseImplement.Models.Client", b => + { + b.Navigation("Orders"); + }); + + modelBuilder.Entity("AbstractSoftwareInstallationDatabaseImplement.Models.Implementer", b => + { + b.Navigation("Orders"); + }); + + modelBuilder.Entity("AbstractSoftwareInstallationDatabaseImplement.Models.Package", b => + { + b.Navigation("Orders"); + + b.Navigation("Softwares"); + }); + + modelBuilder.Entity("AbstractSoftwareInstallationDatabaseImplement.Models.Software", b => + { + b.Navigation("PackageSoftwares"); + }); +#pragma warning restore 612, 618 + } + } +} diff --git a/SoftwareInstallation/AbstractSoftwareInstallationDatabaseImplement/Migrations/20230423205115_OrderUPDATE.cs b/SoftwareInstallation/AbstractSoftwareInstallationDatabaseImplement/Migrations/20230423205115_OrderUPDATE.cs new file mode 100644 index 0000000..cb79582 --- /dev/null +++ b/SoftwareInstallation/AbstractSoftwareInstallationDatabaseImplement/Migrations/20230423205115_OrderUPDATE.cs @@ -0,0 +1,59 @@ +using Microsoft.EntityFrameworkCore.Migrations; + +#nullable disable + +namespace AbstractSoftwareInstallationDatabaseImplement.Migrations +{ + /// + public partial class OrderUPDATE : Migration + { + /// + protected override void Up(MigrationBuilder migrationBuilder) + { + migrationBuilder.DropForeignKey( + name: "FK_Orders_Implementers_ImplementerId", + table: "Orders"); + + migrationBuilder.AlterColumn( + name: "ImplementerId", + table: "Orders", + type: "int", + nullable: false, + defaultValue: 0, + oldClrType: typeof(int), + oldType: "int", + oldNullable: true); + + migrationBuilder.AddForeignKey( + name: "FK_Orders_Implementers_ImplementerId", + table: "Orders", + column: "ImplementerId", + principalTable: "Implementers", + principalColumn: "Id", + onDelete: ReferentialAction.Cascade); + } + + /// + protected override void Down(MigrationBuilder migrationBuilder) + { + migrationBuilder.DropForeignKey( + name: "FK_Orders_Implementers_ImplementerId", + table: "Orders"); + + migrationBuilder.AlterColumn( + name: "ImplementerId", + table: "Orders", + type: "int", + nullable: true, + oldClrType: typeof(int), + oldType: "int"); + + migrationBuilder.AddForeignKey( + name: "FK_Orders_Implementers_ImplementerId", + table: "Orders", + column: "ImplementerId", + principalTable: "Implementers", + principalColumn: "Id"); + } + } +} diff --git a/SoftwareInstallation/AbstractSoftwareInstallationDatabaseImplement/Migrations/AbstractSoftwareInstallationDatabaseModelSnapshot.cs b/SoftwareInstallation/AbstractSoftwareInstallationDatabaseImplement/Migrations/AbstractSoftwareInstallationDatabaseModelSnapshot.cs new file mode 100644 index 0000000..51e1636 --- /dev/null +++ b/SoftwareInstallation/AbstractSoftwareInstallationDatabaseImplement/Migrations/AbstractSoftwareInstallationDatabaseModelSnapshot.cs @@ -0,0 +1,256 @@ +// +using System; +using AbstractSoftwareInstallationDatabaseImplement; +using Microsoft.EntityFrameworkCore; +using Microsoft.EntityFrameworkCore.Infrastructure; +using Microsoft.EntityFrameworkCore.Metadata; +using Microsoft.EntityFrameworkCore.Storage.ValueConversion; + +#nullable disable + +namespace AbstractSoftwareInstallationDatabaseImplement.Migrations +{ + [DbContext(typeof(AbstractSoftwareInstallationDatabase))] + partial class AbstractSoftwareInstallationDatabaseModelSnapshot : ModelSnapshot + { + protected override void BuildModel(ModelBuilder modelBuilder) + { +#pragma warning disable 612, 618 + modelBuilder + .HasAnnotation("ProductVersion", "7.0.4") + .HasAnnotation("Relational:MaxIdentifierLength", 128); + + SqlServerModelBuilderExtensions.UseIdentityColumns(modelBuilder); + + modelBuilder.Entity("AbstractPackageInstallationDatabaseImplement.Models.Order", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("int"); + + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); + + b.Property("ClientId") + .HasColumnType("int"); + + b.Property("Count") + .HasColumnType("int"); + + b.Property("DateCreate") + .HasColumnType("datetime2"); + + b.Property("DateImplement") + .HasColumnType("datetime2"); + + b.Property("ImplementerId") + .HasColumnType("int"); + + b.Property("PackageId") + .HasColumnType("int"); + + b.Property("Status") + .HasColumnType("int"); + + b.Property("Sum") + .HasColumnType("float"); + + b.HasKey("Id"); + + b.HasIndex("ClientId"); + + b.HasIndex("ImplementerId"); + + b.HasIndex("PackageId"); + + b.ToTable("Orders"); + }); + + modelBuilder.Entity("AbstractSoftwareInstallationDatabaseImplement.Models.Client", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("int"); + + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); + + b.Property("ClientFIO") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.Property("Email") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.Property("Password") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.HasKey("Id"); + + b.ToTable("Clients"); + }); + + modelBuilder.Entity("AbstractSoftwareInstallationDatabaseImplement.Models.Implementer", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("int"); + + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); + + b.Property("ImplementerFIO") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.Property("Password") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.Property("Qualification") + .HasColumnType("int"); + + b.Property("WorkExperience") + .HasColumnType("int"); + + b.HasKey("Id"); + + b.ToTable("Implementers"); + }); + + modelBuilder.Entity("AbstractSoftwareInstallationDatabaseImplement.Models.Package", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("int"); + + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); + + b.Property("PackageName") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.Property("Price") + .HasColumnType("float"); + + b.HasKey("Id"); + + b.ToTable("Packages"); + }); + + modelBuilder.Entity("AbstractSoftwareInstallationDatabaseImplement.Models.PackageSoftware", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("int"); + + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); + + b.Property("Count") + .HasColumnType("int"); + + b.Property("PackageId") + .HasColumnType("int"); + + b.Property("SoftwareId") + .HasColumnType("int"); + + b.HasKey("Id"); + + b.HasIndex("PackageId"); + + b.HasIndex("SoftwareId"); + + b.ToTable("PackageSoftwares"); + }); + + modelBuilder.Entity("AbstractSoftwareInstallationDatabaseImplement.Models.Software", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("int"); + + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); + + b.Property("Cost") + .HasColumnType("float"); + + b.Property("SoftwareName") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.HasKey("Id"); + + b.ToTable("Softwares"); + }); + + modelBuilder.Entity("AbstractPackageInstallationDatabaseImplement.Models.Order", b => + { + b.HasOne("AbstractSoftwareInstallationDatabaseImplement.Models.Client", "Client") + .WithMany("Orders") + .HasForeignKey("ClientId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.HasOne("AbstractSoftwareInstallationDatabaseImplement.Models.Implementer", "Implementer") + .WithMany("Orders") + .HasForeignKey("ImplementerId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.HasOne("AbstractSoftwareInstallationDatabaseImplement.Models.Package", "Package") + .WithMany("Orders") + .HasForeignKey("PackageId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.Navigation("Client"); + + b.Navigation("Implementer"); + + b.Navigation("Package"); + }); + + modelBuilder.Entity("AbstractSoftwareInstallationDatabaseImplement.Models.PackageSoftware", b => + { + b.HasOne("AbstractSoftwareInstallationDatabaseImplement.Models.Package", "Package") + .WithMany("Softwares") + .HasForeignKey("PackageId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.HasOne("AbstractSoftwareInstallationDatabaseImplement.Models.Software", "Software") + .WithMany("PackageSoftwares") + .HasForeignKey("SoftwareId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.Navigation("Package"); + + b.Navigation("Software"); + }); + + modelBuilder.Entity("AbstractSoftwareInstallationDatabaseImplement.Models.Client", b => + { + b.Navigation("Orders"); + }); + + modelBuilder.Entity("AbstractSoftwareInstallationDatabaseImplement.Models.Implementer", b => + { + b.Navigation("Orders"); + }); + + modelBuilder.Entity("AbstractSoftwareInstallationDatabaseImplement.Models.Package", b => + { + b.Navigation("Orders"); + + b.Navigation("Softwares"); + }); + + modelBuilder.Entity("AbstractSoftwareInstallationDatabaseImplement.Models.Software", b => + { + b.Navigation("PackageSoftwares"); + }); +#pragma warning restore 612, 618 + } + } +} diff --git a/SoftwareInstallation/AbstractSoftwareInstallationDatabaseImplement/Models/Client.cs b/SoftwareInstallation/AbstractSoftwareInstallationDatabaseImplement/Models/Client.cs new file mode 100644 index 0000000..f53311f --- /dev/null +++ b/SoftwareInstallation/AbstractSoftwareInstallationDatabaseImplement/Models/Client.cs @@ -0,0 +1,59 @@ +using AbstractPackageInstallationDatabaseImplement.Models; +using AbstractSoftwareInstallationContracts.BindingModels; +using AbstractSoftwareInstallationContracts.ViewModels; +using AbstractSoftwareInstallationDataModels.Models; +using System; +using System.Collections.Generic; +using System.ComponentModel.DataAnnotations; +using System.ComponentModel.DataAnnotations.Schema; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace AbstractSoftwareInstallationDatabaseImplement.Models +{ + public class Client : IClientModel + { + public int Id { get; private set; } + [Required] + public string ClientFIO { get; private set; } = string.Empty; + [Required] + public string Email { get; private set; } = string.Empty; + [Required] + public string Password { get; private set; } = string.Empty; + [ForeignKey("ClientId")] + public virtual List Orders { get; set; } = new(); + + public static Client? Create(ClientBindingModel? model) + { + if (model == null) + { + return null; + } + return new Client() + { + Id = model.Id, + ClientFIO = model.ClientFIO, + Email = model.Email, + Password = model.Password + }; + } + public void Update(ClientBindingModel? model) + { + if (model == null) + { + return; + } + ClientFIO = model.ClientFIO; + Email = model.Email; + Password = model.Password; + } + public ClientViewModel GetViewModel => new() + { + Id = Id, + ClientFIO = ClientFIO, + Email = Email, + Password = Password + }; + } +} diff --git a/SoftwareInstallation/AbstractSoftwareInstallationDatabaseImplement/Models/Implementer.cs b/SoftwareInstallation/AbstractSoftwareInstallationDatabaseImplement/Models/Implementer.cs new file mode 100644 index 0000000..a8ef5b3 --- /dev/null +++ b/SoftwareInstallation/AbstractSoftwareInstallationDatabaseImplement/Models/Implementer.cs @@ -0,0 +1,64 @@ +using AbstractPackageInstallationDatabaseImplement.Models; +using AbstractSoftwareInstallationContracts.BindingModels; +using AbstractSoftwareInstallationContracts.ViewModels; +using AbstractSoftwareInstallationDataModels.Models; +using System; +using System.Collections.Generic; +using System.ComponentModel.DataAnnotations; +using System.ComponentModel.DataAnnotations.Schema; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace AbstractSoftwareInstallationDatabaseImplement.Models +{ + public class Implementer : IImplementerModel + { + public int Id { get; private set; } + [Required] + public int Qualification { get; private set; } + [Required] + public string ImplementerFIO { get; private set; } = string.Empty; + [Required] + public int WorkExperience { get; private set; } + [Required] + public string Password { get; private set; } = string.Empty; + [ForeignKey("ImplementerId")] + public virtual List Orders { get; set; } = new(); + + public static Implementer? Create(ImplementerBindingModel? model) + { + if (model == null) + { + return null; + } + return new Implementer() + { + Id = model.Id, + Qualification = model.Qualification, + ImplementerFIO = model.ImplementerFIO, + WorkExperience = model.WorkExperience, + Password = model.Password + }; + } + public void Update(ImplementerBindingModel? model) + { + if (model == null) + { + return; + } + Qualification = model.Qualification; + ImplementerFIO = model.ImplementerFIO; + WorkExperience = model.WorkExperience; + Password = model.Password; + } + public ImplementerViewModel GetViewModel => new() + { + Id = Id, + Qualification = Qualification, + ImplementerFIO = ImplementerFIO, + WorkExperience = WorkExperience, + Password = Password + }; + } +} diff --git a/SoftwareInstallation/AbstractSoftwareInstallationDatabaseImplement/Models/Order.cs b/SoftwareInstallation/AbstractSoftwareInstallationDatabaseImplement/Models/Order.cs new file mode 100644 index 0000000..9d27cb2 --- /dev/null +++ b/SoftwareInstallation/AbstractSoftwareInstallationDatabaseImplement/Models/Order.cs @@ -0,0 +1,84 @@ +using AbstractSoftwareInstallationContracts.BindingModels; +using AbstractSoftwareInstallationContracts.ViewModels; +using AbstractSoftwareInstallationDatabaseImplement; +using AbstractSoftwareInstallationDatabaseImplement.Models; +using AbstractSoftwareInstallationDataModels; +using AbstractSoftwareInstallationDataModels.Models; +using System; +using System.Collections.Generic; +using System.ComponentModel.DataAnnotations; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace AbstractPackageInstallationDatabaseImplement.Models +{ + public class Order : IOrderModel + { + public int Id { get; private set; } + [Required] + public int PackageId { get; private set; } + [Required] + public int ClientId { get; private set; } + [Required] + public int ImplementerId { get; private set; } + [Required] + public int Count { get; private set; } + [Required] + public double Sum { get; private set; } + [Required] + public OrderStatus Status { get; private set; } = OrderStatus.Неизвестен; + [Required] + public DateTime DateCreate { get; private set; } = DateTime.Now; + + public DateTime? DateImplement { get; private set; } + public virtual Package Package { get; set; } + public virtual Client Client { get; set; } + public virtual Implementer Implementer { get; set; } + public static Order? Create(OrderBindingModel? model) + { + if (model == null) + { + return null; + } + return new Order + { + PackageId = model.PackageId, + ClientId = model.ClientId, + ImplementerId = model.ImplementerId, + Count = model.Count, + Sum = model.Sum, + Status = model.Status, + DateCreate = model.DateCreate, + DateImplement = model.DateImplement, + Id = model.Id + }; + } + + public void Update(OrderBindingModel? model) + { + if (model == null) + { + return; + } + Status = model.Status; + DateImplement = model.DateImplement; + } + + public OrderViewModel GetViewModel => new() + { + Id = Id, + PackageId = PackageId, + ClientId = ClientId, + ImplementerId = ImplementerId, + Count = Count, + Sum = Sum, + Status = Status, + DateCreate = DateCreate, + DateImplement = DateImplement, + PackageName = Package.PackageName, + Email = Client.Email, + ImplementerFIO = Implementer.ImplementerFIO + }; + } +} diff --git a/SoftwareInstallation/AbstractSoftwareInstallationDatabaseImplement/Models/Package.cs b/SoftwareInstallation/AbstractSoftwareInstallationDatabaseImplement/Models/Package.cs new file mode 100644 index 0000000..e2578bb --- /dev/null +++ b/SoftwareInstallation/AbstractSoftwareInstallationDatabaseImplement/Models/Package.cs @@ -0,0 +1,107 @@ +using AbstractPackageInstallationDatabaseImplement.Models; +using AbstractSoftwareInstallationContracts.BindingModels; +using AbstractSoftwareInstallationContracts.ViewModels; +using AbstractSoftwareInstallationDatabaseImplement.Models; +using AbstractSoftwareInstallationDataModels; +using AbstractSoftwareInstallationDataModels.Models; +using System; +using System.Collections.Generic; +using System.ComponentModel.DataAnnotations; +using System.ComponentModel.DataAnnotations.Schema; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace AbstractSoftwareInstallationDatabaseImplement.Models +{ + public class Package : IPackageModel + { + public int Id { get; private set; } + [Required] + public string PackageName { get; private set; } = string.Empty; + [Required] + public double Price { get; private set; } + + private Dictionary? _packageSoftwares = null; + + [NotMapped] + public Dictionary PackageSoftware + { + get + { + if (_packageSoftwares == null) + { + _packageSoftwares = Softwares.ToDictionary(recPC => recPC.SoftwareId, recPC => (recPC.Software as ISoftwareModel, recPC.Count)); + } + return _packageSoftwares; + } + } + + [ForeignKey("PackageId")] + public virtual List Softwares { get; set; } = new(); + [ForeignKey("PackageId")] + public virtual List Orders { get; set; } = new(); + + + public static Package? Create(AbstractSoftwareInstallationDatabase context, PackageBindingModel model) + { + var Softwares = context.Softwares; + + return new Package() + { + Id = model.Id, + PackageName = model.PackageName, + Price = model.Price, + Softwares = model.PackageSoftware.Select(x => new PackageSoftware + { + Software = context.Softwares.First(y => y.Id == x.Key), + Count = x.Value.Item2 + }).ToList() + }; + } + + public void Update(PackageBindingModel model) + { + PackageName = model.PackageName; + Price = model.Price; + } + public PackageViewModel GetViewModel => new() + { + Id = Id, + PackageName = PackageName, + Price = Price, + PackageSoftware = PackageSoftware + }; + + public void UpdateSoftwares(AbstractSoftwareInstallationDatabase context, PackageBindingModel model) + { + var packageSoftwares = context.PackageSoftwares + .Where(rec => rec.PackageId == model.Id).ToList(); + if (packageSoftwares != null && packageSoftwares.Count > 0) + { // удалили те, которых нет в модели + context.PackageSoftwares.RemoveRange(packageSoftwares.Where(rec => !model.PackageSoftware.ContainsKey(rec.SoftwareId))); + context.SaveChanges(); + // обновили количество у существующих записей + foreach (var updateSoftware in packageSoftwares) + { + updateSoftware.Count = model.PackageSoftware[updateSoftware.SoftwareId].Item2; + model.PackageSoftware.Remove(updateSoftware.SoftwareId); + } + context.SaveChanges(); + } + var package = context.Packages.First(x => x.Id == Id); + foreach (var pc in model.PackageSoftware) + { + context.PackageSoftwares.Add(new PackageSoftware + { + Package = package, + Software = context.Softwares.First(x => x.Id == pc.Key), + Count = pc.Value.Item2 + }); + context.SaveChanges(); + } + _packageSoftwares = null; + } + + } +} diff --git a/SoftwareInstallation/AbstractSoftwareInstallationDatabaseImplement/Models/PackageSoftware.cs b/SoftwareInstallation/AbstractSoftwareInstallationDatabaseImplement/Models/PackageSoftware.cs new file mode 100644 index 0000000..eeca146 --- /dev/null +++ b/SoftwareInstallation/AbstractSoftwareInstallationDatabaseImplement/Models/PackageSoftware.cs @@ -0,0 +1,22 @@ +using System; +using System.Collections.Generic; +using System.ComponentModel.DataAnnotations; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace AbstractSoftwareInstallationDatabaseImplement.Models +{ + public class PackageSoftware + { + public int Id { get; set; } + [Required] + public int PackageId { get; set; } + [Required] + public int SoftwareId { get; set; } + [Required] + public int Count { get; set; } + public virtual Software Software { get; set; } = new(); + public virtual Package Package { get; set; } = new(); + } +} diff --git a/SoftwareInstallation/AbstractSoftwareInstallationDatabaseImplement/Models/Software.cs b/SoftwareInstallation/AbstractSoftwareInstallationDatabaseImplement/Models/Software.cs new file mode 100644 index 0000000..d7e9151 --- /dev/null +++ b/SoftwareInstallation/AbstractSoftwareInstallationDatabaseImplement/Models/Software.cs @@ -0,0 +1,53 @@ +using AbstractSoftwareInstallationContracts.BindingModels; +using AbstractSoftwareInstallationContracts.ViewModels; +using AbstractSoftwareInstallationDataModels.Models; +using System; +using System.Collections.Generic; +using System.ComponentModel.DataAnnotations; +using System.ComponentModel.DataAnnotations.Schema; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace AbstractSoftwareInstallationDatabaseImplement.Models +{ + public class Software : ISoftwareModel + { + public int Id { get; private set; } + [Required] + public string SoftwareName { get; private set; } = String.Empty; + [Required] + public double Cost { get; set; } + [ForeignKey("SoftwareId")] + public virtual List PackageSoftwares { get; set; } = new(); + public static Software? Create(SoftwareBindingModel? model) + { + if (model == null) + { + return null; + } + return new Software() + { + Id = model.Id, + SoftwareName = model.SoftwareName, + Cost = model.Cost + }; + } + public void Update(SoftwareBindingModel? model) + { + if (model == null) + { + return; + } + SoftwareName = model.SoftwareName; + Cost = model.Cost; + } + public SoftwareViewModel GetViewModel => new() + { + Id = Id, + SoftwareName = SoftwareName, + Cost = Cost + }; + + } +}