Бд, логика done, надеюсь работает)))
This commit is contained in:
parent
989d867eda
commit
1bf465766d
@ -8,8 +8,17 @@
|
||||
<ImplicitUsings>enable</ImplicitUsings>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="Microsoft.EntityFrameworkCore" Version="8.0.10" />
|
||||
<PackageReference Include="Microsoft.EntityFrameworkCore.Design" Version="8.0.10">
|
||||
<PrivateAssets>all</PrivateAssets>
|
||||
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
|
||||
</PackageReference>
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\FormLibrary\FormLibrary.csproj" />
|
||||
<ProjectReference Include="..\InternetShopOrdersDatabaseImplement\InternetShopOrdersDatabaseImplement.csproj" />
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
7
KopLab1/InetShopDataModels/IId.cs
Normal file
7
KopLab1/InetShopDataModels/IId.cs
Normal file
@ -0,0 +1,7 @@
|
||||
namespace InternetShopOrdersDataModels
|
||||
{
|
||||
public interface IId
|
||||
{
|
||||
int Id { get; }
|
||||
}
|
||||
}
|
@ -0,0 +1,9 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
|
||||
<PropertyGroup>
|
||||
<TargetFramework>net8.0</TargetFramework>
|
||||
<ImplicitUsings>enable</ImplicitUsings>
|
||||
<Nullable>enable</Nullable>
|
||||
</PropertyGroup>
|
||||
|
||||
</Project>
|
13
KopLab1/InetShopDataModels/Models/ICityModel.cs
Normal file
13
KopLab1/InetShopDataModels/Models/ICityModel.cs
Normal file
@ -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; }
|
||||
}
|
||||
}
|
23
KopLab1/InetShopDataModels/Models/IOrderModel.cs
Normal file
23
KopLab1/InetShopDataModels/Models/IOrderModel.cs
Normal file
@ -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<string> OrderStatusHistory { get; }
|
||||
|
||||
// Город назначения
|
||||
int DestinationCityId { get; }
|
||||
|
||||
// Дата получения заказа
|
||||
DateTime ExpectedDeliveryDate { get; }
|
||||
}
|
||||
}
|
@ -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<CityViewModel>? 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));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@ -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<OrderViewModel>? 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));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,15 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
|
||||
<PropertyGroup>
|
||||
<TargetFramework>net8.0</TargetFramework>
|
||||
<ImplicitUsings>enable</ImplicitUsings>
|
||||
<Nullable>enable</Nullable>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\InetShopDataModels\InternetShopOrdersDataModels.csproj" />
|
||||
<ProjectReference Include="..\InternetShopOrdersContracts\InternetShopOrdersContracts.csproj" />
|
||||
<ProjectReference Include="..\InternetShopOrdersDatabaseImplement\InternetShopOrdersDatabaseImplement.csproj" />
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
@ -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;
|
||||
}
|
||||
}
|
@ -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<string> OrderStatusHistory { get; set; } = new List<string>();
|
||||
public int DestinationCityId { get; set; }
|
||||
public ICityModel DestinationCity { get; set; }
|
||||
public DateTime ExpectedDeliveryDate { get; set; }
|
||||
}
|
||||
}
|
@ -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<CityViewModel>? ReadList(CitySearchModel? model);
|
||||
CityViewModel? ReadElement(CitySearchModel model);
|
||||
bool Create(CityBindingModel model);
|
||||
bool Update(CityBindingModel model);
|
||||
bool Delete(CityBindingModel model);
|
||||
}
|
||||
}
|
@ -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<OrderViewModel>? ReadList(OrderSearchModel? model);
|
||||
OrderViewModel? ReadElement(OrderSearchModel model);
|
||||
bool Create(OrderBindingModel model);
|
||||
bool Update(OrderBindingModel model);
|
||||
bool Delete(OrderBindingModel model);
|
||||
}
|
||||
}
|
@ -0,0 +1,13 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
|
||||
<PropertyGroup>
|
||||
<TargetFramework>net8.0</TargetFramework>
|
||||
<ImplicitUsings>enable</ImplicitUsings>
|
||||
<Nullable>enable</Nullable>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\InetShopDataModels\InternetShopOrdersDataModels.csproj" />
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
@ -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; }
|
||||
}
|
||||
}
|
@ -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; }
|
||||
}
|
||||
}
|
@ -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<CityViewModel> GetFullList();
|
||||
List<CityViewModel> GetFilteredList(CitySearchModel model);
|
||||
CityViewModel? GetElement(CitySearchModel model);
|
||||
CityViewModel? Insert(CityBindingModel model);
|
||||
CityViewModel? Update(CityBindingModel model);
|
||||
CityViewModel? Delete(CityBindingModel model);
|
||||
}
|
||||
}
|
@ -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<OrderViewModel> GetFullList();
|
||||
List<OrderViewModel> GetFilteredList(OrderSearchModel model);
|
||||
OrderViewModel? GetElement(OrderSearchModel model);
|
||||
OrderViewModel? Insert(OrderBindingModel model);
|
||||
OrderViewModel? Update(OrderBindingModel model);
|
||||
OrderViewModel? Delete(OrderBindingModel model);
|
||||
}
|
||||
}
|
@ -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;
|
||||
}
|
||||
}
|
@ -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<string> OrderStatusHistory { get; set; }
|
||||
|
||||
public int DestinationCityId { get; set; }
|
||||
[DisplayName("Город назначения")]
|
||||
public string DestinationCityName { get; set; }
|
||||
|
||||
[DisplayName("Дата получения заказа")]
|
||||
public DateTime ExpectedDeliveryDate { get; set; }
|
||||
}
|
||||
}
|
@ -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<CityViewModel> GetFullList()
|
||||
{
|
||||
using var context = new OrdersDatabase();
|
||||
return context.Cities
|
||||
.Select(x => x.GetViewModel)
|
||||
.ToList();
|
||||
}
|
||||
public List<CityViewModel> 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;
|
||||
}
|
||||
}
|
||||
}
|
@ -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<OrderViewModel> GetFullList()
|
||||
{
|
||||
using var context = new OrdersDatabase();
|
||||
return context.Orders
|
||||
.Include(x => x.DestinationCity)
|
||||
.Select(x => x.GetViewModel)
|
||||
.ToList();
|
||||
}
|
||||
public List<OrderViewModel> 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;
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,23 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
|
||||
<PropertyGroup>
|
||||
<TargetFramework>net8.0</TargetFramework>
|
||||
<ImplicitUsings>enable</ImplicitUsings>
|
||||
<Nullable>enable</Nullable>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="Microsoft.EntityFrameworkCore" Version="8.0.10" />
|
||||
<PackageReference Include="Microsoft.EntityFrameworkCore.Tools" Version="8.0.10">
|
||||
<PrivateAssets>all</PrivateAssets>
|
||||
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
|
||||
</PackageReference>
|
||||
<PackageReference Include="Npgsql.EntityFrameworkCore.PostgreSQL" Version="8.0.8" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\InetShopDataModels\InternetShopOrdersDataModels.csproj" />
|
||||
<ProjectReference Include="..\InternetShopOrdersContracts\InternetShopOrdersContracts.csproj" />
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
88
KopLab1/InternetShopOrdersDatabaseImplement/Migrations/20241027193729_InitialCreate.Designer.cs
generated
Normal file
88
KopLab1/InternetShopOrdersDatabaseImplement/Migrations/20241027193729_InitialCreate.Designer.cs
generated
Normal file
@ -0,0 +1,88 @@
|
||||
// <auto-generated />
|
||||
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
|
||||
{
|
||||
/// <inheritdoc />
|
||||
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<int>("Id")
|
||||
.ValueGeneratedOnAdd()
|
||||
.HasColumnType("integer");
|
||||
|
||||
NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property<int>("Id"));
|
||||
|
||||
b.Property<string>("Name")
|
||||
.IsRequired()
|
||||
.HasColumnType("text");
|
||||
|
||||
b.HasKey("Id");
|
||||
|
||||
b.ToTable("Cities");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("InternetShopOrdersDatabaseImplement.Models.Orders", b =>
|
||||
{
|
||||
b.Property<int>("Id")
|
||||
.ValueGeneratedOnAdd()
|
||||
.HasColumnType("integer");
|
||||
|
||||
NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property<int>("Id"));
|
||||
|
||||
b.Property<int>("DestinationCityId")
|
||||
.HasColumnType("integer");
|
||||
|
||||
b.Property<DateTime>("ExpectedDeliveryDate")
|
||||
.HasColumnType("timestamp with time zone");
|
||||
|
||||
b.Property<string>("Fullname")
|
||||
.IsRequired()
|
||||
.HasColumnType("text");
|
||||
|
||||
b.Property<List<string>>("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
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,67 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using Microsoft.EntityFrameworkCore.Migrations;
|
||||
using Npgsql.EntityFrameworkCore.PostgreSQL.Metadata;
|
||||
|
||||
#nullable disable
|
||||
|
||||
namespace InternetShopOrdersDatabaseImplement.Migrations
|
||||
{
|
||||
/// <inheritdoc />
|
||||
public partial class InitialCreate : Migration
|
||||
{
|
||||
/// <inheritdoc />
|
||||
protected override void Up(MigrationBuilder migrationBuilder)
|
||||
{
|
||||
migrationBuilder.CreateTable(
|
||||
name: "Cities",
|
||||
columns: table => new
|
||||
{
|
||||
Id = table.Column<int>(type: "integer", nullable: false)
|
||||
.Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn),
|
||||
Name = table.Column<string>(type: "text", nullable: false)
|
||||
},
|
||||
constraints: table =>
|
||||
{
|
||||
table.PrimaryKey("PK_Cities", x => x.Id);
|
||||
});
|
||||
|
||||
migrationBuilder.CreateTable(
|
||||
name: "Orders",
|
||||
columns: table => new
|
||||
{
|
||||
Id = table.Column<int>(type: "integer", nullable: false)
|
||||
.Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn),
|
||||
Fullname = table.Column<string>(type: "text", nullable: false),
|
||||
OrderStatusHistory = table.Column<List<string>>(type: "text[]", nullable: false),
|
||||
DestinationCityId = table.Column<int>(type: "integer", nullable: false),
|
||||
ExpectedDeliveryDate = table.Column<DateTime>(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");
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
protected override void Down(MigrationBuilder migrationBuilder)
|
||||
{
|
||||
migrationBuilder.DropTable(
|
||||
name: "Orders");
|
||||
|
||||
migrationBuilder.DropTable(
|
||||
name: "Cities");
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,85 @@
|
||||
// <auto-generated />
|
||||
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<int>("Id")
|
||||
.ValueGeneratedOnAdd()
|
||||
.HasColumnType("integer");
|
||||
|
||||
NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property<int>("Id"));
|
||||
|
||||
b.Property<string>("Name")
|
||||
.IsRequired()
|
||||
.HasColumnType("text");
|
||||
|
||||
b.HasKey("Id");
|
||||
|
||||
b.ToTable("Cities");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("InternetShopOrdersDatabaseImplement.Models.Orders", b =>
|
||||
{
|
||||
b.Property<int>("Id")
|
||||
.ValueGeneratedOnAdd()
|
||||
.HasColumnType("integer");
|
||||
|
||||
NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property<int>("Id"));
|
||||
|
||||
b.Property<int>("DestinationCityId")
|
||||
.HasColumnType("integer");
|
||||
|
||||
b.Property<DateTime>("ExpectedDeliveryDate")
|
||||
.HasColumnType("timestamp with time zone");
|
||||
|
||||
b.Property<string>("Fullname")
|
||||
.IsRequired()
|
||||
.HasColumnType("text");
|
||||
|
||||
b.Property<List<string>>("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
|
||||
}
|
||||
}
|
||||
}
|
54
KopLab1/InternetShopOrdersDatabaseImplement/Models/Cities.cs
Normal file
54
KopLab1/InternetShopOrdersDatabaseImplement/Models/Cities.cs
Normal file
@ -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,
|
||||
};
|
||||
}
|
||||
}
|
66
KopLab1/InternetShopOrdersDatabaseImplement/Models/Orders.cs
Normal file
66
KopLab1/InternetShopOrdersDatabaseImplement/Models/Orders.cs
Normal file
@ -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<string> OrderStatusHistory { get; set; } = new List<string>();
|
||||
|
||||
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,
|
||||
};
|
||||
}
|
||||
}
|
@ -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> Orders { set; get; }
|
||||
public virtual DbSet<Cities> Cities { set; get; }
|
||||
}
|
||||
}
|
@ -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
|
||||
|
Loading…
Reference in New Issue
Block a user