diff --git a/COP/COP.sln b/COP/COP.sln index 021f9bf..854bfe4 100644 --- a/COP/COP.sln +++ b/COP/COP.sln @@ -7,6 +7,12 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "WinForms", "WinForms\WinFor EndProject Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "VisualCompLib", "VisualCompLib\VisualCompLib.csproj", "{FC1CFC63-5739-4519-B689-E8B614A9D106}" EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ClientsContracts", "ClientsContracts\ClientsContracts.csproj", "{849DCBC2-7B2D-43A5-87BD-CFE9BC4F0B6C}" +EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ClientBusinessLogic", "ClientBusinessLogic\ClientBusinessLogic.csproj", "{6A4A31E6-F956-4312-B63D-807ABF5CD63E}" +EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ClientsDatabaseImplement", "ClientsDatabaseImplement\ClientsDatabaseImplement.csproj", "{662252C6-5C66-43CD-8D94-5360E2761EB6}" +EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|Any CPU = Debug|Any CPU @@ -21,6 +27,18 @@ Global {FC1CFC63-5739-4519-B689-E8B614A9D106}.Debug|Any CPU.Build.0 = Debug|Any CPU {FC1CFC63-5739-4519-B689-E8B614A9D106}.Release|Any CPU.ActiveCfg = Release|Any CPU {FC1CFC63-5739-4519-B689-E8B614A9D106}.Release|Any CPU.Build.0 = Release|Any CPU + {849DCBC2-7B2D-43A5-87BD-CFE9BC4F0B6C}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {849DCBC2-7B2D-43A5-87BD-CFE9BC4F0B6C}.Debug|Any CPU.Build.0 = Debug|Any CPU + {849DCBC2-7B2D-43A5-87BD-CFE9BC4F0B6C}.Release|Any CPU.ActiveCfg = Release|Any CPU + {849DCBC2-7B2D-43A5-87BD-CFE9BC4F0B6C}.Release|Any CPU.Build.0 = Release|Any CPU + {6A4A31E6-F956-4312-B63D-807ABF5CD63E}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {6A4A31E6-F956-4312-B63D-807ABF5CD63E}.Debug|Any CPU.Build.0 = Debug|Any CPU + {6A4A31E6-F956-4312-B63D-807ABF5CD63E}.Release|Any CPU.ActiveCfg = Release|Any CPU + {6A4A31E6-F956-4312-B63D-807ABF5CD63E}.Release|Any CPU.Build.0 = Release|Any CPU + {662252C6-5C66-43CD-8D94-5360E2761EB6}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {662252C6-5C66-43CD-8D94-5360E2761EB6}.Debug|Any CPU.Build.0 = Debug|Any CPU + {662252C6-5C66-43CD-8D94-5360E2761EB6}.Release|Any CPU.ActiveCfg = Release|Any CPU + {662252C6-5C66-43CD-8D94-5360E2761EB6}.Release|Any CPU.Build.0 = Release|Any CPU EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE diff --git a/COP/ClientBusinessLogic/BusinessLogics/ClientLogic.cs b/COP/ClientBusinessLogic/BusinessLogics/ClientLogic.cs new file mode 100644 index 0000000..afc38e2 --- /dev/null +++ b/COP/ClientBusinessLogic/BusinessLogics/ClientLogic.cs @@ -0,0 +1,62 @@ +using ClientsContracts.BindingModels; +using ClientsContracts.BusinessLogicContracts; +using ClientsContracts.StorageContracts; +using ClientsContracts.ViewModels; + +namespace ClientBusinessLogic.BusinessLogics +{ + public class ClientLogic : IClientLogic + { + private readonly IClientStorage _clientStorage; + public ClientLogic(IClientStorage clientStorage) + { + _clientStorage = clientStorage; + } + public void CreateOrUpdate(ClientBindingModel model) + { + var element = _clientStorage.GetElement( + new ClientBindingModel + { + Reviews = model.Reviews, + Name = model.Name, + Status = model.Status, + Amount = model.Amount + }); + if (element != null && element.Id != model.Id) + { + throw new Exception("Клиент с таким именем уже существует"); + } + if (model.Id.HasValue) + { + _clientStorage.Update(model); + } + else + { + _clientStorage.Insert(model); + } + } + + public void Delete(ClientBindingModel model) + { + var element = _clientStorage.GetElement(new ClientBindingModel { Id = model.Id }); + if (element == null) + { + throw new Exception("Клиент не найден"); + } + _clientStorage.Delete(model); + } + + public List Read(ClientBindingModel model) + { + if (model == null) + { + return _clientStorage.GetFullList(); + } + if (model.Id.HasValue) + { + return new List { _clientStorage.GetElement(model) }; + } + return _clientStorage.GetFilteredList(model); + } + } +} diff --git a/COP/ClientBusinessLogic/BusinessLogics/StatusLogic.cs b/COP/ClientBusinessLogic/BusinessLogics/StatusLogic.cs new file mode 100644 index 0000000..bb0c8be --- /dev/null +++ b/COP/ClientBusinessLogic/BusinessLogics/StatusLogic.cs @@ -0,0 +1,60 @@ +using ClientsContracts.BindingModels; +using ClientsContracts.BusinessLogicContracts; +using ClientsContracts.StorageContracts; +using ClientsContracts.ViewModels; + +namespace ClientBusinessLogic.BusinessLogics +{ + public class StatusLogic : IStatusLogic + { + private readonly IStatusStorage _statusStorage; + public StatusLogic(IStatusStorage statusStorage) + { + _statusStorage = statusStorage; + } + + public void CreateOrUpdate(StatusBindingModel model) + { + var element = _statusStorage.GetElement( + new StatusBindingModel + { + Name = model.Name + }); + if (element != null && element.Id != model.Id) + { + throw new Exception("Такой статус уже существует"); + } + if (model.Id.HasValue) + { + _statusStorage.Update(model); + } + else + { + _statusStorage.Insert(model); + } + } + + public void Delete(StatusBindingModel model) + { + var element = _statusStorage.GetElement(new StatusBindingModel { Id = model.Id }); + if (element == null) + { + throw new Exception("Статус не найден"); + } + _statusStorage.Delete(model); + } + + public List Read(StatusBindingModel model) + { + if (model == null) + { + return _statusStorage.GetFullList(); + } + if (model.Id.HasValue) + { + return new List { _statusStorage.GetElement(model) }; + } + return _statusStorage.GetFilteredList(model); + } + } +} diff --git a/COP/ClientBusinessLogic/ClientBusinessLogic.csproj b/COP/ClientBusinessLogic/ClientBusinessLogic.csproj new file mode 100644 index 0000000..6e400c9 --- /dev/null +++ b/COP/ClientBusinessLogic/ClientBusinessLogic.csproj @@ -0,0 +1,14 @@ + + + + net6.0-windows + enable + true + enable + + + + + + + diff --git a/COP/ClientsContracts/BindingModels/ClientBindingModel.cs b/COP/ClientsContracts/BindingModels/ClientBindingModel.cs new file mode 100644 index 0000000..eb66b53 --- /dev/null +++ b/COP/ClientsContracts/BindingModels/ClientBindingModel.cs @@ -0,0 +1,15 @@ +namespace ClientsContracts.BindingModels +{ + public class ClientBindingModel + { + public int? Id { get; set; } + + public string Name { get; set; } + + public string Reviews { get; set; } + + public string Status { get; set; } + + public int? Amount { get; set; } + } +} diff --git a/COP/ClientsContracts/BindingModels/StatusBindingModel.cs b/COP/ClientsContracts/BindingModels/StatusBindingModel.cs new file mode 100644 index 0000000..16eb5b2 --- /dev/null +++ b/COP/ClientsContracts/BindingModels/StatusBindingModel.cs @@ -0,0 +1,9 @@ +namespace ClientsContracts.BindingModels +{ + public class StatusBindingModel + { + public int? Id { get; set; } + + public string Name { get; set; } + } +} diff --git a/COP/ClientsContracts/BusinessLogicContracts/IClientLogic.cs b/COP/ClientsContracts/BusinessLogicContracts/IClientLogic.cs new file mode 100644 index 0000000..550cf3c --- /dev/null +++ b/COP/ClientsContracts/BusinessLogicContracts/IClientLogic.cs @@ -0,0 +1,12 @@ +using ClientsContracts.BindingModels; +using ClientsContracts.ViewModels; + +namespace ClientsContracts.BusinessLogicContracts +{ + public interface IClientLogic + { + List Read(ClientBindingModel model); + void CreateOrUpdate(ClientBindingModel model); + void Delete(ClientBindingModel model); + } +} diff --git a/COP/ClientsContracts/BusinessLogicContracts/IStatusLogic.cs b/COP/ClientsContracts/BusinessLogicContracts/IStatusLogic.cs new file mode 100644 index 0000000..75972d8 --- /dev/null +++ b/COP/ClientsContracts/BusinessLogicContracts/IStatusLogic.cs @@ -0,0 +1,12 @@ +using ClientsContracts.BindingModels; +using ClientsContracts.ViewModels; + +namespace ClientsContracts.BusinessLogicContracts +{ + public interface IStatusLogic + { + List Read(StatusBindingModel model); + void CreateOrUpdate(StatusBindingModel model); + void Delete(StatusBindingModel model); + } +} diff --git a/COP/ClientsContracts/ClientsContracts.csproj b/COP/ClientsContracts/ClientsContracts.csproj new file mode 100644 index 0000000..060aa1c --- /dev/null +++ b/COP/ClientsContracts/ClientsContracts.csproj @@ -0,0 +1,10 @@ + + + + net6.0-windows + enable + true + enable + + + diff --git a/COP/ClientsContracts/StorageContracts/IClientStorage.cs b/COP/ClientsContracts/StorageContracts/IClientStorage.cs new file mode 100644 index 0000000..a9f7424 --- /dev/null +++ b/COP/ClientsContracts/StorageContracts/IClientStorage.cs @@ -0,0 +1,16 @@ +using ClientsContracts.BindingModels; +using ClientsContracts.ViewModels; + +namespace ClientsContracts.StorageContracts +{ + public interface IClientStorage + { + List GetFullList(); + List GetFilteredList(ClientBindingModel model); + ClientViewModel GetElement(ClientBindingModel model); + + void Insert(ClientBindingModel model); + void Update(ClientBindingModel model); + void Delete(ClientBindingModel model); + } +} diff --git a/COP/ClientsContracts/StorageContracts/IStatusStorage.cs b/COP/ClientsContracts/StorageContracts/IStatusStorage.cs new file mode 100644 index 0000000..dfcc601 --- /dev/null +++ b/COP/ClientsContracts/StorageContracts/IStatusStorage.cs @@ -0,0 +1,16 @@ +using ClientsContracts.BindingModels; +using ClientsContracts.ViewModels; + +namespace ClientsContracts.StorageContracts +{ + public interface IStatusStorage + { + List GetFullList(); + List GetFilteredList(StatusBindingModel model); + StatusViewModel GetElement(StatusBindingModel model); + + void Insert(StatusBindingModel model); + void Update(StatusBindingModel model); + void Delete(StatusBindingModel model); + } +} diff --git a/COP/ClientsContracts/ViewModels/ClientViewModel.cs b/COP/ClientsContracts/ViewModels/ClientViewModel.cs new file mode 100644 index 0000000..be11d1a --- /dev/null +++ b/COP/ClientsContracts/ViewModels/ClientViewModel.cs @@ -0,0 +1,19 @@ +using System.ComponentModel; + +namespace ClientsContracts.ViewModels +{ + public class ClientViewModel + { + public int? Id { get; set; } + + [DisplayName("ФИО")] + public string Name { get; set; } + + [DisplayName("Отзывы")] + public string Reviews { get; set; } + [DisplayName("Статус")] + public string Status { get; set; } + [DisplayName("Сумма покупок")] + public int? Amount { get; set; } + } +} diff --git a/COP/ClientsContracts/ViewModels/StatusViewModel.cs b/COP/ClientsContracts/ViewModels/StatusViewModel.cs new file mode 100644 index 0000000..4af3a50 --- /dev/null +++ b/COP/ClientsContracts/ViewModels/StatusViewModel.cs @@ -0,0 +1,9 @@ +namespace ClientsContracts.ViewModels +{ + public class StatusViewModel + { + public int? Id { get; set; } + + public string Name { get; set; } + } +} diff --git a/COP/ClientsDatabaseImplement/ClientsDatabase.cs b/COP/ClientsDatabaseImplement/ClientsDatabase.cs new file mode 100644 index 0000000..b2213eb --- /dev/null +++ b/COP/ClientsDatabaseImplement/ClientsDatabase.cs @@ -0,0 +1,19 @@ +using Microsoft.EntityFrameworkCore; +using ClientsDatabaseImplement.Models; + +namespace ClientsDatabaseImplement +{ + public class ClientsDatabase : DbContext + { + protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder) + { + if (optionsBuilder.IsConfigured == false) + { + optionsBuilder.UseNpgsql(@"Host=localhost;Port=5432;Database=ClientsDatabase;Username=postgres;Password=186qazwsx"); + } + base.OnConfiguring(optionsBuilder); + } + public virtual DbSet Clients { set; get; } + public virtual DbSet Statuses { set; get; } + } +} diff --git a/COP/ClientsDatabaseImplement/ClientsDatabaseImplement.csproj b/COP/ClientsDatabaseImplement/ClientsDatabaseImplement.csproj new file mode 100644 index 0000000..a7e761c --- /dev/null +++ b/COP/ClientsDatabaseImplement/ClientsDatabaseImplement.csproj @@ -0,0 +1,23 @@ + + + + net6.0-windows + enable + true + enable + + + + + + all + runtime; build; native; contentfiles; analyzers; buildtransitive + + + + + + + + + diff --git a/COP/ClientsDatabaseImplement/Implements/ClientStorage.cs b/COP/ClientsDatabaseImplement/Implements/ClientStorage.cs new file mode 100644 index 0000000..c407a90 --- /dev/null +++ b/COP/ClientsDatabaseImplement/Implements/ClientStorage.cs @@ -0,0 +1,120 @@ +using ClientsContracts.StorageContracts; +using ClientsContracts.BindingModels; +using ClientsContracts.ViewModels; +using ClientsDatabaseImplement.Models; + +namespace ClientsDatabaseImplement.Implements +{ + public class ClientStorage : IClientStorage + { + public void Delete(ClientBindingModel model) + { + var context = new ClientsDatabase(); + var client = context.Clients.FirstOrDefault(rec => rec.Id == model.Id); + if (client != null) + { + context.Clients.Remove(client); + context.SaveChanges(); + } + else + { + throw new Exception("Клиент не найден"); + } + } + + public ClientViewModel GetElement(ClientBindingModel model) + { + if (model == null) + { + return null; + } + using var context = new ClientsDatabase(); + var client = context.Clients + .ToList() + .FirstOrDefault(rec => rec.Id == model.Id); + return client != null ? CreateModel(client) : null; + } + + public List GetFilteredList(ClientBindingModel model) + { + var context = new ClientsDatabase(); + return context.Clients + .Where(client => client.Name.Contains(model.Name) && client.Status.Contains(model.Status)) + .ToList() + .Select(CreateModel) + .ToList(); + } + + public List GetFullList() + { + using (var context = new ClientsDatabase()) + { + return context.Clients + .ToList() + .Select(CreateModel) + .ToList(); + } + } + + public void Insert(ClientBindingModel model) + { + var context = new ClientsDatabase(); + var transaction = context.Database.BeginTransaction(); + try + { + context.Clients.Add(CreateModel(model, new Client())); + context.SaveChanges(); + transaction.Commit(); + } + catch + { + transaction.Rollback(); + throw; + } + } + + public void Update(ClientBindingModel model) + { + var context = new ClientsDatabase(); + var transaction = context.Database.BeginTransaction(); + try + { + var client = context.Clients.FirstOrDefault(rec => rec.Id == model.Id); + if (client == null) + { + throw new Exception("Клиент не найден"); + } + CreateModel(model, client); + context.SaveChanges(); + transaction.Commit(); + } + catch + { + transaction.Rollback(); + throw; + } + } + + private static Client CreateModel(ClientBindingModel model, Client client) + { + client.Amount = model.Amount; + client.Name = model.Name; + client.Status = model.Status; + client.Reviews = model.Reviews; + + return client; + } + + private ClientViewModel CreateModel(Client client) + { + return new ClientViewModel + { + Id = client.Id, + Amount = client.Amount, + Name = client.Name, + Status = client.Status, + Reviews = client.Reviews + }; + } + } +} diff --git a/COP/ClientsDatabaseImplement/Implements/StatusStorage.cs b/COP/ClientsDatabaseImplement/Implements/StatusStorage.cs new file mode 100644 index 0000000..07845ec --- /dev/null +++ b/COP/ClientsDatabaseImplement/Implements/StatusStorage.cs @@ -0,0 +1,115 @@ +using ClientsContracts.StorageContracts; +using ClientsContracts.BindingModels; +using ClientsContracts.ViewModels; +using ClientsDatabaseImplement.Models; + +namespace ClientsDatabaseImplement.Implements +{ + public class StatusStorage : IStatusStorage + { + public void Delete(StatusBindingModel model) + { + var context = new ClientsDatabase(); + var status = context.Statuses.FirstOrDefault(rec => rec.Id == model.Id); + if (status != null) + { + context.Statuses.Remove(status); + context.SaveChanges(); + } + else + { + throw new Exception("Статус не найден"); + } + } + + public StatusViewModel GetElement(StatusBindingModel model) + { + if (model == null) + { + return null; + } + using var context = new ClientsDatabase(); + + var status = context.Statuses + .ToList() + .FirstOrDefault(rec => rec.Id == model.Id || rec.Name == model.Name); + return status != null ? CreateModel(status) : null; + } + + + public List GetFilteredList(StatusBindingModel model) + { + if (model == null) + { + return null; + } + using var context = new ClientsDatabase(); + return context.Statuses + .Where(rec => rec.Name.Contains(model.Name)) + .Select(CreateModel) + .ToList(); + } + + public List GetFullList() + { + using var context = new ClientsDatabase(); + return context.Statuses + .Select(CreateModel) + .ToList(); + } + + public void Insert(StatusBindingModel model) + { + var context = new ClientsDatabase(); + var transaction = context.Database.BeginTransaction(); + try + { + context.Statuses.Add(CreateModel(model, new Status())); + context.SaveChanges(); + transaction.Commit(); + } + catch + { + transaction.Rollback(); + throw; + } + } + + public void Update(StatusBindingModel model) + { + var context = new ClientsDatabase(); + var transaction = context.Database.BeginTransaction(); + try + { + var status = context.Statuses.FirstOrDefault(rec => rec.Id == model.Id); + if (status == null) + { + throw new Exception("Статус не найден"); + } + CreateModel(model, status); + context.SaveChanges(); + transaction.Commit(); + } + catch + { + transaction.Rollback(); + throw; + } + } + + private static Status CreateModel(StatusBindingModel model, Status status) + { + status.Name = model.Name; + return status; + } + + private static StatusViewModel CreateModel(Status status) + { + return new StatusViewModel + { + Id = status.Id, + Name = status.Name + }; + } + } +} diff --git a/COP/ClientsDatabaseImplement/Migrations/20231024184241_InitMigration.Designer.cs b/COP/ClientsDatabaseImplement/Migrations/20231024184241_InitMigration.Designer.cs new file mode 100644 index 0000000..85e2c35 --- /dev/null +++ b/COP/ClientsDatabaseImplement/Migrations/20231024184241_InitMigration.Designer.cs @@ -0,0 +1,75 @@ +// +using System; +using ClientsDatabaseImplement; +using Microsoft.EntityFrameworkCore; +using Microsoft.EntityFrameworkCore.Infrastructure; +using Microsoft.EntityFrameworkCore.Migrations; +using Microsoft.EntityFrameworkCore.Storage.ValueConversion; +using Npgsql.EntityFrameworkCore.PostgreSQL.Metadata; + +#nullable disable + +namespace ClientsDatabaseImplement.Migrations +{ + [DbContext(typeof(ClientsDatabase))] + [Migration("20231024184241_InitMigration")] + partial class InitMigration + { + /// + protected override void BuildTargetModel(ModelBuilder modelBuilder) + { +#pragma warning disable 612, 618 + modelBuilder + .HasAnnotation("ProductVersion", "7.0.11") + .HasAnnotation("Relational:MaxIdentifierLength", 63); + + NpgsqlModelBuilderExtensions.UseIdentityByDefaultColumns(modelBuilder); + + modelBuilder.Entity("ClientsDatabaseImplement.Models.Client", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("integer"); + + NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property("Id")); + + b.Property("Amount") + .HasColumnType("integer"); + + b.Property("Name") + .IsRequired() + .HasColumnType("text"); + + b.Property("Reviews") + .IsRequired() + .HasColumnType("text"); + + b.Property("Status") + .IsRequired() + .HasColumnType("text"); + + b.HasKey("Id"); + + b.ToTable("Clients"); + }); + + modelBuilder.Entity("ClientsDatabaseImplement.Models.Status", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("integer"); + + NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property("Id")); + + b.Property("Name") + .IsRequired() + .HasColumnType("text"); + + b.HasKey("Id"); + + b.ToTable("Statuses"); + }); +#pragma warning restore 612, 618 + } + } +} diff --git a/COP/ClientsDatabaseImplement/Migrations/20231024184241_InitMigration.cs b/COP/ClientsDatabaseImplement/Migrations/20231024184241_InitMigration.cs new file mode 100644 index 0000000..4487b6b --- /dev/null +++ b/COP/ClientsDatabaseImplement/Migrations/20231024184241_InitMigration.cs @@ -0,0 +1,54 @@ +using Microsoft.EntityFrameworkCore.Migrations; +using Npgsql.EntityFrameworkCore.PostgreSQL.Metadata; + +#nullable disable + +namespace ClientsDatabaseImplement.Migrations +{ + /// + public partial class InitMigration : Migration + { + /// + protected override void Up(MigrationBuilder migrationBuilder) + { + migrationBuilder.CreateTable( + name: "Clients", + columns: table => new + { + Id = table.Column(type: "integer", nullable: false) + .Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn), + Name = table.Column(type: "text", nullable: false), + Reviews = table.Column(type: "text", nullable: false), + Status = table.Column(type: "text", nullable: false), + Amount = table.Column(type: "integer", nullable: true) + }, + constraints: table => + { + table.PrimaryKey("PK_Clients", x => x.Id); + }); + + migrationBuilder.CreateTable( + name: "Statuses", + columns: table => new + { + Id = table.Column(type: "integer", nullable: false) + .Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn), + Name = table.Column(type: "text", nullable: false) + }, + constraints: table => + { + table.PrimaryKey("PK_Statuses", x => x.Id); + }); + } + + /// + protected override void Down(MigrationBuilder migrationBuilder) + { + migrationBuilder.DropTable( + name: "Clients"); + + migrationBuilder.DropTable( + name: "Statuses"); + } + } +} diff --git a/COP/ClientsDatabaseImplement/Migrations/ClientsDatabaseModelSnapshot.cs b/COP/ClientsDatabaseImplement/Migrations/ClientsDatabaseModelSnapshot.cs new file mode 100644 index 0000000..9eb1f9c --- /dev/null +++ b/COP/ClientsDatabaseImplement/Migrations/ClientsDatabaseModelSnapshot.cs @@ -0,0 +1,72 @@ +// +using System; +using ClientsDatabaseImplement; +using Microsoft.EntityFrameworkCore; +using Microsoft.EntityFrameworkCore.Infrastructure; +using Microsoft.EntityFrameworkCore.Storage.ValueConversion; +using Npgsql.EntityFrameworkCore.PostgreSQL.Metadata; + +#nullable disable + +namespace ClientsDatabaseImplement.Migrations +{ + [DbContext(typeof(ClientsDatabase))] + partial class ClientsDatabaseModelSnapshot : ModelSnapshot + { + protected override void BuildModel(ModelBuilder modelBuilder) + { +#pragma warning disable 612, 618 + modelBuilder + .HasAnnotation("ProductVersion", "7.0.11") + .HasAnnotation("Relational:MaxIdentifierLength", 63); + + NpgsqlModelBuilderExtensions.UseIdentityByDefaultColumns(modelBuilder); + + modelBuilder.Entity("ClientsDatabaseImplement.Models.Client", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("integer"); + + NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property("Id")); + + b.Property("Amount") + .HasColumnType("integer"); + + b.Property("Name") + .IsRequired() + .HasColumnType("text"); + + b.Property("Reviews") + .IsRequired() + .HasColumnType("text"); + + b.Property("Status") + .IsRequired() + .HasColumnType("text"); + + b.HasKey("Id"); + + b.ToTable("Clients"); + }); + + modelBuilder.Entity("ClientsDatabaseImplement.Models.Status", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("integer"); + + NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property("Id")); + + b.Property("Name") + .IsRequired() + .HasColumnType("text"); + + b.HasKey("Id"); + + b.ToTable("Statuses"); + }); +#pragma warning restore 612, 618 + } + } +} diff --git a/COP/ClientsDatabaseImplement/Models/Client.cs b/COP/ClientsDatabaseImplement/Models/Client.cs new file mode 100644 index 0000000..b017fa2 --- /dev/null +++ b/COP/ClientsDatabaseImplement/Models/Client.cs @@ -0,0 +1,19 @@ +using System.ComponentModel.DataAnnotations; + +namespace ClientsDatabaseImplement.Models +{ + public class Client + { + public int Id { get; set; } + + [Required] + public string Name { get; set; } + + [Required] + public string Reviews { get; set; } + [Required] + public string Status { get; set; } + + public int? Amount { get; set; } + } +} diff --git a/COP/ClientsDatabaseImplement/Models/Status.cs b/COP/ClientsDatabaseImplement/Models/Status.cs new file mode 100644 index 0000000..09733a2 --- /dev/null +++ b/COP/ClientsDatabaseImplement/Models/Status.cs @@ -0,0 +1,12 @@ +using System.ComponentModel.DataAnnotations; + +namespace ClientsDatabaseImplement.Models +{ + public class Status + { + public int Id { get; set; } + + [Required] + public string Name { get; set; } + } +} diff --git a/COP/VisualCompLib/VisualCompLib.csproj b/COP/VisualCompLib/VisualCompLib.csproj index 4be1e4c..96dee46 100644 --- a/COP/VisualCompLib/VisualCompLib.csproj +++ b/COP/VisualCompLib/VisualCompLib.csproj @@ -5,6 +5,7 @@ enable true enable + True diff --git a/COP/WinForms/WinForms.csproj b/COP/WinForms/WinForms.csproj index 234fae2..950ca23 100644 --- a/COP/WinForms/WinForms.csproj +++ b/COP/WinForms/WinForms.csproj @@ -9,11 +9,19 @@ - + + + + all + runtime; build; native; contentfiles; analyzers; buildtransitive + + + + - + \ No newline at end of file