diff --git a/KopLab1/Forms/Forms.csproj b/KopLab1/Forms/Forms.csproj
index 07a9ca3..764e403 100644
--- a/KopLab1/Forms/Forms.csproj
+++ b/KopLab1/Forms/Forms.csproj
@@ -8,8 +8,17 @@
enable
+
+
+
+ all
+ runtime; build; native; contentfiles; analyzers; buildtransitive
+
+
+
+
\ No newline at end of file
diff --git a/KopLab1/InetShopDataModels/IId.cs b/KopLab1/InetShopDataModels/IId.cs
new file mode 100644
index 0000000..0290158
--- /dev/null
+++ b/KopLab1/InetShopDataModels/IId.cs
@@ -0,0 +1,7 @@
+namespace InternetShopOrdersDataModels
+{
+ public interface IId
+ {
+ int Id { get; }
+ }
+}
diff --git a/KopLab1/InetShopDataModels/InternetShopOrdersDataModels.csproj b/KopLab1/InetShopDataModels/InternetShopOrdersDataModels.csproj
new file mode 100644
index 0000000..fa71b7a
--- /dev/null
+++ b/KopLab1/InetShopDataModels/InternetShopOrdersDataModels.csproj
@@ -0,0 +1,9 @@
+
+
+
+ net8.0
+ enable
+ enable
+
+
+
diff --git a/KopLab1/InetShopDataModels/Models/ICityModel.cs b/KopLab1/InetShopDataModels/Models/ICityModel.cs
new file mode 100644
index 0000000..c06307d
--- /dev/null
+++ b/KopLab1/InetShopDataModels/Models/ICityModel.cs
@@ -0,0 +1,13 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace InternetShopOrdersDataModels.Models
+{
+ public interface ICityModel : IId
+ {
+ string Name { get; }
+ }
+}
diff --git a/KopLab1/InetShopDataModels/Models/IOrderModel.cs b/KopLab1/InetShopDataModels/Models/IOrderModel.cs
new file mode 100644
index 0000000..79896a5
--- /dev/null
+++ b/KopLab1/InetShopDataModels/Models/IOrderModel.cs
@@ -0,0 +1,23 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace InternetShopOrdersDataModels.Models
+{
+ public interface IOrderModel : IId
+ {
+ // Полное имя заказчика
+ string Fullname { get; }
+
+ // Метки движения заказа (не более 6)
+ List OrderStatusHistory { get; }
+
+ // Город назначения
+ int DestinationCityId { get; }
+
+ // Дата получения заказа
+ DateTime ExpectedDeliveryDate { get; }
+ }
+}
diff --git a/KopLab1/InternetShopOrdersBusinessLogic/BusinessLogics/CityLogic.cs b/KopLab1/InternetShopOrdersBusinessLogic/BusinessLogics/CityLogic.cs
new file mode 100644
index 0000000..e64c193
--- /dev/null
+++ b/KopLab1/InternetShopOrdersBusinessLogic/BusinessLogics/CityLogic.cs
@@ -0,0 +1,87 @@
+using InternetShopOrdersContracts.BindingModels;
+using InternetShopOrdersContracts.BusinessLogicContracts;
+using InternetShopOrdersContracts.SearchModels;
+using InternetShopOrdersContracts.StorageContracts;
+using InternetShopOrdersContracts.ViewModels;
+
+namespace InternetShopOrdersBusinessLogic.BusinessLogics
+{
+ public class CityLogic : ICityLogic
+ {
+ private readonly ICityStorage _selectedItemStorage;
+
+ public CityLogic(ICityStorage selectedItemStorage)
+ {
+ _selectedItemStorage = selectedItemStorage;
+ }
+
+ public List? ReadList(CitySearchModel? model)
+ {
+ var list = model == null ? _selectedItemStorage.GetFullList() : _selectedItemStorage.GetFilteredList(model);
+ if (list == null)
+ {
+ return null;
+ }
+ return list;
+ }
+
+ public CityViewModel? ReadElement(CitySearchModel model)
+ {
+ if (model == null)
+ {
+ throw new ArgumentNullException(nameof(model));
+ }
+ var element = _selectedItemStorage.GetElement(model);
+ if (element == null)
+ {
+ return null;
+ }
+ return element;
+ }
+
+ public bool Create(CityBindingModel model)
+ {
+ CheckModel(model);
+ if (_selectedItemStorage.Insert(model) == null)
+ {
+ return false;
+ }
+ return true;
+ }
+
+ public bool Update(CityBindingModel model)
+ {
+ CheckModel(model);
+ if (_selectedItemStorage.Update(model) == null)
+ {
+ return false;
+ }
+ return true;
+ }
+ public bool Delete(CityBindingModel model)
+ {
+ CheckModel(model, false);
+ if (_selectedItemStorage.Delete(model) == null)
+ {
+ return false;
+ }
+ return true;
+ }
+
+ private void CheckModel(CityBindingModel model, bool withParams = true)
+ {
+ if (model == null)
+ {
+ throw new ArgumentNullException(nameof(model));
+ }
+ if (!withParams)
+ {
+ return;
+ }
+ if (string.IsNullOrEmpty(model.Name))
+ {
+ throw new ArgumentNullException("Нет названия города", nameof(model.Name));
+ }
+ }
+ }
+}
diff --git a/KopLab1/InternetShopOrdersBusinessLogic/BusinessLogics/OrderLogic.cs b/KopLab1/InternetShopOrdersBusinessLogic/BusinessLogics/OrderLogic.cs
new file mode 100644
index 0000000..861c6dd
--- /dev/null
+++ b/KopLab1/InternetShopOrdersBusinessLogic/BusinessLogics/OrderLogic.cs
@@ -0,0 +1,88 @@
+using InternetShopOrdersContracts.BindingModels;
+using InternetShopOrdersContracts.BusinessLogicContracts;
+using InternetShopOrdersContracts.SearchModels;
+using InternetShopOrdersContracts.StorageContracts;
+using InternetShopOrdersContracts.ViewModels;
+
+namespace InternetShopOrdersBusinessLogic.BusinessLogics
+{
+ public class OrderLogic : IOrderLogic
+ {
+ private readonly IOrderStorage _orderStorage;
+
+ public OrderLogic(IOrderStorage orderStorage)
+ {
+ _orderStorage = orderStorage;
+ }
+
+ public List? ReadList(OrderSearchModel? model)
+ {
+ var list = model == null ? _orderStorage.GetFullList() : _orderStorage.GetFilteredList(model);
+ if (list == null)
+ {
+ return null;
+ }
+ return list;
+ }
+
+ public OrderViewModel? ReadElement(OrderSearchModel? model)
+ {
+ if (model == null)
+ {
+ throw new ArgumentNullException(nameof(model));
+ }
+ var element = _orderStorage.GetElement(model);
+ if (element == null)
+ {
+ return null;
+ }
+ return element;
+ }
+
+ public bool Create(OrderBindingModel model)
+ {
+ CheckModel(model);
+ if (_orderStorage.Insert(model) == null)
+ {
+ return false;
+ }
+ return true;
+ }
+
+ public bool Update(OrderBindingModel model)
+ {
+ CheckModel(model);
+ if (_orderStorage.Update(model) == null)
+ {
+ return false;
+ }
+ return true;
+ }
+
+ public bool Delete(OrderBindingModel model)
+ {
+ CheckModel(model, false);
+ if (_orderStorage.Delete(model) == null)
+ {
+ return false;
+ }
+ return true;
+ }
+
+ private void CheckModel(OrderBindingModel model, bool withParams = true)
+ {
+ if (model == null)
+ {
+ throw new ArgumentNullException(nameof(model));
+ }
+ if (!withParams)
+ {
+ return;
+ }
+ if (string.IsNullOrEmpty(model.Fullname))
+ {
+ throw new ArgumentNullException("Нет ФИО заказчика", nameof(model.Fullname));
+ }
+ }
+ }
+}
diff --git a/KopLab1/InternetShopOrdersBusinessLogic/InternetShopOrdersBusinessLogic.csproj b/KopLab1/InternetShopOrdersBusinessLogic/InternetShopOrdersBusinessLogic.csproj
new file mode 100644
index 0000000..ac1a112
--- /dev/null
+++ b/KopLab1/InternetShopOrdersBusinessLogic/InternetShopOrdersBusinessLogic.csproj
@@ -0,0 +1,15 @@
+
+
+
+ net8.0
+ enable
+ enable
+
+
+
+
+
+
+
+
+
diff --git a/KopLab1/InternetShopOrdersContracts/BindingModels/CityBindingModel.cs b/KopLab1/InternetShopOrdersContracts/BindingModels/CityBindingModel.cs
new file mode 100644
index 0000000..1a456a4
--- /dev/null
+++ b/KopLab1/InternetShopOrdersContracts/BindingModels/CityBindingModel.cs
@@ -0,0 +1,15 @@
+using InternetShopOrdersDataModels.Models;
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace InternetShopOrdersContracts.BindingModels
+{
+ public class CityBindingModel : ICityModel
+ {
+ public int Id { get; set; }
+ public string Name { get; set; } = String.Empty;
+ }
+}
diff --git a/KopLab1/InternetShopOrdersContracts/BindingModels/OrderBindingModel.cs b/KopLab1/InternetShopOrdersContracts/BindingModels/OrderBindingModel.cs
new file mode 100644
index 0000000..8926dee
--- /dev/null
+++ b/KopLab1/InternetShopOrdersContracts/BindingModels/OrderBindingModel.cs
@@ -0,0 +1,16 @@
+using System;
+using System.Collections.Generic;
+using InternetShopOrdersDataModels.Models;
+
+namespace InternetShopOrdersContracts.BindingModels
+{
+ public class OrderBindingModel : IOrderModel
+ {
+ public int Id { get; set; }
+ public string Fullname { get; set; } = string.Empty;
+ public List OrderStatusHistory { get; set; } = new List();
+ public int DestinationCityId { get; set; }
+ public ICityModel DestinationCity { get; set; }
+ public DateTime ExpectedDeliveryDate { get; set; }
+ }
+}
diff --git a/KopLab1/InternetShopOrdersContracts/BusinessLogicContracts/ICityLogic.cs b/KopLab1/InternetShopOrdersContracts/BusinessLogicContracts/ICityLogic.cs
new file mode 100644
index 0000000..c8fbb10
--- /dev/null
+++ b/KopLab1/InternetShopOrdersContracts/BusinessLogicContracts/ICityLogic.cs
@@ -0,0 +1,20 @@
+using InternetShopOrdersContracts.BindingModels;
+using InternetShopOrdersContracts.SearchModels;
+using InternetShopOrdersContracts.ViewModels;
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace InternetShopOrdersContracts.BusinessLogicContracts
+{
+ public interface ICityLogic
+ {
+ List? ReadList(CitySearchModel? model);
+ CityViewModel? ReadElement(CitySearchModel model);
+ bool Create(CityBindingModel model);
+ bool Update(CityBindingModel model);
+ bool Delete(CityBindingModel model);
+ }
+}
diff --git a/KopLab1/InternetShopOrdersContracts/BusinessLogicContracts/IOrderLogic.cs b/KopLab1/InternetShopOrdersContracts/BusinessLogicContracts/IOrderLogic.cs
new file mode 100644
index 0000000..b7ff318
--- /dev/null
+++ b/KopLab1/InternetShopOrdersContracts/BusinessLogicContracts/IOrderLogic.cs
@@ -0,0 +1,20 @@
+using InternetShopOrdersContracts.BindingModels;
+using InternetShopOrdersContracts.SearchModels;
+using InternetShopOrdersContracts.ViewModels;
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace InternetShopOrdersContracts.BusinessLogicContracts
+{
+ public interface IOrderLogic
+ {
+ List? ReadList(OrderSearchModel? model);
+ OrderViewModel? ReadElement(OrderSearchModel model);
+ bool Create(OrderBindingModel model);
+ bool Update(OrderBindingModel model);
+ bool Delete(OrderBindingModel model);
+ }
+}
diff --git a/KopLab1/InternetShopOrdersContracts/InternetShopOrdersContracts.csproj b/KopLab1/InternetShopOrdersContracts/InternetShopOrdersContracts.csproj
new file mode 100644
index 0000000..05323f2
--- /dev/null
+++ b/KopLab1/InternetShopOrdersContracts/InternetShopOrdersContracts.csproj
@@ -0,0 +1,13 @@
+
+
+
+ net8.0
+ enable
+ enable
+
+
+
+
+
+
+
diff --git a/KopLab1/InternetShopOrdersContracts/SearchModels/CitySearchModel.cs b/KopLab1/InternetShopOrdersContracts/SearchModels/CitySearchModel.cs
new file mode 100644
index 0000000..1ce8441
--- /dev/null
+++ b/KopLab1/InternetShopOrdersContracts/SearchModels/CitySearchModel.cs
@@ -0,0 +1,13 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace InternetShopOrdersContracts.SearchModels
+{
+ public class CitySearchModel
+ {
+ public int? Id { get; set; }
+ }
+}
diff --git a/KopLab1/InternetShopOrdersContracts/SearchModels/OrderSearchModel.cs b/KopLab1/InternetShopOrdersContracts/SearchModels/OrderSearchModel.cs
new file mode 100644
index 0000000..7cbdd5b
--- /dev/null
+++ b/KopLab1/InternetShopOrdersContracts/SearchModels/OrderSearchModel.cs
@@ -0,0 +1,13 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace InternetShopOrdersContracts.SearchModels
+{
+ public class OrderSearchModel
+ {
+ public int? Id { get; set; }
+ }
+}
diff --git a/KopLab1/InternetShopOrdersContracts/StorageContracts/ICityStorage.cs b/KopLab1/InternetShopOrdersContracts/StorageContracts/ICityStorage.cs
new file mode 100644
index 0000000..52712af
--- /dev/null
+++ b/KopLab1/InternetShopOrdersContracts/StorageContracts/ICityStorage.cs
@@ -0,0 +1,21 @@
+using InternetShopOrdersContracts.BindingModels;
+using InternetShopOrdersContracts.SearchModels;
+using InternetShopOrdersContracts.ViewModels;
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace InternetShopOrdersContracts.StorageContracts
+{
+ public interface ICityStorage
+ {
+ List GetFullList();
+ List GetFilteredList(CitySearchModel model);
+ CityViewModel? GetElement(CitySearchModel model);
+ CityViewModel? Insert(CityBindingModel model);
+ CityViewModel? Update(CityBindingModel model);
+ CityViewModel? Delete(CityBindingModel model);
+ }
+}
diff --git a/KopLab1/InternetShopOrdersContracts/StorageContracts/IOrderStorage.cs b/KopLab1/InternetShopOrdersContracts/StorageContracts/IOrderStorage.cs
new file mode 100644
index 0000000..c7dae00
--- /dev/null
+++ b/KopLab1/InternetShopOrdersContracts/StorageContracts/IOrderStorage.cs
@@ -0,0 +1,21 @@
+using InternetShopOrdersContracts.BindingModels;
+using InternetShopOrdersContracts.SearchModels;
+using InternetShopOrdersContracts.ViewModels;
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace InternetShopOrdersContracts.StorageContracts
+{
+ public interface IOrderStorage
+ {
+ List GetFullList();
+ List GetFilteredList(OrderSearchModel model);
+ OrderViewModel? GetElement(OrderSearchModel model);
+ OrderViewModel? Insert(OrderBindingModel model);
+ OrderViewModel? Update(OrderBindingModel model);
+ OrderViewModel? Delete(OrderBindingModel model);
+ }
+}
diff --git a/KopLab1/InternetShopOrdersContracts/ViewModels/CityViewModel.cs b/KopLab1/InternetShopOrdersContracts/ViewModels/CityViewModel.cs
new file mode 100644
index 0000000..455b33e
--- /dev/null
+++ b/KopLab1/InternetShopOrdersContracts/ViewModels/CityViewModel.cs
@@ -0,0 +1,17 @@
+using InternetShopOrdersDataModels.Models;
+using System;
+using System.Collections.Generic;
+using System.ComponentModel;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace InternetShopOrdersContracts.ViewModels
+{
+ public class CityViewModel : ICityModel
+ {
+ public int Id { get; set; }
+ [DisplayName("Название")]
+ public string Name { get; set; } = string.Empty;
+ }
+}
diff --git a/KopLab1/InternetShopOrdersContracts/ViewModels/OrderViewModel.cs b/KopLab1/InternetShopOrdersContracts/ViewModels/OrderViewModel.cs
new file mode 100644
index 0000000..469a5ce
--- /dev/null
+++ b/KopLab1/InternetShopOrdersContracts/ViewModels/OrderViewModel.cs
@@ -0,0 +1,28 @@
+using InternetShopOrdersDataModels.Models;
+using System;
+using System.Collections.Generic;
+using System.ComponentModel;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace InternetShopOrdersContracts.ViewModels
+{
+ public class OrderViewModel : IOrderModel
+ {
+ public int Id { get; set; }
+
+ [DisplayName("ФИО заказчика")]
+ public string Fullname { get; set; } = string.Empty;
+
+ [DisplayName("История заказа")]
+ public List OrderStatusHistory { get; set; }
+
+ public int DestinationCityId { get; set; }
+ [DisplayName("Город назначения")]
+ public string DestinationCityName { get; set; }
+
+ [DisplayName("Дата получения заказа")]
+ public DateTime ExpectedDeliveryDate { get; set; }
+ }
+}
diff --git a/KopLab1/InternetShopOrdersDatabaseImplement/Implements/CityStorage.cs b/KopLab1/InternetShopOrdersDatabaseImplement/Implements/CityStorage.cs
new file mode 100644
index 0000000..75c7285
--- /dev/null
+++ b/KopLab1/InternetShopOrdersDatabaseImplement/Implements/CityStorage.cs
@@ -0,0 +1,79 @@
+using InternetShopOrdersContracts.BindingModels;
+using InternetShopOrdersContracts.SearchModels;
+using InternetShopOrdersContracts.StorageContracts;
+using InternetShopOrdersContracts.ViewModels;
+using InternetShopOrdersDatabaseImplement.Models;
+using Microsoft.EntityFrameworkCore;
+
+namespace InternetShopOrdersDatabaseImplement.Implements
+{
+ public class CityStorage : ICityStorage
+ {
+ public List GetFullList()
+ {
+ using var context = new OrdersDatabase();
+ return context.Cities
+ .Select(x => x.GetViewModel)
+ .ToList();
+ }
+ public List GetFilteredList(CitySearchModel model)
+ {
+ if (!model.Id.HasValue)
+ {
+ return new();
+ }
+ using var context = new OrdersDatabase();
+ return context.Cities
+ .Where(x => x.Id == model.Id)
+ .Select(x => x.GetViewModel)
+ .ToList();
+ }
+ public CityViewModel? GetElement(CitySearchModel model)
+ {
+ if (!model.Id.HasValue)
+ {
+ return null;
+ }
+ using var context = new OrdersDatabase();
+ return context.Cities
+ .FirstOrDefault(x => model.Id.HasValue && x.Id == model.Id)
+ ?.GetViewModel;
+ }
+ public CityViewModel? Insert(CityBindingModel model)
+ {
+ var newSelectedItem = Cities.Create(model);
+ if (newSelectedItem == null)
+ {
+ return null;
+ }
+ using var context = new OrdersDatabase();
+ context.Cities.Add(newSelectedItem);
+ context.SaveChanges();
+ return newSelectedItem.GetViewModel;
+ }
+ public CityViewModel? Update(CityBindingModel model)
+ {
+ using var context = new OrdersDatabase();
+ var component = context.Cities.FirstOrDefault(x => x.Id == model.Id);
+ if (component == null)
+ {
+ return null;
+ }
+ component.Update(model);
+ context.SaveChanges();
+ return component.GetViewModel;
+ }
+ public CityViewModel? Delete(CityBindingModel model)
+ {
+ using var context = new OrdersDatabase();
+ var element = context.Cities.FirstOrDefault(rec => rec.Id == model.Id);
+ if (element != null)
+ {
+ context.Cities.Remove(element);
+ context.SaveChanges();
+ return element.GetViewModel;
+ }
+ return null;
+ }
+ }
+}
diff --git a/KopLab1/InternetShopOrdersDatabaseImplement/Implements/OrderStorage.cs b/KopLab1/InternetShopOrdersDatabaseImplement/Implements/OrderStorage.cs
new file mode 100644
index 0000000..2758ab1
--- /dev/null
+++ b/KopLab1/InternetShopOrdersDatabaseImplement/Implements/OrderStorage.cs
@@ -0,0 +1,87 @@
+using InternetShopOrdersContracts.BindingModels;
+using InternetShopOrdersContracts.SearchModels;
+using InternetShopOrdersContracts.StorageContracts;
+using InternetShopOrdersContracts.ViewModels;
+using InternetShopOrdersDatabaseImplement.Models;
+using Microsoft.EntityFrameworkCore;
+using System.Security.Principal;
+
+namespace InternetShopOrdersDatabaseImplement.Implements
+{
+ public class OrderStorage : IOrderStorage
+ {
+ public List GetFullList()
+ {
+ using var context = new OrdersDatabase();
+ return context.Orders
+ .Include(x => x.DestinationCity)
+ .Select(x => x.GetViewModel)
+ .ToList();
+ }
+ public List GetFilteredList(OrderSearchModel model)
+ {
+ if (!model.Id.HasValue)
+ {
+ return new();
+ }
+
+ using var context = new OrdersDatabase();
+ return context.Orders
+ .Include(x => x.DestinationCity)
+ .Where(x => x.Id == model.Id)
+ .Select(x => x.GetViewModel)
+ .ToList();
+ }
+ public OrderViewModel? GetElement(OrderSearchModel model)
+ {
+ if (!model.Id.HasValue)
+ {
+ return null;
+ }
+
+ using var context = new OrdersDatabase();
+ return context.Orders
+ .Include(x => x.DestinationCity)
+ .FirstOrDefault(x => x.Id == model.Id)
+ ?.GetViewModel;
+ }
+ public OrderViewModel? Insert(OrderBindingModel model)
+ {
+ using var context = new OrdersDatabase();
+ var newOrder = Orders.Create(context, model);
+ if (newOrder == null)
+ {
+ return null;
+ }
+ context.Orders.Add(newOrder);
+ context.SaveChanges();
+ return newOrder.GetViewModel;
+ }
+ public OrderViewModel? Update(OrderBindingModel model)
+ {
+ using var context = new OrdersDatabase();
+ var Order = context.Orders.FirstOrDefault(x => x.Id == model.Id);
+ if (Order == null)
+ {
+ return null;
+ }
+ Order.Update(model, context);
+ context.SaveChanges();
+ return Order.GetViewModel;
+ }
+ public OrderViewModel? Delete(OrderBindingModel model)
+ {
+ using var context = new OrdersDatabase();
+ var element = context.Orders
+ .Include(x => x.DestinationCity)
+ .FirstOrDefault(rec => rec.Id == model.Id);
+ if (element != null)
+ {
+ context.Orders.Remove(element);
+ context.SaveChanges();
+ return element.GetViewModel;
+ }
+ return null;
+ }
+ }
+}
diff --git a/KopLab1/InternetShopOrdersDatabaseImplement/InternetShopOrdersDatabaseImplement.csproj b/KopLab1/InternetShopOrdersDatabaseImplement/InternetShopOrdersDatabaseImplement.csproj
new file mode 100644
index 0000000..2e8d5d8
--- /dev/null
+++ b/KopLab1/InternetShopOrdersDatabaseImplement/InternetShopOrdersDatabaseImplement.csproj
@@ -0,0 +1,23 @@
+
+
+
+ net8.0
+ enable
+ enable
+
+
+
+
+
+ all
+ runtime; build; native; contentfiles; analyzers; buildtransitive
+
+
+
+
+
+
+
+
+
+
diff --git a/KopLab1/InternetShopOrdersDatabaseImplement/Migrations/20241027193729_InitialCreate.Designer.cs b/KopLab1/InternetShopOrdersDatabaseImplement/Migrations/20241027193729_InitialCreate.Designer.cs
new file mode 100644
index 0000000..1cb41bf
--- /dev/null
+++ b/KopLab1/InternetShopOrdersDatabaseImplement/Migrations/20241027193729_InitialCreate.Designer.cs
@@ -0,0 +1,88 @@
+//
+using System;
+using System.Collections.Generic;
+using InternetShopOrdersDatabaseImplement;
+using Microsoft.EntityFrameworkCore;
+using Microsoft.EntityFrameworkCore.Infrastructure;
+using Microsoft.EntityFrameworkCore.Migrations;
+using Microsoft.EntityFrameworkCore.Storage.ValueConversion;
+using Npgsql.EntityFrameworkCore.PostgreSQL.Metadata;
+
+#nullable disable
+
+namespace InternetShopOrdersDatabaseImplement.Migrations
+{
+ [DbContext(typeof(OrdersDatabase))]
+ [Migration("20241027193729_InitialCreate")]
+ partial class InitialCreate
+ {
+ ///
+ protected override void BuildTargetModel(ModelBuilder modelBuilder)
+ {
+#pragma warning disable 612, 618
+ modelBuilder
+ .HasAnnotation("ProductVersion", "8.0.10")
+ .HasAnnotation("Relational:MaxIdentifierLength", 63);
+
+ NpgsqlModelBuilderExtensions.UseIdentityByDefaultColumns(modelBuilder);
+
+ modelBuilder.Entity("InternetShopOrdersDatabaseImplement.Models.Cities", b =>
+ {
+ b.Property("Id")
+ .ValueGeneratedOnAdd()
+ .HasColumnType("integer");
+
+ NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property("Id"));
+
+ b.Property("Name")
+ .IsRequired()
+ .HasColumnType("text");
+
+ b.HasKey("Id");
+
+ b.ToTable("Cities");
+ });
+
+ modelBuilder.Entity("InternetShopOrdersDatabaseImplement.Models.Orders", b =>
+ {
+ b.Property("Id")
+ .ValueGeneratedOnAdd()
+ .HasColumnType("integer");
+
+ NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property("Id"));
+
+ b.Property("DestinationCityId")
+ .HasColumnType("integer");
+
+ b.Property("ExpectedDeliveryDate")
+ .HasColumnType("timestamp with time zone");
+
+ b.Property("Fullname")
+ .IsRequired()
+ .HasColumnType("text");
+
+ b.Property>("OrderStatusHistory")
+ .IsRequired()
+ .HasColumnType("text[]");
+
+ b.HasKey("Id");
+
+ b.HasIndex("DestinationCityId");
+
+ b.ToTable("Orders");
+ });
+
+ modelBuilder.Entity("InternetShopOrdersDatabaseImplement.Models.Orders", b =>
+ {
+ b.HasOne("InternetShopOrdersDatabaseImplement.Models.Cities", "DestinationCity")
+ .WithMany()
+ .HasForeignKey("DestinationCityId")
+ .OnDelete(DeleteBehavior.Cascade)
+ .IsRequired();
+
+ b.Navigation("DestinationCity");
+ });
+#pragma warning restore 612, 618
+ }
+ }
+}
diff --git a/KopLab1/InternetShopOrdersDatabaseImplement/Migrations/20241027193729_InitialCreate.cs b/KopLab1/InternetShopOrdersDatabaseImplement/Migrations/20241027193729_InitialCreate.cs
new file mode 100644
index 0000000..7376e11
--- /dev/null
+++ b/KopLab1/InternetShopOrdersDatabaseImplement/Migrations/20241027193729_InitialCreate.cs
@@ -0,0 +1,67 @@
+using System;
+using System.Collections.Generic;
+using Microsoft.EntityFrameworkCore.Migrations;
+using Npgsql.EntityFrameworkCore.PostgreSQL.Metadata;
+
+#nullable disable
+
+namespace InternetShopOrdersDatabaseImplement.Migrations
+{
+ ///
+ public partial class InitialCreate : Migration
+ {
+ ///
+ protected override void Up(MigrationBuilder migrationBuilder)
+ {
+ migrationBuilder.CreateTable(
+ name: "Cities",
+ 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_Cities", x => x.Id);
+ });
+
+ migrationBuilder.CreateTable(
+ name: "Orders",
+ columns: table => new
+ {
+ Id = table.Column(type: "integer", nullable: false)
+ .Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn),
+ Fullname = table.Column(type: "text", nullable: false),
+ OrderStatusHistory = table.Column>(type: "text[]", nullable: false),
+ DestinationCityId = table.Column(type: "integer", nullable: false),
+ ExpectedDeliveryDate = table.Column(type: "timestamp with time zone", nullable: false)
+ },
+ constraints: table =>
+ {
+ table.PrimaryKey("PK_Orders", x => x.Id);
+ table.ForeignKey(
+ name: "FK_Orders_Cities_DestinationCityId",
+ column: x => x.DestinationCityId,
+ principalTable: "Cities",
+ principalColumn: "Id",
+ onDelete: ReferentialAction.Cascade);
+ });
+
+ migrationBuilder.CreateIndex(
+ name: "IX_Orders_DestinationCityId",
+ table: "Orders",
+ column: "DestinationCityId");
+ }
+
+ ///
+ protected override void Down(MigrationBuilder migrationBuilder)
+ {
+ migrationBuilder.DropTable(
+ name: "Orders");
+
+ migrationBuilder.DropTable(
+ name: "Cities");
+ }
+ }
+}
diff --git a/KopLab1/InternetShopOrdersDatabaseImplement/Migrations/OrdersDatabaseModelSnapshot.cs b/KopLab1/InternetShopOrdersDatabaseImplement/Migrations/OrdersDatabaseModelSnapshot.cs
new file mode 100644
index 0000000..ea866f6
--- /dev/null
+++ b/KopLab1/InternetShopOrdersDatabaseImplement/Migrations/OrdersDatabaseModelSnapshot.cs
@@ -0,0 +1,85 @@
+//
+using System;
+using System.Collections.Generic;
+using InternetShopOrdersDatabaseImplement;
+using Microsoft.EntityFrameworkCore;
+using Microsoft.EntityFrameworkCore.Infrastructure;
+using Microsoft.EntityFrameworkCore.Storage.ValueConversion;
+using Npgsql.EntityFrameworkCore.PostgreSQL.Metadata;
+
+#nullable disable
+
+namespace InternetShopOrdersDatabaseImplement.Migrations
+{
+ [DbContext(typeof(OrdersDatabase))]
+ partial class OrdersDatabaseModelSnapshot : ModelSnapshot
+ {
+ protected override void BuildModel(ModelBuilder modelBuilder)
+ {
+#pragma warning disable 612, 618
+ modelBuilder
+ .HasAnnotation("ProductVersion", "8.0.10")
+ .HasAnnotation("Relational:MaxIdentifierLength", 63);
+
+ NpgsqlModelBuilderExtensions.UseIdentityByDefaultColumns(modelBuilder);
+
+ modelBuilder.Entity("InternetShopOrdersDatabaseImplement.Models.Cities", b =>
+ {
+ b.Property("Id")
+ .ValueGeneratedOnAdd()
+ .HasColumnType("integer");
+
+ NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property("Id"));
+
+ b.Property("Name")
+ .IsRequired()
+ .HasColumnType("text");
+
+ b.HasKey("Id");
+
+ b.ToTable("Cities");
+ });
+
+ modelBuilder.Entity("InternetShopOrdersDatabaseImplement.Models.Orders", b =>
+ {
+ b.Property("Id")
+ .ValueGeneratedOnAdd()
+ .HasColumnType("integer");
+
+ NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property("Id"));
+
+ b.Property("DestinationCityId")
+ .HasColumnType("integer");
+
+ b.Property("ExpectedDeliveryDate")
+ .HasColumnType("timestamp with time zone");
+
+ b.Property("Fullname")
+ .IsRequired()
+ .HasColumnType("text");
+
+ b.Property>("OrderStatusHistory")
+ .IsRequired()
+ .HasColumnType("text[]");
+
+ b.HasKey("Id");
+
+ b.HasIndex("DestinationCityId");
+
+ b.ToTable("Orders");
+ });
+
+ modelBuilder.Entity("InternetShopOrdersDatabaseImplement.Models.Orders", b =>
+ {
+ b.HasOne("InternetShopOrdersDatabaseImplement.Models.Cities", "DestinationCity")
+ .WithMany()
+ .HasForeignKey("DestinationCityId")
+ .OnDelete(DeleteBehavior.Cascade)
+ .IsRequired();
+
+ b.Navigation("DestinationCity");
+ });
+#pragma warning restore 612, 618
+ }
+ }
+}
diff --git a/KopLab1/InternetShopOrdersDatabaseImplement/Models/Cities.cs b/KopLab1/InternetShopOrdersDatabaseImplement/Models/Cities.cs
new file mode 100644
index 0000000..ceed1cb
--- /dev/null
+++ b/KopLab1/InternetShopOrdersDatabaseImplement/Models/Cities.cs
@@ -0,0 +1,54 @@
+using InternetShopOrdersContracts.BindingModels;
+using InternetShopOrdersContracts.ViewModels;
+using InternetShopOrdersDataModels.Models;
+
+using System;
+using System.Collections.Generic;
+using System.ComponentModel.DataAnnotations;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace InternetShopOrdersDatabaseImplement.Models
+{
+ public class Cities : ICityModel
+ {
+ public int Id { get; private set; }
+ [Required]
+ public string Name { get; private set; } = string.Empty;
+
+ public static Cities? Create(CityBindingModel? model)
+ {
+ if (model == null)
+ {
+ return null;
+ }
+ return new Cities()
+ {
+ Id = model.Id,
+ Name = model.Name,
+ };
+ }
+ public static Cities? Create(CityViewModel? model)
+ {
+ return new Cities()
+ {
+ Id = model.Id,
+ Name = model.Name,
+ };
+ }
+ public void Update(CityBindingModel? model)
+ {
+ if (model == null)
+ {
+ return;
+ }
+ Name = model.Name;
+ }
+ public CityViewModel GetViewModel => new()
+ {
+ Id = Id,
+ Name = Name,
+ };
+ }
+}
diff --git a/KopLab1/InternetShopOrdersDatabaseImplement/Models/Orders.cs b/KopLab1/InternetShopOrdersDatabaseImplement/Models/Orders.cs
new file mode 100644
index 0000000..f72c0af
--- /dev/null
+++ b/KopLab1/InternetShopOrdersDatabaseImplement/Models/Orders.cs
@@ -0,0 +1,66 @@
+using InternetShopOrdersContracts.BindingModels;
+using InternetShopOrdersContracts.ViewModels;
+using InternetShopOrdersDataModels.Models;
+
+using System;
+using System.Collections.Generic;
+using System.ComponentModel.DataAnnotations;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace InternetShopOrdersDatabaseImplement.Models
+{
+ public class Orders : IOrderModel
+ {
+ [Required]
+ public string Fullname { get; set; } = string.Empty;
+
+ // Метки движения заказа (не более 6)
+ public List OrderStatusHistory { get; set; } = new List();
+
+ public int Id { get; private set; }
+
+ public int DestinationCityId { get; set; }
+ public virtual Cities DestinationCity { get; set; } = new();
+
+ public DateTime ExpectedDeliveryDate { get; set; }
+
+ public static Orders? Create(OrdersDatabase context, OrderBindingModel? model)
+ {
+ if (model == null)
+ {
+ return null;
+ }
+ return new Orders()
+ {
+ Id = model.Id,
+ Fullname = model.Fullname,
+ DestinationCity = context.Cities.First(x => x.Id == model.Id),
+ ExpectedDeliveryDate = model.ExpectedDeliveryDate
+ };
+ }
+
+ public void Update(OrderBindingModel? model, OrdersDatabase context)
+ {
+ if (model == null)
+ {
+ return;
+ }
+ Fullname = model.Fullname;
+ DestinationCity = context.Cities.First(x => x.Id == model.Id);
+ OrderStatusHistory = model.OrderStatusHistory.ToList();
+ ExpectedDeliveryDate = model.ExpectedDeliveryDate;
+ }
+
+ public OrderViewModel GetViewModel => new()
+ {
+ Id = Id,
+ Fullname = Fullname,
+ DestinationCityId = DestinationCity.Id,
+ DestinationCityName = DestinationCity.Name,
+ OrderStatusHistory = OrderStatusHistory,
+ ExpectedDeliveryDate = ExpectedDeliveryDate,
+ };
+ }
+}
\ No newline at end of file
diff --git a/KopLab1/InternetShopOrdersDatabaseImplement/OrdersDatabase.cs b/KopLab1/InternetShopOrdersDatabaseImplement/OrdersDatabase.cs
new file mode 100644
index 0000000..a9f7b51
--- /dev/null
+++ b/KopLab1/InternetShopOrdersDatabaseImplement/OrdersDatabase.cs
@@ -0,0 +1,20 @@
+using InternetShopOrdersDatabaseImplement.Models;
+using Microsoft.EntityFrameworkCore;
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Security.Principal;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace InternetShopOrdersDatabaseImplement
+{
+ public class OrdersDatabase : DbContext
+ {
+ protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
+ => optionsBuilder.UseNpgsql("Host=localhost;Database=InternetShopOrdersDB;Username=postgres;Password=postgres");
+
+ public virtual DbSet Orders { set; get; }
+ public virtual DbSet Cities { set; get; }
+ }
+}
diff --git a/KopLab1/KopLab1.sln b/KopLab1/KopLab1.sln
index 5506f5f..70ce9ee 100644
--- a/KopLab1/KopLab1.sln
+++ b/KopLab1/KopLab1.sln
@@ -3,9 +3,17 @@ Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio Version 17
VisualStudioVersion = 17.11.35222.181
MinimumVisualStudioVersion = 10.0.40219.1
-Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "FormLibrary", "FormLibrary\FormLibrary.csproj", "{E840E4D9-B195-449A-AB24-ECAAE2655D58}"
+Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "FormLibrary", "FormLibrary\FormLibrary.csproj", "{E840E4D9-B195-449A-AB24-ECAAE2655D58}"
EndProject
-Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Forms", "Forms\Forms.csproj", "{83F3C50D-D872-48B6-8932-1D5B7E0A40F0}"
+Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Forms", "Forms\Forms.csproj", "{83F3C50D-D872-48B6-8932-1D5B7E0A40F0}"
+EndProject
+Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "InternetShopOrdersDataModels", "InetShopDataModels\InternetShopOrdersDataModels.csproj", "{FC789ABE-4687-4521-871C-72E1130C6BE6}"
+EndProject
+Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "InternetShopOrdersDatabaseImplement", "InternetShopOrdersDatabaseImplement\InternetShopOrdersDatabaseImplement.csproj", "{AE2BEC62-31AA-4043-B1EC-C4B3F674A4AF}"
+EndProject
+Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "InternetShopOrdersContracts", "InternetShopOrdersContracts\InternetShopOrdersContracts.csproj", "{21E46342-A4FE-437D-BE39-9950919DECDC}"
+EndProject
+Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "InternetShopOrdersBusinessLogic", "InternetShopOrdersBusinessLogic\InternetShopOrdersBusinessLogic.csproj", "{148CAD37-ECDC-4B97-9AD0-1D0990B1B8BE}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
@@ -21,6 +29,22 @@ Global
{83F3C50D-D872-48B6-8932-1D5B7E0A40F0}.Debug|Any CPU.Build.0 = Debug|Any CPU
{83F3C50D-D872-48B6-8932-1D5B7E0A40F0}.Release|Any CPU.ActiveCfg = Release|Any CPU
{83F3C50D-D872-48B6-8932-1D5B7E0A40F0}.Release|Any CPU.Build.0 = Release|Any CPU
+ {FC789ABE-4687-4521-871C-72E1130C6BE6}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
+ {FC789ABE-4687-4521-871C-72E1130C6BE6}.Debug|Any CPU.Build.0 = Debug|Any CPU
+ {FC789ABE-4687-4521-871C-72E1130C6BE6}.Release|Any CPU.ActiveCfg = Release|Any CPU
+ {FC789ABE-4687-4521-871C-72E1130C6BE6}.Release|Any CPU.Build.0 = Release|Any CPU
+ {AE2BEC62-31AA-4043-B1EC-C4B3F674A4AF}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
+ {AE2BEC62-31AA-4043-B1EC-C4B3F674A4AF}.Debug|Any CPU.Build.0 = Debug|Any CPU
+ {AE2BEC62-31AA-4043-B1EC-C4B3F674A4AF}.Release|Any CPU.ActiveCfg = Release|Any CPU
+ {AE2BEC62-31AA-4043-B1EC-C4B3F674A4AF}.Release|Any CPU.Build.0 = Release|Any CPU
+ {21E46342-A4FE-437D-BE39-9950919DECDC}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
+ {21E46342-A4FE-437D-BE39-9950919DECDC}.Debug|Any CPU.Build.0 = Debug|Any CPU
+ {21E46342-A4FE-437D-BE39-9950919DECDC}.Release|Any CPU.ActiveCfg = Release|Any CPU
+ {21E46342-A4FE-437D-BE39-9950919DECDC}.Release|Any CPU.Build.0 = Release|Any CPU
+ {148CAD37-ECDC-4B97-9AD0-1D0990B1B8BE}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
+ {148CAD37-ECDC-4B97-9AD0-1D0990B1B8BE}.Debug|Any CPU.Build.0 = Debug|Any CPU
+ {148CAD37-ECDC-4B97-9AD0-1D0990B1B8BE}.Release|Any CPU.ActiveCfg = Release|Any CPU
+ {148CAD37-ECDC-4B97-9AD0-1D0990B1B8BE}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE