From 596f77bcb965bbacd6cb51ceede944c9f5f999ed Mon Sep 17 00:00:00 2001 From: dex_moth Date: Tue, 14 May 2024 19:05:59 +0400 Subject: [PATCH 1/3] =?UTF-8?q?=D0=B3=D0=BE=D1=82=D0=BE=D0=B2=D0=BE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- FishFactory/Forms/FormMain.cs | 7 +- .../BusinessLogic/OrderLogic.cs | 12 +- .../BusinessLogicsContracts/IOrderLogic.cs | 15 -- .../ViewModels/OrderViewModel.cs | 7 +- .../Models/IImplementerModel.cs | 2 +- .../Implements/ImplementerStorage.cs | 3 +- .../Implements/OrderStorage.cs | 12 +- .../20240514140738_implementer.Designer.cs | 252 ++++++++++++++++++ .../Migrations/20240514140738_implementer.cs | 22 ++ .../20240514143630_implementer2.Designer.cs | 252 ++++++++++++++++++ .../Migrations/20240514143630_implementer2.cs | 22 ++ .../Models/Implementer.cs | 6 +- FishFactoryDatabaseImplement/Models/Order.cs | 7 +- 13 files changed, 573 insertions(+), 46 deletions(-) create mode 100644 FishFactoryDatabaseImplement/Migrations/20240514140738_implementer.Designer.cs create mode 100644 FishFactoryDatabaseImplement/Migrations/20240514140738_implementer.cs create mode 100644 FishFactoryDatabaseImplement/Migrations/20240514143630_implementer2.Designer.cs create mode 100644 FishFactoryDatabaseImplement/Migrations/20240514143630_implementer2.cs diff --git a/FishFactory/Forms/FormMain.cs b/FishFactory/Forms/FormMain.cs index a41d81f..50aa7f6 100644 --- a/FishFactory/Forms/FormMain.cs +++ b/FishFactory/Forms/FormMain.cs @@ -9,15 +9,16 @@ namespace FishFactory.Forms private readonly ILogger _logger; private readonly IOrderLogic _orderLogic; private readonly IReportLogic _reportLogic; - private IWorkProcess _workProcess; + private readonly IWorkProcess _workProcess; - public FormMain(ILogger logger, IOrderLogic orderLogic, IReportLogic reportLogic) + public FormMain(ILogger logger, IOrderLogic orderLogic, IReportLogic reportLogic, IWorkProcess workProcess) { InitializeComponent(); _logger = logger; _orderLogic = orderLogic; _reportLogic = reportLogic; - } + _workProcess = workProcess; + } private void FormMain_Load(object sender, EventArgs e) { LoadData(); diff --git a/FishFactoryBusinessLogic/BusinessLogic/OrderLogic.cs b/FishFactoryBusinessLogic/BusinessLogic/OrderLogic.cs index 11a0cae..52e6f46 100644 --- a/FishFactoryBusinessLogic/BusinessLogic/OrderLogic.cs +++ b/FishFactoryBusinessLogic/BusinessLogic/OrderLogic.cs @@ -13,7 +13,7 @@ namespace FishFactoryBusinessLogic.BusinessLogic private readonly ILogger _logger; private readonly IOrderStorage _orderStorage; - public OrderLogic(ILogger logger, IOrderStorage orderStorage) + public OrderLogic(ILogger logger, IOrderStorage orderStorage) { _logger = logger; _orderStorage = orderStorage; @@ -69,8 +69,8 @@ namespace FishFactoryBusinessLogic.BusinessLogic public bool TakeOrderInWork(OrderBindingModel model) { - return ToNextStatus(model, OrderStatus.Выполняется); - } + return ToNextStatus(model, OrderStatus.Выполняется); + } public bool FinishOrder(OrderBindingModel model) { @@ -101,10 +101,6 @@ namespace FishFactoryBusinessLogic.BusinessLogic model.Status = element.Status; model.Count = element.Count; model.Sum = element.Sum; - if (!model.ImplementerId.HasValue) - { - model.ImplementerId = element.ImplementerId; - } if (model.Status != orderStatus - 1) { @@ -113,7 +109,7 @@ namespace FishFactoryBusinessLogic.BusinessLogic } model.Status = orderStatus; - if (model.Status == OrderStatus.Выдан) + if (model.Status == OrderStatus.Готов) { model.DateImplement = DateTime.Now; } diff --git a/FishFactoryContracts/BusinessLogicsContracts/IOrderLogic.cs b/FishFactoryContracts/BusinessLogicsContracts/IOrderLogic.cs index c25ffb3..8391391 100644 --- a/FishFactoryContracts/BusinessLogicsContracts/IOrderLogic.cs +++ b/FishFactoryContracts/BusinessLogicsContracts/IOrderLogic.cs @@ -1,11 +1,6 @@ using FishFactoryContracts.BindingModels; using FishFactoryContracts.SearchModels; using FishFactoryContracts.ViewModels; -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; namespace FishFactoryContracts.BusinessLogicsContracts { @@ -15,17 +10,7 @@ namespace FishFactoryContracts.BusinessLogicsContracts OrderViewModel? ReadElement(OrderSearchModel model); bool CreateOrder(OrderBindingModel model); bool TakeOrderInWork(OrderBindingModel model); - /// - /// Готов - /// - /// - /// bool FinishOrder(OrderBindingModel model); - /// - /// Доставлен - /// - /// - /// bool DeliveryOrder(OrderBindingModel model); } } diff --git a/FishFactoryContracts/ViewModels/OrderViewModel.cs b/FishFactoryContracts/ViewModels/OrderViewModel.cs index cfe31f5..3ae73d4 100644 --- a/FishFactoryContracts/ViewModels/OrderViewModel.cs +++ b/FishFactoryContracts/ViewModels/OrderViewModel.cs @@ -1,10 +1,5 @@ using FishFactoryDataModel.Enums; -using System; -using System.Collections.Generic; using System.ComponentModel; -using System.Linq; -using System.Text; -using System.Threading.Tasks; namespace FishFactoryContracts.ViewModels { @@ -17,7 +12,7 @@ namespace FishFactoryContracts.ViewModels public string ClientFIO { get; set; } = string.Empty; public int? ImplementerId { get; set; } [DisplayName("Исполнитель")] - public string? ImplementerFIO { get; set; } = string.Empty; + public string? ImplementerFIO { get; set; } = null; public int CannedId { get; set; } [DisplayName("Изделие")] public string CannedName { get; set; } = string.Empty; diff --git a/FishFactoryDataModels/Models/IImplementerModel.cs b/FishFactoryDataModels/Models/IImplementerModel.cs index 396886f..540ede8 100644 --- a/FishFactoryDataModels/Models/IImplementerModel.cs +++ b/FishFactoryDataModels/Models/IImplementerModel.cs @@ -1,6 +1,6 @@ namespace FishFactoryDataModel.Models { - public interface IImplementerModel + public interface IImplementerModel : IId { string ImplementerFIO { get; } string Password { get; } diff --git a/FishFactoryDatabaseImplement/Implements/ImplementerStorage.cs b/FishFactoryDatabaseImplement/Implements/ImplementerStorage.cs index 3c8d2af..47eed17 100644 --- a/FishFactoryDatabaseImplement/Implements/ImplementerStorage.cs +++ b/FishFactoryDatabaseImplement/Implements/ImplementerStorage.cs @@ -26,7 +26,8 @@ namespace FishFactoryDatabaseImplement.Implements public ImplementerViewModel? GetElement(ImplementerSearchModel model) { - if (string.IsNullOrEmpty(model.ImplementerFIO) && !model.Id.HasValue) + if (string.IsNullOrEmpty(model.ImplementerFIO) && string.IsNullOrEmpty(model.Password) && + !model.Id.HasValue) { return null; } diff --git a/FishFactoryDatabaseImplement/Implements/OrderStorage.cs b/FishFactoryDatabaseImplement/Implements/OrderStorage.cs index 40ca72a..aa04722 100644 --- a/FishFactoryDatabaseImplement/Implements/OrderStorage.cs +++ b/FishFactoryDatabaseImplement/Implements/OrderStorage.cs @@ -22,7 +22,7 @@ namespace FishFactoryDatabaseImplement.Implements public List GetFilteredList(OrderSearchModel model) { using var context = new FishFactoryDatabase(); - return context.Orders + return context.Orders .Include(x => x.Canned) .Include(x => x.Client) .Include(x => x.Implementer) @@ -38,11 +38,11 @@ namespace FishFactoryDatabaseImplement.Implements } public OrderViewModel? GetElement(OrderSearchModel model) { - if (!model.Id.HasValue) - { - return new(); - } - using var context = new FishFactoryDatabase(); + if (!model.Id.HasValue && (!model.ImplementerId.HasValue || !model.Status.HasValue)) + { + return null; + } + using var context = new FishFactoryDatabase(); return context.Orders .Include(x => x.Canned) .Include(x => x.Client) diff --git a/FishFactoryDatabaseImplement/Migrations/20240514140738_implementer.Designer.cs b/FishFactoryDatabaseImplement/Migrations/20240514140738_implementer.Designer.cs new file mode 100644 index 0000000..6915550 --- /dev/null +++ b/FishFactoryDatabaseImplement/Migrations/20240514140738_implementer.Designer.cs @@ -0,0 +1,252 @@ +// +using System; +using FishFactoryDatabaseImplement; +using Microsoft.EntityFrameworkCore; +using Microsoft.EntityFrameworkCore.Infrastructure; +using Microsoft.EntityFrameworkCore.Migrations; +using Microsoft.EntityFrameworkCore.Storage.ValueConversion; +using Npgsql.EntityFrameworkCore.PostgreSQL.Metadata; + +#nullable disable + +namespace FishFactoryDatabaseImplement.Migrations +{ + [DbContext(typeof(FishFactoryDatabase))] + [Migration("20240514140738_implementer")] + partial class implementer + { + /// + protected override void BuildTargetModel(ModelBuilder modelBuilder) + { +#pragma warning disable 612, 618 + modelBuilder + .HasAnnotation("ProductVersion", "7.0.16") + .HasAnnotation("Relational:MaxIdentifierLength", 63); + + NpgsqlModelBuilderExtensions.UseIdentityByDefaultColumns(modelBuilder); + + modelBuilder.Entity("FishFactoryDatabaseImplement.Models.Canned", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("integer"); + + NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property("Id")); + + b.Property("CannedName") + .IsRequired() + .HasColumnType("text"); + + b.Property("Price") + .HasColumnType("double precision"); + + b.HasKey("Id"); + + b.ToTable("Canneds"); + }); + + modelBuilder.Entity("FishFactoryDatabaseImplement.Models.CannedComponent", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("integer"); + + NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property("Id")); + + b.Property("CannedId") + .HasColumnType("integer"); + + b.Property("ComponentId") + .HasColumnType("integer"); + + b.Property("Count") + .HasColumnType("integer"); + + b.HasKey("Id"); + + b.HasIndex("CannedId"); + + b.HasIndex("ComponentId"); + + b.ToTable("CannedComponents"); + }); + + modelBuilder.Entity("FishFactoryDatabaseImplement.Models.Client", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("integer"); + + NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property("Id")); + + b.Property("ClientFIO") + .IsRequired() + .HasColumnType("text"); + + b.Property("Email") + .IsRequired() + .HasColumnType("text"); + + b.Property("Password") + .IsRequired() + .HasColumnType("text"); + + b.HasKey("Id"); + + b.ToTable("Clients"); + }); + + modelBuilder.Entity("FishFactoryDatabaseImplement.Models.Component", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("integer"); + + NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property("Id")); + + b.Property("ComponentName") + .IsRequired() + .HasColumnType("text"); + + b.Property("Cost") + .HasColumnType("double precision"); + + b.HasKey("Id"); + + b.ToTable("Components"); + }); + + modelBuilder.Entity("FishFactoryDatabaseImplement.Models.Implementer", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("integer"); + + NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property("Id")); + + b.Property("ImplementerFIO") + .IsRequired() + .HasColumnType("text"); + + b.Property("Password") + .IsRequired() + .HasColumnType("text"); + + b.Property("Qualification") + .HasColumnType("integer"); + + b.Property("WorkExperience") + .HasColumnType("integer"); + + b.HasKey("Id"); + + b.ToTable("Implementers"); + }); + + modelBuilder.Entity("FishFactoryDatabaseImplement.Models.Order", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("integer"); + + NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property("Id")); + + b.Property("CannedId") + .HasColumnType("integer"); + + b.Property("ClientId") + .HasColumnType("integer"); + + b.Property("Count") + .HasColumnType("integer"); + + b.Property("DateCreate") + .HasColumnType("timestamp without time zone"); + + b.Property("DateImplement") + .HasColumnType("timestamp without time zone"); + + b.Property("ImplementerId") + .HasColumnType("integer"); + + b.Property("Status") + .HasColumnType("integer"); + + b.Property("Sum") + .HasColumnType("double precision"); + + b.HasKey("Id"); + + b.HasIndex("CannedId"); + + b.HasIndex("ClientId"); + + b.HasIndex("ImplementerId"); + + b.ToTable("Orders"); + }); + + modelBuilder.Entity("FishFactoryDatabaseImplement.Models.CannedComponent", b => + { + b.HasOne("FishFactoryDatabaseImplement.Models.Canned", "Canned") + .WithMany("Components") + .HasForeignKey("CannedId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.HasOne("FishFactoryDatabaseImplement.Models.Component", "Component") + .WithMany("CannedComponents") + .HasForeignKey("ComponentId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.Navigation("Canned"); + + b.Navigation("Component"); + }); + + modelBuilder.Entity("FishFactoryDatabaseImplement.Models.Order", b => + { + b.HasOne("FishFactoryDatabaseImplement.Models.Canned", "Canned") + .WithMany("Orders") + .HasForeignKey("CannedId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.HasOne("FishFactoryDatabaseImplement.Models.Client", "Client") + .WithMany() + .HasForeignKey("ClientId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.HasOne("FishFactoryDatabaseImplement.Models.Implementer", "Implementer") + .WithMany("Order") + .HasForeignKey("ImplementerId"); + + b.Navigation("Canned"); + + b.Navigation("Client"); + + b.Navigation("Implementer"); + }); + + modelBuilder.Entity("FishFactoryDatabaseImplement.Models.Canned", b => + { + b.Navigation("Components"); + + b.Navigation("Orders"); + }); + + modelBuilder.Entity("FishFactoryDatabaseImplement.Models.Component", b => + { + b.Navigation("CannedComponents"); + }); + + modelBuilder.Entity("FishFactoryDatabaseImplement.Models.Implementer", b => + { + b.Navigation("Order"); + }); +#pragma warning restore 612, 618 + } + } +} diff --git a/FishFactoryDatabaseImplement/Migrations/20240514140738_implementer.cs b/FishFactoryDatabaseImplement/Migrations/20240514140738_implementer.cs new file mode 100644 index 0000000..b171c71 --- /dev/null +++ b/FishFactoryDatabaseImplement/Migrations/20240514140738_implementer.cs @@ -0,0 +1,22 @@ +using Microsoft.EntityFrameworkCore.Migrations; + +#nullable disable + +namespace FishFactoryDatabaseImplement.Migrations +{ + /// + public partial class implementer : Migration + { + /// + protected override void Up(MigrationBuilder migrationBuilder) + { + + } + + /// + protected override void Down(MigrationBuilder migrationBuilder) + { + + } + } +} diff --git a/FishFactoryDatabaseImplement/Migrations/20240514143630_implementer2.Designer.cs b/FishFactoryDatabaseImplement/Migrations/20240514143630_implementer2.Designer.cs new file mode 100644 index 0000000..ac347b6 --- /dev/null +++ b/FishFactoryDatabaseImplement/Migrations/20240514143630_implementer2.Designer.cs @@ -0,0 +1,252 @@ +// +using System; +using FishFactoryDatabaseImplement; +using Microsoft.EntityFrameworkCore; +using Microsoft.EntityFrameworkCore.Infrastructure; +using Microsoft.EntityFrameworkCore.Migrations; +using Microsoft.EntityFrameworkCore.Storage.ValueConversion; +using Npgsql.EntityFrameworkCore.PostgreSQL.Metadata; + +#nullable disable + +namespace FishFactoryDatabaseImplement.Migrations +{ + [DbContext(typeof(FishFactoryDatabase))] + [Migration("20240514143630_implementer2")] + partial class implementer2 + { + /// + protected override void BuildTargetModel(ModelBuilder modelBuilder) + { +#pragma warning disable 612, 618 + modelBuilder + .HasAnnotation("ProductVersion", "7.0.16") + .HasAnnotation("Relational:MaxIdentifierLength", 63); + + NpgsqlModelBuilderExtensions.UseIdentityByDefaultColumns(modelBuilder); + + modelBuilder.Entity("FishFactoryDatabaseImplement.Models.Canned", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("integer"); + + NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property("Id")); + + b.Property("CannedName") + .IsRequired() + .HasColumnType("text"); + + b.Property("Price") + .HasColumnType("double precision"); + + b.HasKey("Id"); + + b.ToTable("Canneds"); + }); + + modelBuilder.Entity("FishFactoryDatabaseImplement.Models.CannedComponent", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("integer"); + + NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property("Id")); + + b.Property("CannedId") + .HasColumnType("integer"); + + b.Property("ComponentId") + .HasColumnType("integer"); + + b.Property("Count") + .HasColumnType("integer"); + + b.HasKey("Id"); + + b.HasIndex("CannedId"); + + b.HasIndex("ComponentId"); + + b.ToTable("CannedComponents"); + }); + + modelBuilder.Entity("FishFactoryDatabaseImplement.Models.Client", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("integer"); + + NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property("Id")); + + b.Property("ClientFIO") + .IsRequired() + .HasColumnType("text"); + + b.Property("Email") + .IsRequired() + .HasColumnType("text"); + + b.Property("Password") + .IsRequired() + .HasColumnType("text"); + + b.HasKey("Id"); + + b.ToTable("Clients"); + }); + + modelBuilder.Entity("FishFactoryDatabaseImplement.Models.Component", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("integer"); + + NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property("Id")); + + b.Property("ComponentName") + .IsRequired() + .HasColumnType("text"); + + b.Property("Cost") + .HasColumnType("double precision"); + + b.HasKey("Id"); + + b.ToTable("Components"); + }); + + modelBuilder.Entity("FishFactoryDatabaseImplement.Models.Implementer", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("integer"); + + NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property("Id")); + + b.Property("ImplementerFIO") + .IsRequired() + .HasColumnType("text"); + + b.Property("Password") + .IsRequired() + .HasColumnType("text"); + + b.Property("Qualification") + .HasColumnType("integer"); + + b.Property("WorkExperience") + .HasColumnType("integer"); + + b.HasKey("Id"); + + b.ToTable("Implementers"); + }); + + modelBuilder.Entity("FishFactoryDatabaseImplement.Models.Order", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("integer"); + + NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property("Id")); + + b.Property("CannedId") + .HasColumnType("integer"); + + b.Property("ClientId") + .HasColumnType("integer"); + + b.Property("Count") + .HasColumnType("integer"); + + b.Property("DateCreate") + .HasColumnType("timestamp without time zone"); + + b.Property("DateImplement") + .HasColumnType("timestamp without time zone"); + + b.Property("ImplementerId") + .HasColumnType("integer"); + + b.Property("Status") + .HasColumnType("integer"); + + b.Property("Sum") + .HasColumnType("double precision"); + + b.HasKey("Id"); + + b.HasIndex("CannedId"); + + b.HasIndex("ClientId"); + + b.HasIndex("ImplementerId"); + + b.ToTable("Orders"); + }); + + modelBuilder.Entity("FishFactoryDatabaseImplement.Models.CannedComponent", b => + { + b.HasOne("FishFactoryDatabaseImplement.Models.Canned", "Canned") + .WithMany("Components") + .HasForeignKey("CannedId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.HasOne("FishFactoryDatabaseImplement.Models.Component", "Component") + .WithMany("CannedComponents") + .HasForeignKey("ComponentId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.Navigation("Canned"); + + b.Navigation("Component"); + }); + + modelBuilder.Entity("FishFactoryDatabaseImplement.Models.Order", b => + { + b.HasOne("FishFactoryDatabaseImplement.Models.Canned", "Canned") + .WithMany("Orders") + .HasForeignKey("CannedId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.HasOne("FishFactoryDatabaseImplement.Models.Client", "Client") + .WithMany() + .HasForeignKey("ClientId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.HasOne("FishFactoryDatabaseImplement.Models.Implementer", "Implementer") + .WithMany("Order") + .HasForeignKey("ImplementerId"); + + b.Navigation("Canned"); + + b.Navigation("Client"); + + b.Navigation("Implementer"); + }); + + modelBuilder.Entity("FishFactoryDatabaseImplement.Models.Canned", b => + { + b.Navigation("Components"); + + b.Navigation("Orders"); + }); + + modelBuilder.Entity("FishFactoryDatabaseImplement.Models.Component", b => + { + b.Navigation("CannedComponents"); + }); + + modelBuilder.Entity("FishFactoryDatabaseImplement.Models.Implementer", b => + { + b.Navigation("Order"); + }); +#pragma warning restore 612, 618 + } + } +} diff --git a/FishFactoryDatabaseImplement/Migrations/20240514143630_implementer2.cs b/FishFactoryDatabaseImplement/Migrations/20240514143630_implementer2.cs new file mode 100644 index 0000000..7105be2 --- /dev/null +++ b/FishFactoryDatabaseImplement/Migrations/20240514143630_implementer2.cs @@ -0,0 +1,22 @@ +using Microsoft.EntityFrameworkCore.Migrations; + +#nullable disable + +namespace FishFactoryDatabaseImplement.Migrations +{ + /// + public partial class implementer2 : Migration + { + /// + protected override void Up(MigrationBuilder migrationBuilder) + { + + } + + /// + protected override void Down(MigrationBuilder migrationBuilder) + { + + } + } +} diff --git a/FishFactoryDatabaseImplement/Models/Implementer.cs b/FishFactoryDatabaseImplement/Models/Implementer.cs index efd595b..f68ae31 100644 --- a/FishFactoryDatabaseImplement/Models/Implementer.cs +++ b/FishFactoryDatabaseImplement/Models/Implementer.cs @@ -13,10 +13,10 @@ namespace FishFactoryDatabaseImplement.Models public string Password { get; private set; } = string.Empty; - public int WorkExperience { get; private set; } + public int WorkExperience { get; private set; } = 0; - public int Qualification { get; private set; } - [ForeignKey("ImplementerId")] + public int Qualification { get; private set; } = 0; + [ForeignKey("ImplementerId")] public virtual List Order { get; set; } = new(); public static Implementer? Create(ImplementerBindingModel? model) diff --git a/FishFactoryDatabaseImplement/Models/Order.cs b/FishFactoryDatabaseImplement/Models/Order.cs index 6dd1c23..a079ca2 100644 --- a/FishFactoryDatabaseImplement/Models/Order.cs +++ b/FishFactoryDatabaseImplement/Models/Order.cs @@ -39,8 +39,9 @@ namespace FishFactoryDatabaseImplement.Models ClientId = model.ClientId, Client = context.Clients.First(x => x.Id == model.ClientId), ImplementerId = model.ImplementerId, - Implementer = model.ImplementerId.HasValue ? context.Implementers.First(x => x.Id == model.ImplementerId) : null, - Count = model.Count, + Implementer = model.ImplementerId == null ? null : context.Implementers.First(i => i.Id == model.ImplementerId), + + Count = model.Count, Sum = model.Sum, Status = model.Status, DateCreate = model.DateCreate, @@ -73,7 +74,7 @@ namespace FishFactoryDatabaseImplement.Models ClientId = ClientId, ClientFIO = Client.ClientFIO, ImplementerId = ImplementerId, - ImplementerFIO = Implementer?.ImplementerFIO, + ImplementerFIO = Implementer == null ? string.Empty : Implementer.ImplementerFIO, Count = Count, Sum = Sum, Status = Status, From 8d048df15b45a018697fac70fd2bb0c62ff5915d Mon Sep 17 00:00:00 2001 From: dex_moth Date: Wed, 19 Jun 2024 14:38:52 +0400 Subject: [PATCH 2/3] =?UTF-8?q?=D0=BE=D1=82=D0=BE=D0=B1=D1=80=D0=B0=D0=B6?= =?UTF-8?q?=D0=B5=D0=BD=D0=B8=D0=B5=20=D0=BA=D0=BE=D0=BB=D0=BE=D0=BD=D0=BE?= =?UTF-8?q?=D0=BA?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../BusinessLogic/OrderLogic.cs | 10 ++++++++-- .../SearchModels/ImplementerSearchModel.cs | 6 +++--- .../ViewModels/ImplementerViewModel.cs | 4 ++-- .../Models/Implementer.cs | 17 +++++++++-------- 4 files changed, 22 insertions(+), 15 deletions(-) diff --git a/FishFactoryBusinessLogic/BusinessLogic/OrderLogic.cs b/FishFactoryBusinessLogic/BusinessLogic/OrderLogic.cs index 52e6f46..fb61b4e 100644 --- a/FishFactoryBusinessLogic/BusinessLogic/OrderLogic.cs +++ b/FishFactoryBusinessLogic/BusinessLogic/OrderLogic.cs @@ -94,15 +94,21 @@ namespace FishFactoryBusinessLogic.BusinessLogic throw new ArgumentNullException(nameof(element)); } - model.CannedId = element.CannedId; + if (element.ImplementerId != null && model.ImplementerId != null && model.ImplementerId != element.ImplementerId) + { + throw new InvalidOperationException(nameof(model.ImplementerId)); + } + + model.CannedId = element.CannedId; model.ClientId = element.ClientId; model.DateCreate = element.DateCreate; model.DateImplement = element.DateImplement; model.Status = element.Status; model.Count = element.Count; model.Sum = element.Sum; + model.ImplementerId = element.ImplementerId.HasValue ? element.ImplementerId : model.ImplementerId; - if (model.Status != orderStatus - 1) + if (model.Status != orderStatus - 1) { _logger.LogWarning("Status update to " + orderStatus + " operation failed"); return false; diff --git a/FishFactoryContracts/SearchModels/ImplementerSearchModel.cs b/FishFactoryContracts/SearchModels/ImplementerSearchModel.cs index be9c97f..2420ab5 100644 --- a/FishFactoryContracts/SearchModels/ImplementerSearchModel.cs +++ b/FishFactoryContracts/SearchModels/ImplementerSearchModel.cs @@ -4,7 +4,7 @@ namespace FishFactoryContracts.SearchModels public class ImplementerSearchModel { public int? Id { get; set; } - public string? ImplementerFIO { get; set; } - public string? Password { get; set; } - } + public string? ImplementerFIO { get; set; } = string.Empty; + public string? Password { get; set; } = string.Empty; + } } diff --git a/FishFactoryContracts/ViewModels/ImplementerViewModel.cs b/FishFactoryContracts/ViewModels/ImplementerViewModel.cs index ceaae40..6c8008a 100644 --- a/FishFactoryContracts/ViewModels/ImplementerViewModel.cs +++ b/FishFactoryContracts/ViewModels/ImplementerViewModel.cs @@ -1,9 +1,9 @@ - +using FishFactoryDataModel.Models; using System.ComponentModel; namespace FishFactoryContracts.ViewModels { - public class ImplementerViewModel + public class ImplementerViewModel : IImplementerModel { public int Id { get; set; } [DisplayName("ФИО исполнителя")] diff --git a/FishFactoryDatabaseImplement/Models/Implementer.cs b/FishFactoryDatabaseImplement/Models/Implementer.cs index f68ae31..dd3193e 100644 --- a/FishFactoryDatabaseImplement/Models/Implementer.cs +++ b/FishFactoryDatabaseImplement/Models/Implementer.cs @@ -1,6 +1,7 @@ using FishFactoryContracts.BindingModels; using FishFactoryContracts.ViewModels; using FishFactoryDataModel.Models; +using System.ComponentModel.DataAnnotations; using System.ComponentModel.DataAnnotations.Schema; namespace FishFactoryDatabaseImplement.Models @@ -8,14 +9,14 @@ namespace FishFactoryDatabaseImplement.Models public class Implementer : IImplementerModel { public int Id { get; private set; } - - public string ImplementerFIO { get; private set; } = string.Empty; - - public string Password { get; private set; } = string.Empty; - - public int WorkExperience { get; private set; } = 0; - - public int Qualification { get; private set; } = 0; + [Required] + public string ImplementerFIO { get; private set; } = string.Empty; + [Required] + public string Password { get; private set; } = string.Empty; + [Required] + public int WorkExperience { get; private set; } = 0; + [Required] + public int Qualification { get; private set; } = 0; [ForeignKey("ImplementerId")] public virtual List Order { get; set; } = new(); From 34004cd13f970e0301bf1bb2f64620816259e8cc Mon Sep 17 00:00:00 2001 From: dex_moth Date: Fri, 21 Jun 2024 20:59:30 +0400 Subject: [PATCH 3/3] =?UTF-8?q?=D1=80=D0=B0=D0=B1=D0=BE=D1=82=D0=B0=D0=B5?= =?UTF-8?q?=D1=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- FishFactory/FishFactory.csproj | 3 +++ FishFactoryBusinessLogic/BusinessLogic/WorkModeling.cs | 10 +++++----- .../SearchModels/ImplementerSearchModel.cs | 2 +- FishFactoryDatabaseImplement/Models/Order.cs | 6 ------ 4 files changed, 9 insertions(+), 12 deletions(-) diff --git a/FishFactory/FishFactory.csproj b/FishFactory/FishFactory.csproj index d2c10da..f36cb40 100644 --- a/FishFactory/FishFactory.csproj +++ b/FishFactory/FishFactory.csproj @@ -42,6 +42,9 @@ + + Always + Always diff --git a/FishFactoryBusinessLogic/BusinessLogic/WorkModeling.cs b/FishFactoryBusinessLogic/BusinessLogic/WorkModeling.cs index 73eada3..1a59259 100644 --- a/FishFactoryBusinessLogic/BusinessLogic/WorkModeling.cs +++ b/FishFactoryBusinessLogic/BusinessLogic/WorkModeling.cs @@ -31,9 +31,8 @@ namespace FishFactoryBusinessLogic.BusinessLogic return; } var orders = _orderLogic.ReadList(new OrderSearchModel { Status = OrderStatus.Принят }); - var processingOrders = _orderLogic.ReadList(new OrderSearchModel { Status = OrderStatus.Выполняется }); - if (orders == null || processingOrders == null || (orders.Count == 0 && processingOrders.Count == 0)) + if (orders == null || orders.Count == 0) { _logger.LogWarning("DoWork. Orders is null or empty"); return; @@ -78,7 +77,8 @@ namespace FishFactoryBusinessLogic.BusinessLogic { Id = order.Id }); - } + Thread.Sleep(implementer.Qualification * _rnd.Next(10, 100)); + } // кто-то мог уже перехватить заказ, игнорируем ошибку catch (InvalidOperationException ex) { @@ -91,7 +91,7 @@ namespace FishFactoryBusinessLogic.BusinessLogic throw; } // отдыхаем - Thread.Sleep(implementer.Qualification * _rnd.Next(10, 100)); + } }); } @@ -104,7 +104,7 @@ namespace FishFactoryBusinessLogic.BusinessLogic } try { - var runOrder = await Task.Run(() => _orderLogic.ReadElement(new OrderSearchModel + var runOrder = await Task.Run(() => _orderLogic.ReadElement(new() { ImplementerId = implementer.Id, Status = OrderStatus.Выполняется diff --git a/FishFactoryContracts/SearchModels/ImplementerSearchModel.cs b/FishFactoryContracts/SearchModels/ImplementerSearchModel.cs index 2420ab5..ec31f76 100644 --- a/FishFactoryContracts/SearchModels/ImplementerSearchModel.cs +++ b/FishFactoryContracts/SearchModels/ImplementerSearchModel.cs @@ -4,7 +4,7 @@ namespace FishFactoryContracts.SearchModels public class ImplementerSearchModel { public int? Id { get; set; } - public string? ImplementerFIO { get; set; } = string.Empty; + public string? ImplementerFIO { get; set; } = string.Empty; public string? Password { get; set; } = string.Empty; } } diff --git a/FishFactoryDatabaseImplement/Models/Order.cs b/FishFactoryDatabaseImplement/Models/Order.cs index a079ca2..10d329b 100644 --- a/FishFactoryDatabaseImplement/Models/Order.cs +++ b/FishFactoryDatabaseImplement/Models/Order.cs @@ -56,14 +56,8 @@ namespace FishFactoryDatabaseImplement.Models } using var context = new FishFactoryDatabase(); - Id = model.Id; - CannedId = model.CannedId; - ClientId = model.ClientId; ImplementerId = model.ImplementerId; - Implementer = model.ImplementerId.HasValue ? context.Implementers.First(x => x.Id == model.ImplementerId) : null; - Sum = model.Sum; Status = model.Status; - DateCreate = model.DateCreate; DateImplement = model.DateImplement; } public OrderViewModel GetViewModel => new()