diff --git a/SoftwareInstallation/AbstractSoftwareInstallationContracts/BindingModels/PackageBindingModel.cs b/SoftwareInstallation/AbstractSoftwareInstallationContracts/BindingModels/PackageBindingModel.cs index 4128929..207d5b9 100644 --- a/SoftwareInstallation/AbstractSoftwareInstallationContracts/BindingModels/PackageBindingModel.cs +++ b/SoftwareInstallation/AbstractSoftwareInstallationContracts/BindingModels/PackageBindingModel.cs @@ -13,5 +13,6 @@ namespace AbstractSoftwareInstallationContracts.BindingModels public string PackageName { get; set; } = string.Empty; public double Price { get; set; } public Dictionary PackageSoftware{get;set;} = new(); + } } \ No newline at end of file diff --git a/SoftwareInstallation/AbstractSoftwareInstallationDatabaseImplement/Implements/ClientStorage.cs b/SoftwareInstallation/AbstractSoftwareInstallationDatabaseImplement/Implements/ClientStorage.cs deleted file mode 100644 index a7496be..0000000 --- a/SoftwareInstallation/AbstractSoftwareInstallationDatabaseImplement/Implements/ClientStorage.cs +++ /dev/null @@ -1,89 +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 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 deleted file mode 100644 index e010416..0000000 --- a/SoftwareInstallation/AbstractSoftwareInstallationDatabaseImplement/Implements/ImplementerStorage.cs +++ /dev/null @@ -1,84 +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 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/Migrations/20230422195123_Client.Designer.cs b/SoftwareInstallation/AbstractSoftwareInstallationDatabaseImplement/Migrations/20230422195123_Client.Designer.cs deleted file mode 100644 index 4f61cbf..0000000 --- a/SoftwareInstallation/AbstractSoftwareInstallationDatabaseImplement/Migrations/20230422195123_Client.Designer.cs +++ /dev/null @@ -1,214 +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("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 deleted file mode 100644 index 1e199b5..0000000 --- a/SoftwareInstallation/AbstractSoftwareInstallationDatabaseImplement/Migrations/20230422195123_Client.cs +++ /dev/null @@ -1,68 +0,0 @@ -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 deleted file mode 100644 index f5b9aae..0000000 --- a/SoftwareInstallation/AbstractSoftwareInstallationDatabaseImplement/Migrations/20230423193329_Implementer.Designer.cs +++ /dev/null @@ -1,255 +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("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 deleted file mode 100644 index 9c24aaf..0000000 --- a/SoftwareInstallation/AbstractSoftwareInstallationDatabaseImplement/Migrations/20230423193329_Implementer.cs +++ /dev/null @@ -1,67 +0,0 @@ -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 deleted file mode 100644 index 3e8fb73..0000000 --- a/SoftwareInstallation/AbstractSoftwareInstallationDatabaseImplement/Migrations/20230423205115_OrderUPDATE.Designer.cs +++ /dev/null @@ -1,259 +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("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 deleted file mode 100644 index cb79582..0000000 --- a/SoftwareInstallation/AbstractSoftwareInstallationDatabaseImplement/Migrations/20230423205115_OrderUPDATE.cs +++ /dev/null @@ -1,59 +0,0 @@ -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/Models/Client.cs b/SoftwareInstallation/AbstractSoftwareInstallationDatabaseImplement/Models/Client.cs deleted file mode 100644 index f53311f..0000000 --- a/SoftwareInstallation/AbstractSoftwareInstallationDatabaseImplement/Models/Client.cs +++ /dev/null @@ -1,59 +0,0 @@ -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 deleted file mode 100644 index a8ef5b3..0000000 --- a/SoftwareInstallation/AbstractSoftwareInstallationDatabaseImplement/Models/Implementer.cs +++ /dev/null @@ -1,64 +0,0 @@ -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/AbstractSoftwareInstallationFileImplement/AbstractSoftwareInstallationFileImplement.csproj b/SoftwareInstallation/AbstractSoftwareInstallationFileImplement/AbstractSoftwareInstallationFileImplement.csproj deleted file mode 100644 index abac8cd..0000000 --- a/SoftwareInstallation/AbstractSoftwareInstallationFileImplement/AbstractSoftwareInstallationFileImplement.csproj +++ /dev/null @@ -1,14 +0,0 @@ - - - - net6.0 - enable - enable - - - - - - - - diff --git a/SoftwareInstallation/AbstractSoftwareInstallationFileImplement/DataFileSingleton.cs b/SoftwareInstallation/AbstractSoftwareInstallationFileImplement/DataFileSingleton.cs deleted file mode 100644 index 46b31f5..0000000 --- a/SoftwareInstallation/AbstractSoftwareInstallationFileImplement/DataFileSingleton.cs +++ /dev/null @@ -1,50 +0,0 @@ -using AbstractSoftwareInstallationFileImplement.Models; -using System.Xml.Linq; - -namespace AbstractSoftwareInstallationFileImplement -{ - internal class DataFileSingleton - { - - private static DataFileSingleton? instance; - private readonly string SoftwareFileName = "Software.xml"; - private readonly string OrderFileName = "Order.xml"; - private readonly string PackageFileName = "Package.xml"; - public List Softwares { get; private set; } - public List Orders { get; private set; } - public List Packages { get; private set; } - public static DataFileSingleton GetInstance() - { - if (instance == null) - { - instance = new DataFileSingleton(); - } - return instance; - } - public void SaveSoftwares() => SaveData(Softwares, SoftwareFileName, "Softwares", x => x.GetXElement); - public void SavePackages() => SaveData(Packages, PackageFileName, "Packages", x => x.GetXElement); - public void SaveOrders() => SaveData(Orders, OrderFileName, "Orders", x => x.GetXElement); - private DataFileSingleton() - { - Softwares = LoadData(SoftwareFileName, "Software", x => Software.Create(x)!)!; - Packages = LoadData(PackageFileName, "Package", x => Package.Create(x)!)!; - Orders = LoadData(OrderFileName, "Order", x => Order.Create(x)!)!; - } - private static List? LoadData(string filename, string xmlNodeName, Func selectFunction) - { - if (File.Exists(filename)) - { - return XDocument.Load(filename)?.Root?.Elements(xmlNodeName)?.Select(selectFunction)?.ToList(); - } - return new List(); - } - - private static void SaveData(List data, string filename, string xmlNodeName, Func selectFunction) - { - if (data != null) - { - new XDocument(new XElement(xmlNodeName, data.Select(selectFunction).ToArray())).Save(filename); - } - } - } -} diff --git a/SoftwareInstallation/AbstractSoftwareInstallationFileImplement/Implements/OrderStorage.cs b/SoftwareInstallation/AbstractSoftwareInstallationFileImplement/Implements/OrderStorage.cs deleted file mode 100644 index 6b6ba76..0000000 --- a/SoftwareInstallation/AbstractSoftwareInstallationFileImplement/Implements/OrderStorage.cs +++ /dev/null @@ -1,91 +0,0 @@ -using AbstractSoftwareInstallationContracts.BindingModels; -using AbstractSoftwareInstallationContracts.SearchModels; -using AbstractSoftwareInstallationContracts.StoragesContracts; -using AbstractSoftwareInstallationContracts.ViewModels; -using AbstractSoftwareInstallationFileImplement.Models; - -namespace AbstractSoftwareInstallationFileImplement.Implements -{ - public class OrderStorage : IOrderStorage - { - private readonly DataFileSingleton source; - - public OrderStorage() - { - source = DataFileSingleton.GetInstance(); - } - - public OrderViewModel? GetElement(OrderSearchModel model) - { - if (!model.Id.HasValue) - { - return null; - } - return GetViewModel(source.Orders.FirstOrDefault(x => (model.Id.HasValue && x.Id == model.Id))); - } - - public List GetFilteredList(OrderSearchModel model) - { - if (!model.Id.HasValue) - { - return new(); - } - return source.Orders - .Where(x => x.Id == model.Id) - .Select(x => GetViewModel(x)) - .ToList(); - } - - public List GetFullList() - { - return source.Orders.Select(x => GetViewModel(x)).ToList(); - } - - public OrderViewModel? Insert(OrderBindingModel model) - { - model.Id = source.Orders.Count > 0 ? source.Orders.Max(x => x.Id) + 1 : 1; - var newOrder = Order.Create(model); - if (newOrder == null) - { - return null; - } - source.Orders.Add(newOrder); - source.SaveOrders(); - return GetViewModel(newOrder); - } - - public OrderViewModel? Update(OrderBindingModel model) - { - var order = source.Orders.FirstOrDefault(x => x.Id == model.Id); - if (order == null) - { - return null; - } - order.Update(model); - source.SaveOrders(); - return GetViewModel(order); - } - public OrderViewModel? Delete(OrderBindingModel model) - { - var order = source.Orders.FirstOrDefault(x => x.Id == model.Id); - if (order == null) - { - return null; - } - source.Orders.Remove(order); - source.SaveOrders(); - return GetViewModel(order); - } - - private OrderViewModel GetViewModel(Order order) - { - var viewModel = order.GetViewModel; - var package = source.Packages.FirstOrDefault(x => x.Id == order.PackageId); - if (package != null) - { - viewModel.PackageName = package.PackageName; - } - return viewModel; - } - } -} diff --git a/SoftwareInstallation/AbstractSoftwareInstallationFileImplement/Implements/PackageStorage.cs b/SoftwareInstallation/AbstractSoftwareInstallationFileImplement/Implements/PackageStorage.cs deleted file mode 100644 index e3f23cf..0000000 --- a/SoftwareInstallation/AbstractSoftwareInstallationFileImplement/Implements/PackageStorage.cs +++ /dev/null @@ -1,89 +0,0 @@ -using AbstractSoftwareInstallationContracts.BindingModels; -using AbstractSoftwareInstallationContracts.SearchModels; -using AbstractSoftwareInstallationContracts.StoragesContracts; -using AbstractSoftwareInstallationContracts.ViewModels; -using AbstractSoftwareInstallationFileImplement.Models; -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; - -namespace AbstractSoftwareInstallationFileImplement.Implements -{ - public class PackageStorage : IPackageStorage - { - private readonly DataFileSingleton source; - - public PackageStorage() - { - source = DataFileSingleton.GetInstance(); - } - - public PackageViewModel? GetElement(PackageSearchModel model) - { - if (string.IsNullOrEmpty(model.PackageName) && !model.Id.HasValue) - { - return null; - } - return source.Packages - .FirstOrDefault(x => - (!string.IsNullOrEmpty(model.PackageName) - && x.PackageName == model.PackageName) - || (model.Id.HasValue && x.Id == model.Id))?.GetViewModel; - } - - public List GetFilteredList(PackageSearchModel model) - { - if (string.IsNullOrEmpty(model.PackageName)) - { - return new(); - } - return source.Packages - .Where(x => x.PackageName.Contains(model.PackageName)) - .Select(x => x.GetViewModel) - .ToList(); - } - - public List GetFullList() - { - return source.Packages.Select(x => x.GetViewModel).ToList(); - } - - public PackageViewModel? Insert(PackageBindingModel model) - { - model.Id = source.Packages.Count > 0 ? source.Packages.Max(x => x.Id) + 1 : 1; - var newPackage = Package.Create(model); - if (newPackage == null) - { - return null; - } - source.Packages.Add(newPackage); - source.SavePackages(); - return newPackage.GetViewModel; - } - - public PackageViewModel? Update(PackageBindingModel model) - { - var Package = source.Packages.FirstOrDefault(x => x.Id == model.Id); - if (Package == null) - { - return null; - } - Package.Update(model); - source.SavePackages(); - return Package.GetViewModel; - } - public PackageViewModel? Delete(PackageBindingModel model) - { - var Package = source.Packages.FirstOrDefault(x => x.Id == model.Id); - if (Package == null) - { - return null; - } - source.Packages.Remove(Package); - source.SavePackages(); - return Package.GetViewModel; - } - } -} diff --git a/SoftwareInstallation/AbstractSoftwareInstallationFileImplement/Implements/SoftwareStorage.cs b/SoftwareInstallation/AbstractSoftwareInstallationFileImplement/Implements/SoftwareStorage.cs deleted file mode 100644 index 61d2332..0000000 --- a/SoftwareInstallation/AbstractSoftwareInstallationFileImplement/Implements/SoftwareStorage.cs +++ /dev/null @@ -1,77 +0,0 @@ -using AbstractSoftwareInstallationContracts.BindingModels; -using AbstractSoftwareInstallationContracts.SearchModels; -using AbstractSoftwareInstallationContracts.StoragesContracts; -using AbstractSoftwareInstallationContracts.ViewModels; -using AbstractSoftwareInstallationFileImplement.Models; - -namespace AbstractSoftwareInstallationFileImplement.Implements -{ - public class SoftwareStorage : ISoftwareStorage - { - private readonly DataFileSingleton _source; - public SoftwareStorage() - { - _source = DataFileSingleton.GetInstance(); - } - public List GetFullList() - { - return _source.Softwares.Select(x => x.GetViewModel).ToList(); - } - public List GetFilteredList(SoftwareSearchModel - model) - { - if (string.IsNullOrEmpty(model.SoftwareName)) - { - return new(); - } - return _source.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; - } - return _source.Softwares.FirstOrDefault(x => - (!string.IsNullOrEmpty(model.SoftwareName) - && x.SoftwareName == model.SoftwareName) - || (model.Id.HasValue && x.Id == model.Id))?.GetViewModel; - } - public SoftwareViewModel? Insert(SoftwareBindingModel model) - { - model.Id = _source.Softwares.Count > 0 ? _source.Softwares.Max(x => x.Id) + 1 : 1; - var newSoftware = Software.Create(model); - if (newSoftware == null) - { - return null; - } - _source.Softwares.Add(newSoftware); - _source.SaveSoftwares(); - return newSoftware.GetViewModel; - } - public SoftwareViewModel? Update(SoftwareBindingModel model) - { - var software = _source.Softwares.FirstOrDefault(x => x.Id == model.Id); - if (software == null) - { - return null; - } - software.Update(model); - _source.SaveSoftwares(); - return software.GetViewModel; - } - public SoftwareViewModel? Delete(SoftwareBindingModel model) - { - var software = _source.Softwares.FirstOrDefault(x => x.Id == model.Id); - if (software == null) - { - return null; - } - _source.Softwares.Remove(software); - _source.SaveSoftwares(); - return software.GetViewModel; - } - } -} diff --git a/SoftwareInstallation/AbstractSoftwareInstallationFileImplement/Models/Order.cs b/SoftwareInstallation/AbstractSoftwareInstallationFileImplement/Models/Order.cs deleted file mode 100644 index 0d5b520..0000000 --- a/SoftwareInstallation/AbstractSoftwareInstallationFileImplement/Models/Order.cs +++ /dev/null @@ -1,90 +0,0 @@ -using AbstractSoftwareInstallationContracts.BindingModels; -using AbstractSoftwareInstallationContracts.ViewModels; -using AbstractSoftwareInstallationDataModels; -using AbstractSoftwareInstallationDataModels.Models; -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; -using System.Xml.Linq; - -namespace AbstractSoftwareInstallationFileImplement.Models -{ - internal class Order : IOrderModel - { - public int PackageId { get; private set; } - - public int Count { get; private set; } - - public double Sum { get; private set; } - - public OrderStatus Status { get; private set; } = OrderStatus.Неизвестен; - - public DateTime DateCreate { get; private set; } = DateTime.Now; - - public DateTime? DateImplement { get; private set; } - - public int Id { get; private 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 static Order? Create(XElement element) - { - if (element == null) return null; - return new Order() - { - Id = Convert.ToInt32(element.Attribute("Id")!.Value), - PackageId = Convert.ToInt32(element.Element("PackageId")!.Value), - Sum = Convert.ToDouble(element.Element("Sum")!.Value), - Count = Convert.ToInt32(element.Element("Count")!.Value), - Status = (OrderStatus)Enum.Parse(typeof(OrderStatus), element.Element("Status")!.Value), - DateCreate = Convert.ToDateTime(element.Element("DateCreate")!.Value), - DateImplement = string.IsNullOrEmpty(element.Element("DateImplement")!.Value) ? null : Convert.ToDateTime(element.Element("DateImplement")!.Value) - }; - } - - 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 - }; - public XElement GetXElement => new( - "Order", - new XAttribute("Id", Id), - new XElement("PackageId", PackageId.ToString()), - new XElement("Count", Count.ToString()), - new XElement("Sum", Sum.ToString()), - new XElement("Status", Status.ToString()), - new XElement("DateCreate", DateCreate.ToString()), - new XElement("DateImplement", DateImplement.ToString()) - ); - } -} diff --git a/SoftwareInstallation/AbstractSoftwareInstallationFileImplement/Models/Package.cs b/SoftwareInstallation/AbstractSoftwareInstallationFileImplement/Models/Package.cs deleted file mode 100644 index 221fdae..0000000 --- a/SoftwareInstallation/AbstractSoftwareInstallationFileImplement/Models/Package.cs +++ /dev/null @@ -1,107 +0,0 @@ -using AbstractSoftwareInstallationContracts.BindingModels; -using AbstractSoftwareInstallationContracts.ViewModels; -using AbstractSoftwareInstallationDataModels.Models; -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; -using System.Xml.Linq; - -namespace AbstractSoftwareInstallationFileImplement.Models -{ - internal class Package : IPackageModel - { - public string PackageName { get; private set; } = string.Empty; - - public double Price { get; private set; } - - public int Id { get; private set; } - - public Dictionary Softwares { get; private set; } = new(); - - private Dictionary? _PackageSoftware = null; - public Dictionary PackageSoftware - { - get - { - if (_PackageSoftware == null) - { - var source = DataFileSingleton.GetInstance(); - _PackageSoftware = Softwares.ToDictionary( - x => x.Key, - y => ((source.Softwares.FirstOrDefault(z => z.Id == y.Key) as ISoftwareModel)!, y.Value) - ); - } - return _PackageSoftware; - } - } - - - public static Package? Create(PackageBindingModel? model) - { - if (model == null) - { - return null; - } - return new Package() - { - Id = model.Id, - PackageName = model.PackageName, - Price = model.Price, - Softwares = model.PackageSoftware.ToDictionary(x => x.Key, x => x.Value.Item2) - }; - } - - public static Package? Create(XElement element) - { - if (element == null) - { - return null; - } - return new Package() - { - Id = Convert.ToInt32(element.Attribute("Id")!.Value), - PackageName = element.Element("PackageName")!.Value, - Price = Convert.ToDouble(element.Element("Price")!.Value), - Softwares = element.Element("PackageSoftware")!.Elements("PackageSoftware").ToDictionary( - x => Convert.ToInt32(x.Element("Key")?.Value), - x => Convert.ToInt32(x.Element("Value")?.Value) - ) - }; - } - - - public void Update(PackageBindingModel? model) - { - if (model == null) - { - return; - } - PackageName = model.PackageName; - Price = model.Price; - Softwares = model.PackageSoftware.ToDictionary(x => x.Key, x => x.Value.Item2); - _PackageSoftware = null; - } - public PackageViewModel GetViewModel => new() - { - Id = Id, - PackageName = PackageName, - Price = Price, - PackageSoftware = PackageSoftware - }; - - public XElement GetXElement => new( - "Package", - new XAttribute("Id", Id), - new XElement("PackageName", PackageName), - new XElement("Price", Price.ToString()), - new XElement("PackageSoftware", Softwares.Select(x => - new XElement("PackageSoftware", - new XElement("Key", x.Key), - new XElement("Value", x.Value))) - .ToArray())); - - - } -} diff --git a/SoftwareInstallation/AbstractSoftwareInstallationFileImplement/Models/Software.cs b/SoftwareInstallation/AbstractSoftwareInstallationFileImplement/Models/Software.cs deleted file mode 100644 index 2107792..0000000 --- a/SoftwareInstallation/AbstractSoftwareInstallationFileImplement/Models/Software.cs +++ /dev/null @@ -1,64 +0,0 @@ -using AbstractSoftwareInstallationContracts.BindingModels; -using AbstractSoftwareInstallationContracts.ViewModels; -using AbstractSoftwareInstallationDataModels.Models; -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; -using System.Xml.Linq; - -namespace AbstractSoftwareInstallationFileImplement.Models -{ - internal class Software : ISoftwareModel - { - public int Id { get; private set; } - public string SoftwareName { get; private set; } = string.Empty; - public double Cost { get; set; } - public static Software? Create(SoftwareBindingModel model) - { - if (model == null) - { - return null; - } - return new Software() - { - Id = model.Id, - SoftwareName = model.SoftwareName, - Cost = model.Cost - }; - } - public static Software? Create(XElement element) - { - if (element == null) - { - return null; - } - return new Software() - { - Id = Convert.ToInt32(element.Attribute("Id")!.Value), - SoftwareName = element.Element("SoftwareName")!.Value, - Cost = Convert.ToDouble(element.Element("Cost")!.Value) - }; - } - 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 - }; - public XElement GetXElement => new("Software", - new XAttribute("Id", Id), - new XElement("SoftwareName", SoftwareName), - new XElement("Cost", Cost.ToString())); - } -}