Глобальное промежуточное сохранение.

This commit is contained in:
Programmist73 2023-04-30 12:07:12 +04:00
parent 5fd72c9524
commit c984bc9462
16 changed files with 231 additions and 37 deletions

View File

@ -0,0 +1,33 @@
using BlacksmithWorkshopContracts.DI;
using BlacksmithWorkshopContracts.StoragesContracts;
using BlacksmithWorkshopDatabaseImplement.Implements;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace BlacksmithWorkshopDatabaseImplement
{
public class DataBaseImplementationExtension : IImplementationExtension
{
public int Priority => 2;
public void RegisterServices()
{
DependencyManager.Instance.RegisterType<IClientStorage, ClientStorage>();
DependencyManager.Instance.RegisterType<IWorkPieceStorage, WorkPieceStorage>();
DependencyManager.Instance.RegisterType<IImplementerStorage, ImplementerStorage>();
DependencyManager.Instance.RegisterType<IMessageInfoStorage, MessageInfoStorage>();
DependencyManager.Instance.RegisterType<IOrderStorage, OrderStorage>();
DependencyManager.Instance.RegisterType<IManufactureStorage, ManufactureStorage>();
DependencyManager.Instance.RegisterType<IBackUpInfo, BackUpInfo>();
}
}
}

View File

@ -6,23 +6,29 @@ using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using System.ComponentModel.DataAnnotations.Schema;
using System.Linq;
using System.Runtime.Serialization;
using System.Text;
using System.Threading.Tasks;
namespace BlacksmithWorkshopDatabaseImplement.Models
{
public class Client : IClientModel
[DataContract]
public class Client : IClientModel
{
public int Id { get; set; }
[DataMember]
public int Id { get; set; }
[Required]
[DataMember]
public string ClientFIO { get; set; } = string.Empty;
[Required]
public string ClientFIO { get; set; } = string.Empty;
[DataMember]
public string Email { get; set; } = string.Empty;
[Required]
public string Email { get; set; } = string.Empty;
[Required]
public string Password { get; set; } = string.Empty;
[DataMember]
public string Password { get; set; } = string.Empty;
//для реализации связи многие ко многим с заказами (так как клиенты могу сделать одинаковый заказ)
[ForeignKey("ClientId")]

View File

@ -6,26 +6,33 @@ using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using System.ComponentModel.DataAnnotations.Schema;
using System.Linq;
using System.Runtime.Serialization;
using System.Text;
using System.Threading.Tasks;
namespace BlacksmithWorkshopDatabaseImplement.Models
{
public class Implementer : IImplementerModel
[DataContract]
public class Implementer : IImplementerModel
{
public int Id { get; set; }
[DataMember]
public int Id { get; set; }
[Required]
public string ImplementerFIO { get; set; } = string.Empty;
[DataMember]
public string ImplementerFIO { get; set; } = string.Empty;
[Required]
public string Password { get; set; } = string.Empty;
[DataMember]
public string Password { get; set; } = string.Empty;
[Required]
public int WorkExperience { get; set; }
[DataMember]
public int WorkExperience { get; set; }
[Required]
public int Qualification { get; set; }
[DataMember]
public int Qualification { get; set; }
//для реализации связи один ко многим с заказами
[ForeignKey("ImplementerId")]

View File

@ -7,25 +7,31 @@ using System.ComponentModel;
using System.ComponentModel.DataAnnotations;
using System.ComponentModel.DataAnnotations.Schema;
using System.Linq;
using System.Runtime.Serialization;
using System.Text;
using System.Threading.Tasks;
namespace BlacksmithWorkshopDatabaseImplement.Models
{
[DataContract]
public class Manufacture : IManufactureModel
{
[DataMember]
public int Id { get; set; }
[Required]
[DataMember]
public string ManufactureName { get; set; } = string.Empty;
[Required]
[DataMember]
public double Price { get; set; }
public Dictionary<int, (IWorkPieceModel, int)>? _manufactureWorkPieces = null;
//это поле не будет "мапиться" в бд
[NotMapped]
[DataMember]
public Dictionary<int, (IWorkPieceModel, int)> ManufactureWorkPieces
{
get

View File

@ -2,22 +2,28 @@
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using System.Linq;
using System.Runtime.Serialization;
using System.Text;
using System.Threading.Tasks;
namespace BlacksmithWorkshopDatabaseImplement.Models
{
[DataContract]
public class ManufactureWorkPiece
{
[DataMember]
public int Id { get; set; }
[Required]
[DataMember]
public int ManufactureId { get; set; }
[Required]
[DataMember]
public int WorkPieceId { get; set; }
[Required]
[DataMember]
public int Count { get; set; }
public virtual WorkPiece WorkPiece { get; set; } = new();

View File

@ -5,31 +5,38 @@ using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using System.Linq;
using System.Runtime.Serialization;
using System.Text;
using System.Threading.Tasks;
namespace BlacksmithWorkshopDatabaseImplement.Models
{
[DataContract]
public class MessageInfo : IMessageInfoModel
{
public int Id { get; set; }
[Key]
public string MessageId { get; set; } = string.Empty;
[DataMember]
public string MessageId { get; set; } = string.Empty;
public int? ClientId { get; set; }
[Required]
public string SenderName { get; set; } = string.Empty;
[DataMember]
public string SenderName { get; set; } = string.Empty;
[Required]
public DateTime DateDelivery { get; set; } = DateTime.Now;
[DataMember]
public DateTime DateDelivery { get; set; } = DateTime.Now;
[Required]
public string Subject { get; set; } = string.Empty;
[DataMember]
public string Subject { get; set; } = string.Empty;
[Required]
public string Body { get; set; } = string.Empty;
[DataMember]
public string Body { get; set; } = string.Empty;
public virtual Client? Client { get; set; }

View File

@ -6,36 +6,47 @@ using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using System.Linq;
using System.Runtime.Serialization;
using System.Text;
using System.Threading.Tasks;
using System.Xml.Linq;
namespace BlacksmithWorkshopDatabaseImplement.Models
{
[DataContract]
public class Order : IOrderModel
{
[DataMember]
public int Id { get; private set; }
[Required]
[DataMember]
public int ManufactureId { get; private set; }
[Required]
public int ClientId { get; private set; }
[DataMember]
public int ClientId { get; private set; }
public int? ImplementerId { get; private set; }
[DataMember]
public int? ImplementerId { get; private set; }
[Required]
[DataMember]
public int Count { get; private set; }
[Required]
[DataMember]
public double Sum { get; private set; }
[Required]
[DataMember]
public OrderStatus Status { get; private set; } = OrderStatus.Неизвестен;
[Required]
[DataMember]
public DateTime DateCreate { get; private set; } = DateTime.Now;
[DataMember]
public DateTime? DateImplement { get; private set; }
//для передачи названия изделия

View File

@ -7,19 +7,24 @@ using System.ComponentModel.DataAnnotations;
using System.ComponentModel.DataAnnotations.Schema;
using System.Data;
using System.Linq;
using System.Runtime.Serialization;
using System.Text;
using System.Threading.Tasks;
namespace BlacksmithWorkshopDatabaseImplement.Models
{
[DataContract]
public class WorkPiece : IWorkPieceModel
{
[DataMember]
public int Id { get; private set; }
[Required]
[DataMember]
public string WorkPieceName { get; private set; } = string.Empty;
[Required]
[DataMember]
public double Cost { get; set; }
//для реализации связи многие ко многим с изделиями

View File

@ -0,0 +1,34 @@
using BlacksmithWorkshopContracts.DI;
using BlacksmithWorkshopContracts.StoragesContracts;
using BlacksmithWorkshopFileImplement.Implements;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace BlacksmithWorkshopFileImplement
{
//для реализации нужных нам зависимостей в данном варианте хранения информации
public class FileImplementationExtension : IImplementationExtension
{
public int Priority => 1;
public void RegisterServices()
{
DependencyManager.Instance.RegisterType<IClientStorage, ClientStorage>();
DependencyManager.Instance.RegisterType<IWorkPieceStorage, WorkPieceStorage>();
DependencyManager.Instance.RegisterType<IImplementerStorage, ImplementerStorage>();
DependencyManager.Instance.RegisterType<IMessageInfoStorage, MessageInfoStorage>();
DependencyManager.Instance.RegisterType<IOrderStorage, OrderStorage>();
DependencyManager.Instance.RegisterType<IManufactureStorage, ManufactureStorage>();
DependencyManager.Instance.RegisterType<IBackUpInfo, BackUpInfo>();
}
}
}

View File

@ -0,0 +1,37 @@
using BlacksmithWorkshopContracts.StoragesContracts;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace BlacksmithWorkshopFileImplement.Implements
{
public class BackUpInfo : IBackUpInfo
{
public List<T>? GetList<T>() where T : class, new()
{
var source = DataFileSingleton.GetInstance();
return (List<T>?)source.GetType().GetProperties()
.FirstOrDefault(x => x.PropertyType.IsGenericType && x.PropertyType.GetGenericArguments()[0] == typeof(T))
?.GetValue(source);
}
public Type? GetTypeByModelInterface(string modelInterfaceName)
{
var assembly = typeof(BackUpInfo).Assembly;
var types = assembly.GetTypes();
foreach (var type in types)
{
if (type.IsClass && type.GetInterface(modelInterfaceName) != null)
{
return type;
}
}
return null;
}
}
}

View File

@ -7,21 +7,27 @@ using System.Collections.Generic;
using System.Data;
using System.Linq;
using System.Reflection;
using System.Runtime.Serialization;
using System.Text;
using System.Threading.Tasks;
using System.Xml.Linq;
namespace BlacksmithWorkshopFileImplement.Models
{
[DataContract]
public class Client : IClientModel
{
[DataMember]
public int Id { get; private set; }
public string ClientFIO { get; private set; } = string.Empty;
[DataMember]
public string ClientFIO { get; private set; } = string.Empty;
public string Email { get; private set; } = string.Empty;
[DataMember]
public string Email { get; private set; } = string.Empty;
public string Password { get; private set; } = string.Empty;
[DataMember]
public string Password { get; private set; } = string.Empty;
public static Client? Create(ClientBindingModel model)
{

View File

@ -5,23 +5,30 @@ using System;
using System.Collections.Generic;
using System.Linq;
using System.Reflection;
using System.Runtime.Serialization;
using System.Text;
using System.Threading.Tasks;
using System.Xml.Linq;
namespace BlacksmithWorkshopFileImplement.Models
{
[DataContract]
public class Implementer : IImplementerModel
{
public int Id { get; private set; }
[DataMember]
public int Id { get; private set; }
public string ImplementerFIO { get; private set; } = string.Empty;
[DataMember]
public string ImplementerFIO { get; private set; } = string.Empty;
public string Password { get; private set; } = string.Empty;
[DataMember]
public string Password { get; private set; } = string.Empty;
public int WorkExperience { get; private set; }
[DataMember]
public int WorkExperience { get; private set; }
public int Qualification { get; private set; }
[DataMember]
public int Qualification { get; private set; }
public static Implementer? Create(ImplementerBindingModel model)
{

View File

@ -4,6 +4,7 @@ using BlacksmithWorkshopDataModels.Models;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.Serialization;
using System.Text;
using System.Threading.Tasks;
using System.Xml.Linq;
@ -11,19 +12,23 @@ using System.Xml.Linq;
namespace BlacksmithWorkshopFileImplement.Models
{
//класс реализующий интерфейс модели изделия
[DataContract]
public class Manufacture : IManufactureModel
{
[DataMember]
public int Id { get; private set; }
[DataMember]
public string ManufactureName { get; private set; } = string.Empty;
[DataMember]
public double Price { get; private set; }
public Dictionary<int, int> WorkPieces { get; private set; } = new();
private Dictionary<int, (IWorkPieceModel, int)>? _manufactureWorkPieces = null;
[DataMember]
public Dictionary<int, (IWorkPieceModel, int)> ManufactureWorkPieces
{
get

View File

@ -6,27 +6,35 @@ using System.Collections.Generic;
using System.Linq;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Serialization;
using System.Text;
using System.Threading.Tasks;
using System.Xml.Linq;
namespace BlacksmithWorkshopFileImplement.Models
{
[DataContract]
public class MessageInfo : IMessageInfoModel
{
public int Id { get; private set; }
[DataMember]
public string MessageId { get; private set; } = string.Empty;
public int? ClientId { get; private set; }
[DataMember]
public int? ClientId { get; private set; }
public string SenderName { get; private set; } = string.Empty;
[DataMember]
public string SenderName { get; private set; } = string.Empty;
public DateTime DateDelivery { get; private set; } = DateTime.Now;
[DataMember]
public DateTime DateDelivery { get; private set; } = DateTime.Now;
public string Subject { get; private set; } = string.Empty;
[DataMember]
public string Subject { get; private set; } = string.Empty;
public string Body { get; private set; } = string.Empty;
[DataMember]
public string Body { get; private set; } = string.Empty;
public static MessageInfo? Create(MessageInfoBindingModel model)
{

View File

@ -6,6 +6,7 @@ using System;
using System.Collections.Generic;
using System.Linq;
using System.Reflection;
using System.Runtime.Serialization;
using System.Text;
using System.Threading.Tasks;
using System.Xml.Linq;
@ -13,24 +14,34 @@ using System.Xml.Linq;
namespace BlacksmithWorkshopFileImplement.Models
{
//класс, реализующий интерфейс модели заказа
[DataContract]
public class Order : IOrderModel
{
[DataMember]
public int Id { get; private set; }
public int ClientId { get; private set; }
[DataMember]
public int ClientId { get; private set; }
public int? ImplementerId { get; private set; }
[DataMember]
public int? ImplementerId { get; private set; }
public int ManufactureId { get; private set; }
[DataMember]
public int ManufactureId { get; private set; }
[DataMember]
public int Count { get; private set; }
[DataMember]
public double Sum { get; private set; }
[DataMember]
public OrderStatus Status { get; private set; } = OrderStatus.Неизвестен;
[DataMember]
public DateTime DateCreate { get; private set; } = DateTime.Now;
[DataMember]
public DateTime? DateImplement { get; private set; }
public static Order? Create(OrderBindingModel model)

View File

@ -5,6 +5,7 @@ using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Linq;
using System.Runtime.Serialization;
using System.Text;
using System.Threading.Tasks;
using System.Xml.Linq;
@ -12,12 +13,16 @@ using System.Xml.Linq;
namespace BlacksmithWorkshopFileImplement.Models
{
//реализация интерфейса модели заготовки
[DataContract]
public class WorkPiece : IWorkPieceModel
{
[DataMember]
public int Id { get; private set; }
[DataMember]
public string WorkPieceName { get; private set; } = string.Empty;
[DataMember]
public double Cost { get; set; }
public static WorkPiece? Create(WorkPieceBindingModel model)