From 095edd6a2496147e2ea0b1ab2ce6f6ee5fb59f05 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=9C=D0=BA=20=D0=98=D0=B3=D0=BE=D1=80=D1=8C?= Date: Mon, 27 Mar 2023 19:09:20 +0400 Subject: [PATCH] =?UTF-8?q?=D0=B4=D0=BE=D1=80=D0=B0=D0=B1=D0=BE=D1=82?= =?UTF-8?q?=D0=BA=D0=B0=20=D0=BC=D0=BE=D0=B4=D0=B5=D0=BB=D0=B5=D0=B9=20?= =?UTF-8?q?=D0=BF=D0=BE=20=D0=BA=D0=BB=D0=B8=D0=B5=D0=BD=D1=82=D0=B0=D0=BC?= =?UTF-8?q?=20=D0=B8=20=D0=B7=D0=B0=D0=BA=D0=B0=D0=B7=D0=B0=D0=BC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../BindingModels/OrderBindingModel.cs | 1 + .../SearchModels/OrderSearchModel.cs | 1 + .../ViewModels/OrderViewModel.cs | 2 + .../Implements/ClientStorage.cs | 2 +- .../Implements/OrderStorage.cs | 9 +- .../20230327145305_Lab5Migration.Designer.cs | 210 ++++++++++++++++++ .../20230327145305_Lab5Migration.cs | 51 +++++ ...BlacksmithWorkshopDatabaseModelSnapshot.cs | 6 +- .../Models/Order.cs | 11 +- .../Implements/ClientStorage.cs | 2 +- .../Implements/OrderStorage.cs | 11 +- .../Models/Order.cs | 13 +- .../Implements/ClientStorage.cs | 6 +- .../Implements/OrderStorage.cs | 15 +- .../Models/Order.cs | 7 +- .../Controllers/MainController.cs | 6 +- 16 files changed, 327 insertions(+), 26 deletions(-) create mode 100644 BlacksmithWorkshop/BlacksmithWorkshopDatebaseImplement/Migrations/20230327145305_Lab5Migration.Designer.cs create mode 100644 BlacksmithWorkshop/BlacksmithWorkshopDatebaseImplement/Migrations/20230327145305_Lab5Migration.cs diff --git a/BlacksmithWorkshop/BlacksmithWorkshopContracts/BindingModels/OrderBindingModel.cs b/BlacksmithWorkshop/BlacksmithWorkshopContracts/BindingModels/OrderBindingModel.cs index 334617b..f428f9b 100644 --- a/BlacksmithWorkshop/BlacksmithWorkshopContracts/BindingModels/OrderBindingModel.cs +++ b/BlacksmithWorkshop/BlacksmithWorkshopContracts/BindingModels/OrderBindingModel.cs @@ -12,5 +12,6 @@ namespace BlacksmithWorkshopContracts.BindingModels public OrderStatus Status { get; set; } = OrderStatus.Неизвестен; public DateTime DateCreate { get; set; } = DateTime.Now; public DateTime? DateImplement { get; set; } + public int ClientId { get; set; } } } \ No newline at end of file diff --git a/BlacksmithWorkshop/BlacksmithWorkshopContracts/SearchModels/OrderSearchModel.cs b/BlacksmithWorkshop/BlacksmithWorkshopContracts/SearchModels/OrderSearchModel.cs index ef64ba8..ba03a28 100644 --- a/BlacksmithWorkshop/BlacksmithWorkshopContracts/SearchModels/OrderSearchModel.cs +++ b/BlacksmithWorkshop/BlacksmithWorkshopContracts/SearchModels/OrderSearchModel.cs @@ -5,5 +5,6 @@ public int? Id { get; set; } public DateTime? DateFrom { get; set; } public DateTime? DateTo { get; set; } + public int? ClientId { get; set; } } } \ No newline at end of file diff --git a/BlacksmithWorkshop/BlacksmithWorkshopContracts/ViewModels/OrderViewModel.cs b/BlacksmithWorkshop/BlacksmithWorkshopContracts/ViewModels/OrderViewModel.cs index 6108267..1985bb4 100644 --- a/BlacksmithWorkshop/BlacksmithWorkshopContracts/ViewModels/OrderViewModel.cs +++ b/BlacksmithWorkshop/BlacksmithWorkshopContracts/ViewModels/OrderViewModel.cs @@ -21,5 +21,7 @@ namespace BlacksmithWorkshopContracts.ViewModels public DateTime DateCreate { get; set; } = DateTime.Now; [DisplayName("Дата выполнения")] public DateTime? DateImplement { get; set; } + [DisplayName("Клиент")] + public int ClientId { get; set; } } } \ No newline at end of file diff --git a/BlacksmithWorkshop/BlacksmithWorkshopDatebaseImplement/Implements/ClientStorage.cs b/BlacksmithWorkshop/BlacksmithWorkshopDatebaseImplement/Implements/ClientStorage.cs index 366aed9..84595a8 100644 --- a/BlacksmithWorkshop/BlacksmithWorkshopDatebaseImplement/Implements/ClientStorage.cs +++ b/BlacksmithWorkshop/BlacksmithWorkshopDatebaseImplement/Implements/ClientStorage.cs @@ -32,7 +32,7 @@ namespace BlacksmithWorkshopDatabaseImplement.Implements { return null; } - return context.Clients.FirstOrDefault(x => ((model.Id.HasValue && x.Id == model.Id) || (!string.IsNullOrEmpty(model.Email) && x.Email == model.Email) || (!string.IsNullOrEmpty(model.ClientFIO) && x.ClientFIO == model.ClientFIO)))?.GetViewModel; + return context.Clients.FirstOrDefault(x => ((model.Id.HasValue && x.Id == model.Id) || (!string.IsNullOrEmpty(model.Email) && x.Email == model.Email && !string.IsNullOrEmpty(model.ClientFIO) && x.ClientFIO == model.ClientFIO)))?.GetViewModel; } public ClientViewModel? Insert(ClientBindingModel model) { diff --git a/BlacksmithWorkshop/BlacksmithWorkshopDatebaseImplement/Implements/OrderStorage.cs b/BlacksmithWorkshop/BlacksmithWorkshopDatebaseImplement/Implements/OrderStorage.cs index a5c29f5..82841b1 100644 --- a/BlacksmithWorkshop/BlacksmithWorkshopDatebaseImplement/Implements/OrderStorage.cs +++ b/BlacksmithWorkshop/BlacksmithWorkshopDatebaseImplement/Implements/OrderStorage.cs @@ -24,7 +24,7 @@ namespace BlacksmithWorkshopDatabaseImplement.Implements } public List GetFilteredList(OrderSearchModel model) { - if (!model.Id.HasValue && (!model.DateFrom.HasValue || !model.DateTo.HasValue)) + if (!model.Id.HasValue && !model.ClientId.HasValue && (!model.DateFrom.HasValue || !model.DateTo.HasValue)) { return new(); } @@ -44,6 +44,13 @@ namespace BlacksmithWorkshopDatabaseImplement.Implements .Select(x => x.GetViewModel) .ToList(); } + else if (model.ClientId.HasValue) + { + orderList = context.Orders + .Where(x => x.ClientId == model.ClientId) + .Select(x => x.GetViewModel) + .ToList(); + } foreach (var order in orderList) { string manufactureName = context.Manufactures diff --git a/BlacksmithWorkshop/BlacksmithWorkshopDatebaseImplement/Migrations/20230327145305_Lab5Migration.Designer.cs b/BlacksmithWorkshop/BlacksmithWorkshopDatebaseImplement/Migrations/20230327145305_Lab5Migration.Designer.cs new file mode 100644 index 0000000..05649b7 --- /dev/null +++ b/BlacksmithWorkshop/BlacksmithWorkshopDatebaseImplement/Migrations/20230327145305_Lab5Migration.Designer.cs @@ -0,0 +1,210 @@ +// +using System; +using BlacksmithWorkshopDatabaseImplement; +using Microsoft.EntityFrameworkCore; +using Microsoft.EntityFrameworkCore.Infrastructure; +using Microsoft.EntityFrameworkCore.Metadata; +using Microsoft.EntityFrameworkCore.Migrations; +using Microsoft.EntityFrameworkCore.Storage.ValueConversion; + +#nullable disable + +namespace BlacksmithWorkshopDatebaseImplement.Migrations +{ + [DbContext(typeof(BlacksmithWorkshopDatabase))] + [Migration("20230327145305_Lab5Migration")] + partial class Lab5Migration + { + /// + 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("BlacksmithWorkshopDatabaseImplement.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("BlacksmithWorkshopDatabaseImplement.Models.Component", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("int"); + + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); + + b.Property("ComponentName") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.Property("Cost") + .HasColumnType("float"); + + b.HasKey("Id"); + + b.ToTable("Components"); + }); + + modelBuilder.Entity("BlacksmithWorkshopDatabaseImplement.Models.Manufacture", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("int"); + + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); + + b.Property("ManufactureName") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.Property("Price") + .HasColumnType("float"); + + b.HasKey("Id"); + + b.ToTable("Manufactures"); + }); + + modelBuilder.Entity("BlacksmithWorkshopDatabaseImplement.Models.ManufactureComponent", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("int"); + + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); + + b.Property("ComponentId") + .HasColumnType("int"); + + b.Property("Count") + .HasColumnType("int"); + + b.Property("ManufactureId") + .HasColumnType("int"); + + b.HasKey("Id"); + + b.HasIndex("ComponentId"); + + b.HasIndex("ManufactureId"); + + b.ToTable("ManufactureComponents"); + }); + + modelBuilder.Entity("BlacksmithWorkshopDatabaseImplement.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("ManufactureId") + .HasColumnType("int"); + + b.Property("Status") + .HasColumnType("int"); + + b.Property("Sum") + .HasColumnType("float"); + + b.HasKey("Id"); + + b.HasIndex("ClientId"); + + b.HasIndex("ManufactureId"); + + b.ToTable("Orders"); + }); + + modelBuilder.Entity("BlacksmithWorkshopDatabaseImplement.Models.ManufactureComponent", b => + { + b.HasOne("BlacksmithWorkshopDatabaseImplement.Models.Component", "Component") + .WithMany("ManufactureComponents") + .HasForeignKey("ComponentId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.HasOne("BlacksmithWorkshopDatabaseImplement.Models.Manufacture", "Manufacture") + .WithMany("Components") + .HasForeignKey("ManufactureId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.Navigation("Component"); + + b.Navigation("Manufacture"); + }); + + modelBuilder.Entity("BlacksmithWorkshopDatabaseImplement.Models.Order", b => + { + b.HasOne("BlacksmithWorkshopDatabaseImplement.Models.Client", null) + .WithMany("Orders") + .HasForeignKey("ClientId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.HasOne("BlacksmithWorkshopDatabaseImplement.Models.Manufacture", null) + .WithMany("Orders") + .HasForeignKey("ManufactureId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + }); + + modelBuilder.Entity("BlacksmithWorkshopDatabaseImplement.Models.Client", b => + { + b.Navigation("Orders"); + }); + + modelBuilder.Entity("BlacksmithWorkshopDatabaseImplement.Models.Component", b => + { + b.Navigation("ManufactureComponents"); + }); + + modelBuilder.Entity("BlacksmithWorkshopDatabaseImplement.Models.Manufacture", b => + { + b.Navigation("Components"); + + b.Navigation("Orders"); + }); +#pragma warning restore 612, 618 + } + } +} diff --git a/BlacksmithWorkshop/BlacksmithWorkshopDatebaseImplement/Migrations/20230327145305_Lab5Migration.cs b/BlacksmithWorkshop/BlacksmithWorkshopDatebaseImplement/Migrations/20230327145305_Lab5Migration.cs new file mode 100644 index 0000000..ca2c8f7 --- /dev/null +++ b/BlacksmithWorkshop/BlacksmithWorkshopDatebaseImplement/Migrations/20230327145305_Lab5Migration.cs @@ -0,0 +1,51 @@ +using Microsoft.EntityFrameworkCore.Migrations; + +#nullable disable + +namespace BlacksmithWorkshopDatebaseImplement.Migrations +{ + /// + public partial class Lab5Migration : Migration + { + /// + protected override void Up(MigrationBuilder migrationBuilder) + { + migrationBuilder.AlterColumn( + name: "ClientId", + table: "Orders", + type: "int", + nullable: false, + defaultValue: 0, + oldClrType: typeof(int), + oldType: "int", + oldNullable: true); + + 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.AlterColumn( + name: "ClientId", + table: "Orders", + type: "int", + nullable: true, + oldClrType: typeof(int), + oldType: "int"); + + migrationBuilder.AddForeignKey( + name: "FK_Orders_Clients_ClientId", + table: "Orders", + column: "ClientId", + principalTable: "Clients", + principalColumn: "Id"); + } + } +} diff --git a/BlacksmithWorkshop/BlacksmithWorkshopDatebaseImplement/Migrations/BlacksmithWorkshopDatabaseModelSnapshot.cs b/BlacksmithWorkshop/BlacksmithWorkshopDatebaseImplement/Migrations/BlacksmithWorkshopDatabaseModelSnapshot.cs index 3d6b04f..e0f81e4 100644 --- a/BlacksmithWorkshop/BlacksmithWorkshopDatebaseImplement/Migrations/BlacksmithWorkshopDatabaseModelSnapshot.cs +++ b/BlacksmithWorkshop/BlacksmithWorkshopDatebaseImplement/Migrations/BlacksmithWorkshopDatabaseModelSnapshot.cs @@ -121,7 +121,7 @@ namespace BlacksmithWorkshopDatebaseImplement.Migrations SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); - b.Property("ClientId") + b.Property("ClientId") .HasColumnType("int"); b.Property("Count") @@ -174,7 +174,9 @@ namespace BlacksmithWorkshopDatebaseImplement.Migrations { b.HasOne("BlacksmithWorkshopDatabaseImplement.Models.Client", null) .WithMany("Orders") - .HasForeignKey("ClientId"); + .HasForeignKey("ClientId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); b.HasOne("BlacksmithWorkshopDatabaseImplement.Models.Manufacture", null) .WithMany("Orders") diff --git a/BlacksmithWorkshop/BlacksmithWorkshopDatebaseImplement/Models/Order.cs b/BlacksmithWorkshop/BlacksmithWorkshopDatebaseImplement/Models/Order.cs index 9747f16..9054b80 100644 --- a/BlacksmithWorkshop/BlacksmithWorkshopDatebaseImplement/Models/Order.cs +++ b/BlacksmithWorkshop/BlacksmithWorkshopDatebaseImplement/Models/Order.cs @@ -20,6 +20,8 @@ namespace BlacksmithWorkshopDatabaseImplement.Models [Required] public DateTime DateCreate { get; private set; } = DateTime.Now; public DateTime? DateImplement { get; private set; } + [Required] + public int ClientId { get; private set; } public static Order? Create(OrderBindingModel model) { if (model == null) @@ -34,7 +36,8 @@ namespace BlacksmithWorkshopDatabaseImplement.Models Sum = model.Sum, Status = model.Status, DateCreate = model.DateCreate, - DateImplement = model.DateImplement + DateImplement = model.DateImplement, + ClientId = model.ClientId }; } public static Order Create(OrderViewModel model) @@ -47,7 +50,8 @@ namespace BlacksmithWorkshopDatabaseImplement.Models Sum = model.Sum, Status = model.Status, DateCreate = model.DateCreate, - DateImplement = model.DateImplement + DateImplement = model.DateImplement, + ClientId = model.ClientId }; } public void Update(OrderBindingModel? model) @@ -70,7 +74,8 @@ namespace BlacksmithWorkshopDatabaseImplement.Models Sum = Sum, Status = Status, DateCreate = DateCreate, - DateImplement = DateImplement + DateImplement = DateImplement, + ClientId = ClientId }; } } diff --git a/BlacksmithWorkshop/BlacksmithWorkshopFileImplement/Implements/ClientStorage.cs b/BlacksmithWorkshop/BlacksmithWorkshopFileImplement/Implements/ClientStorage.cs index 35dd67a..ee41e15 100644 --- a/BlacksmithWorkshop/BlacksmithWorkshopFileImplement/Implements/ClientStorage.cs +++ b/BlacksmithWorkshop/BlacksmithWorkshopFileImplement/Implements/ClientStorage.cs @@ -36,7 +36,7 @@ namespace BlacksmithWorkshopFileImplement.Implements { return null; } - return source.Clients.FirstOrDefault(x => ((model.Id.HasValue && x.Id == model.Id) || (!string.IsNullOrEmpty(model.Email) && x.Email == model.Email) || (!string.IsNullOrEmpty(model.ClientFIO) && x.ClientFIO == model.ClientFIO)))?.GetViewModel; + return source.Clients.FirstOrDefault(x => ((model.Id.HasValue && x.Id == model.Id) || (!string.IsNullOrEmpty(model.Email) && x.Email == model.Email && !string.IsNullOrEmpty(model.ClientFIO) && x.ClientFIO == model.ClientFIO)))?.GetViewModel; } public ClientViewModel? Insert(ClientBindingModel model) { diff --git a/BlacksmithWorkshop/BlacksmithWorkshopFileImplement/Implements/OrderStorage.cs b/BlacksmithWorkshop/BlacksmithWorkshopFileImplement/Implements/OrderStorage.cs index d37e815..ce7f21e 100644 --- a/BlacksmithWorkshop/BlacksmithWorkshopFileImplement/Implements/OrderStorage.cs +++ b/BlacksmithWorkshop/BlacksmithWorkshopFileImplement/Implements/OrderStorage.cs @@ -27,7 +27,7 @@ namespace BlacksmithWorkshopFileImplement.Implements } public List GetFilteredList(OrderSearchModel model) { - if (!model.Id.HasValue && (!model.DateFrom.HasValue || !model.DateTo.HasValue)) + if (!model.Id.HasValue && !model.ClientId.HasValue && (!model.DateFrom.HasValue || !model.DateTo.HasValue)) { return new(); } @@ -45,7 +45,14 @@ namespace BlacksmithWorkshopFileImplement.Implements .Select(x => AddManufactureName(x.GetViewModel)) .ToList(); } - return new();//если нет ни того, ни другого, возвращаем пустой список + else if (model.ClientId.HasValue)//далее ищем по Id клиента + { + return source.Orders + .Where(x => x.ClientId == model.ClientId) + .Select(x => AddManufactureName(x.GetViewModel)) + .ToList(); + } + return new();//если нет ни того, ни другого, ни третьего, возвращаем пустой список } public OrderViewModel? GetElement(OrderSearchModel model) { diff --git a/BlacksmithWorkshop/BlacksmithWorkshopFileImplement/Models/Order.cs b/BlacksmithWorkshop/BlacksmithWorkshopFileImplement/Models/Order.cs index 8ce8605..2e0755f 100644 --- a/BlacksmithWorkshop/BlacksmithWorkshopFileImplement/Models/Order.cs +++ b/BlacksmithWorkshop/BlacksmithWorkshopFileImplement/Models/Order.cs @@ -15,6 +15,7 @@ namespace BlacksmithWorkshopFileImplement.Models public OrderStatus Status { get; private set; } = OrderStatus.Неизвестен; public DateTime DateCreate { get; private set; } = DateTime.Now; public DateTime? DateImplement { get; private set; } + public int ClientId { get; private set; } public static Order? Create(OrderBindingModel? model) { if (model == null) @@ -29,7 +30,8 @@ namespace BlacksmithWorkshopFileImplement.Models Sum = model.Sum, Status = model.Status, DateCreate = model.DateCreate, - DateImplement = model.DateImplement + DateImplement = model.DateImplement, + ClientId = model.ClientId }; } public static Order? Create(XElement element) @@ -51,7 +53,8 @@ namespace BlacksmithWorkshopFileImplement.Models Sum = Convert.ToDouble(element.Element("Sum")!.Value), Status = (OrderStatus)Convert.ToInt32(element.Element("Status")!.Value), DateCreate = Convert.ToDateTime(element.Element("DateCreate")!.Value), - DateImplement = dateImplement + DateImplement = dateImplement, + ClientId = Convert.ToInt32(element.Element("ClientId")!.Value), }; } public void Update(OrderBindingModel? model) @@ -74,7 +77,8 @@ namespace BlacksmithWorkshopFileImplement.Models Sum = Sum, Status = Status, DateCreate = DateCreate, - DateImplement = DateImplement + DateImplement = DateImplement, + ClientId = ClientId }; public XElement GetXElement => new ( @@ -85,7 +89,8 @@ namespace BlacksmithWorkshopFileImplement.Models new XElement("Sum", Sum), new XElement("Status", (int)Status), new XElement("DateCreate", DateCreate), - new XElement("DateImplement", DateImplement) + new XElement("DateImplement", DateImplement), + new XElement("ClientId", ClientId) ); } } \ No newline at end of file diff --git a/BlacksmithWorkshop/BlacksmithWorkshopListImplement/Implements/ClientStorage.cs b/BlacksmithWorkshop/BlacksmithWorkshopListImplement/Implements/ClientStorage.cs index 422a8b4..32b5195 100644 --- a/BlacksmithWorkshop/BlacksmithWorkshopListImplement/Implements/ClientStorage.cs +++ b/BlacksmithWorkshop/BlacksmithWorkshopListImplement/Implements/ClientStorage.cs @@ -53,11 +53,7 @@ namespace BlacksmithWorkshopListImplement.Implements { return client.GetViewModel; } - if (model.Email != null && client.Email.Contains(model.Email))//затем по логину - { - return client.GetViewModel; - } - if (model.ClientFIO != null && client.ClientFIO.Contains(model.ClientFIO))//затем по ФИО + if (model.Email != null && client.Email.Contains(model.Email) && model.Password != null && client.Password.Contains(model.Password))//затем по логину и паролю { return client.GetViewModel; } diff --git a/BlacksmithWorkshop/BlacksmithWorkshopListImplement/Implements/OrderStorage.cs b/BlacksmithWorkshop/BlacksmithWorkshopListImplement/Implements/OrderStorage.cs index 3246ce6..5047ad0 100644 --- a/BlacksmithWorkshop/BlacksmithWorkshopListImplement/Implements/OrderStorage.cs +++ b/BlacksmithWorkshop/BlacksmithWorkshopListImplement/Implements/OrderStorage.cs @@ -28,7 +28,7 @@ namespace BlacksmithWorkshopListImplement.Implements public List GetFilteredList(OrderSearchModel model) { var result = new List(); - if (!model.Id.HasValue && (!model.DateFrom.HasValue || !model.DateTo.HasValue)) + if (!model.Id.HasValue && !model.ClientId.HasValue && (!model.DateFrom.HasValue || !model.DateTo.HasValue)) { return result; } @@ -58,6 +58,19 @@ namespace BlacksmithWorkshopListImplement.Implements } } } + else if (model.ClientId.HasValue)//далее ищем по Id клиента + { + foreach (var order in _source.Orders) + { + if (order.ClientId == model.ClientId) + { + OrderViewModel vm = order.GetViewModel; + var manufacture = _source.Manufactures.Find(x => x.Id == order.ManufactureId); + vm.ManufactureName = manufacture?.ManufactureName ?? string.Empty; + result.Add(vm); + } + } + } return result; } public OrderViewModel? GetElement(OrderSearchModel model) diff --git a/BlacksmithWorkshop/BlacksmithWorkshopListImplement/Models/Order.cs b/BlacksmithWorkshop/BlacksmithWorkshopListImplement/Models/Order.cs index 5772867..ecc4224 100644 --- a/BlacksmithWorkshop/BlacksmithWorkshopListImplement/Models/Order.cs +++ b/BlacksmithWorkshop/BlacksmithWorkshopListImplement/Models/Order.cs @@ -15,6 +15,7 @@ namespace BlacksmithWorkshopListImplement.Models public OrderStatus Status { get; private set; } = OrderStatus.Неизвестен; public DateTime DateCreate { get; private set; } = DateTime.Now; public DateTime? DateImplement { get; private set; } + public int ClientId { get; private set; } public static Order? Create(OrderBindingModel? model) { if (model == null) @@ -29,7 +30,8 @@ namespace BlacksmithWorkshopListImplement.Models Sum = model.Sum, Status = model.Status, DateCreate = model.DateCreate, - DateImplement = model.DateImplement + DateImplement = model.DateImplement, + ClientId = model.ClientId }; } public void Update(OrderBindingModel? model) @@ -52,7 +54,8 @@ namespace BlacksmithWorkshopListImplement.Models Sum = Sum, Status = Status, DateCreate = DateCreate, - DateImplement = DateImplement + DateImplement = DateImplement, + ClientId = ClientId }; } } \ No newline at end of file diff --git a/BlacksmithWorkshop/BlacksmithWorkshopRestAPI/Controllers/MainController.cs b/BlacksmithWorkshop/BlacksmithWorkshopRestAPI/Controllers/MainController.cs index 250c4ae..b9bff64 100644 --- a/BlacksmithWorkshop/BlacksmithWorkshopRestAPI/Controllers/MainController.cs +++ b/BlacksmithWorkshop/BlacksmithWorkshopRestAPI/Controllers/MainController.cs @@ -40,14 +40,12 @@ namespace BlacksmithWorkshopRestAPI.Controllers { return _manufacture.ReadElement(new ManufactureSearchModel { - Id = - manufactureId + Id = manufactureId }); } catch (Exception ex) { - _logger.LogError(ex, "Ошибка получения продукта по id={Id}", - manufactureId); + _logger.LogError(ex, "Ошибка получения продукта по id={Id}", manufactureId); throw; } }