добавлены DataContract и DataMember

This commit is contained in:
Ino 2023-04-12 11:59:00 +04:00
parent 5eea91c76d
commit 5b8087029b
21 changed files with 312 additions and 100 deletions

View File

@ -0,0 +1,22 @@
using IceCreamShopContracts.DI;
using IceCreamShopContracts.StoragesContracts;
using IceCreamShopDatabaseImplement.Implements;
namespace IceCreamShopDatabaseImplement
{
public class DatabaseImplementationExtension : IImplementationExtension
{
public int Priority => 2;
public void RegisterServices()
{
DependencyManager.Instance.RegisterType<IClientStorage, ClientStorage>();
DependencyManager.Instance.RegisterType<IComponentStorage, ComponentStorage>();
DependencyManager.Instance.RegisterType<IImplementerStorage, ImplementerStorage>();
DependencyManager.Instance.RegisterType<IMessageInfoStorage, MessageInfoStorage>();
DependencyManager.Instance.RegisterType<IOrderStorage, OrderStorage>();
DependencyManager.Instance.RegisterType<IIceCreamStorage, IceCreamStorage>();
DependencyManager.Instance.RegisterType<IBackUpInfo, BackUpInfo>();
}
}
}

View File

@ -3,21 +3,27 @@ using IceCreamShopContracts.ViewModels;
using AbstractIceCreamShopDataModels.Models; using AbstractIceCreamShopDataModels.Models;
using System.ComponentModel.DataAnnotations; using System.ComponentModel.DataAnnotations;
using System.ComponentModel.DataAnnotations.Schema; using System.ComponentModel.DataAnnotations.Schema;
using System.Runtime.Serialization;
namespace IceCreamShopDatabaseImplement.Models namespace IceCreamShopDatabaseImplement.Models
{ {
public class Client : IClientModel [DataContract]
public class Client : IClientModel
{ {
[Required] [Required]
public string ClientFIO { get; private set; } = string.Empty; [DataMember]
public string ClientFIO { get; private set; } = string.Empty;
[Required] [Required]
public string Email { get; private set; } = string.Empty; [DataMember]
public string Email { get; private set; } = string.Empty;
[Required] [Required]
public string Password { get; private set; } = string.Empty; [DataMember]
public string Password { get; private set; } = string.Empty;
public int Id { get; private set; } [DataMember]
public int Id { get; private set; }
[ForeignKey("ClientId")] [ForeignKey("ClientId")]
public virtual List<Order> Orders { get; set; } = new(); public virtual List<Order> Orders { get; set; } = new();

View File

@ -3,19 +3,23 @@ using System.ComponentModel.DataAnnotations;
using IceCreamShopContracts.BindingModels; using IceCreamShopContracts.BindingModels;
using IceCreamShopContracts.ViewModels; using IceCreamShopContracts.ViewModels;
using AbstractIceCreamShopDataModels.Models; using AbstractIceCreamShopDataModels.Models;
using System.Runtime.Serialization;
namespace IceCreamShopDatabaseImplement.Models namespace IceCreamShopDatabaseImplement.Models
{ {
public class Component : IComponentModel [DataContract]
public class Component : IComponentModel
{ {
public int Id { get; private set; } [DataMember]
public int Id { get; private set; }
[Required] [Required]
public string ComponentName { get; private set; } = string.Empty; [DataMember]
public string ComponentName { get; private set; } = string.Empty;
[Required] [Required]
public double Cost { get; set; } [DataMember]
public double Cost { get; set; }
[ForeignKey("ComponentId")] [ForeignKey("ComponentId")]
public virtual List<IceCreamComponent> IceCreamComponents { get; set; } = new(); public virtual List<IceCreamComponent> IceCreamComponents { get; set; } = new();

View File

@ -3,23 +3,29 @@ using IceCreamShopContracts.BindingModels;
using IceCreamShopContracts.ViewModels; using IceCreamShopContracts.ViewModels;
using System.ComponentModel.DataAnnotations; using System.ComponentModel.DataAnnotations;
using System.ComponentModel.DataAnnotations.Schema; using System.ComponentModel.DataAnnotations.Schema;
using System.Runtime.Serialization;
namespace IceCreamShopDatabaseImplement.Models namespace IceCreamShopDatabaseImplement.Models
{ {
public class IceCream : IIceCreamModel [DataContract]
public class IceCream : IIceCreamModel
{ {
public int Id { get; set; } [DataMember]
public int Id { get; set; }
[Required] [Required]
public string IceCreamName { get; set; } = string.Empty; [DataMember]
public string IceCreamName { get; set; } = string.Empty;
[Required] [Required]
public double Price { get; set; } [DataMember]
public double Price { get; set; }
private Dictionary<int, (IComponentModel, int)>? _iceCreamComponents = null; private Dictionary<int, (IComponentModel, int)>? _iceCreamComponents = null;
[NotMapped] [NotMapped]
public Dictionary<int, (IComponentModel, int)> IceCreamComponents [DataMember]
public Dictionary<int, (IComponentModel, int)> IceCreamComponents
{ {
get get
{ {

View File

@ -2,20 +2,27 @@
using IceCreamShopContracts.BindingModels; using IceCreamShopContracts.BindingModels;
using IceCreamShopContracts.ViewModels; using IceCreamShopContracts.ViewModels;
using System.ComponentModel.DataAnnotations.Schema; using System.ComponentModel.DataAnnotations.Schema;
using System.Runtime.Serialization;
namespace IceCreamShopDatabaseImplement.Models namespace IceCreamShopDatabaseImplement.Models
{ {
public class Implementer : IImplementerModel [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; }
[ForeignKey("ImplementerId")] [ForeignKey("ImplementerId")]
public virtual List<Order> Orders { get; private set; } = new(); public virtual List<Order> Orders { get; private set; } = new();

View File

@ -2,13 +2,16 @@
using IceCreamShopContracts.BindingModels; using IceCreamShopContracts.BindingModels;
using IceCreamShopContracts.ViewModels; using IceCreamShopContracts.ViewModels;
using System.ComponentModel.DataAnnotations; using System.ComponentModel.DataAnnotations;
using System.Runtime.Serialization;
namespace IceCreamShopDatabaseImplement.Models namespace IceCreamShopDatabaseImplement.Models
{ {
public class MessageInfo : IMessageInfoModel [DataContract]
public class MessageInfo : IMessageInfoModel
{ {
[Key] [Key]
public string MessageId { get; private set; } = string.Empty; [DataMember]
public string MessageId { get; private set; } = string.Empty;
public int? ClientId { get; private set; } public int? ClientId { get; private set; }

View File

@ -4,28 +4,45 @@ using IceCreamShopContracts.BindingModels;
using IceCreamShopContracts.ViewModels; using IceCreamShopContracts.ViewModels;
using System.ComponentModel.DataAnnotations; using System.ComponentModel.DataAnnotations;
using System.Reflection.Metadata; using System.Reflection.Metadata;
using System.Runtime.Serialization;
namespace IceCreamShopDatabaseImplement.Models namespace IceCreamShopDatabaseImplement.Models
{ {
public class Order : IOrderModel [DataContract]
public class Order : IOrderModel
{ {
[Required] [Required]
public int IceCreamId { get; set; } [DataMember]
[Required] public int IceCreamId { get; private set; }
public int ClientId { get; private set; }
public int? ImplementerId { get; private set; }
[Required]
public int Count { get; set; }
[Required]
public double Sum { get; set; }
[Required]
public OrderStatus Status { get; set; }
[Required]
public DateTime DateCreate { get; set; }
public DateTime? DateImplement { get; set; } [Required]
[DataMember]
public int ClientId { get; private set; }
public int Id { get; 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; }
[Required]
[DataMember]
public DateTime DateCreate { get; private set; }
[DataMember]
public DateTime? DateImplement { get; private set; }
[DataMember]
public int Id { get; set; }
public virtual IceCream IceCream{ get; private set; } public virtual IceCream IceCream{ get; private set; }
public virtual Client Client { get; private set; } public virtual Client Client { get; private set; }
public Implementer? Implementer { get; private set; } public Implementer? Implementer { get; private set; }

View File

@ -0,0 +1,22 @@
using IceCreamShopContracts.DI;
using IceCreamShopContracts.StoragesContracts;
using IceCreamShopFileImplement.Implements;
namespace IceCreamShopFileImplement
{
public class FileImplementationExtension : IImplementationExtension
{
public int Priority => 1;
public void RegisterServices()
{
DependencyManager.Instance.RegisterType<IClientStorage, ClientStorage>();
DependencyManager.Instance.RegisterType<IComponentStorage, ComponentStorage>();
DependencyManager.Instance.RegisterType<IImplementerStorage, ImplementerStorage>();
DependencyManager.Instance.RegisterType<IMessageInfoStorage, MessageInfoStorage>();
DependencyManager.Instance.RegisterType<IOrderStorage, OrderStorage>();
DependencyManager.Instance.RegisterType<IIceCreamStorage, IceCreamStorage>();
DependencyManager.Instance.RegisterType<IBackUpInfo, BackUpInfo>();
}
}
}

View File

@ -0,0 +1,29 @@
using IceCreamShopContracts.StoragesContracts;
namespace IceCreamShopFileImplement.Implements
{
public class BackUpInfo : IBackUpInfo
{
public List<T>? GetList<T>() where T : class, new()
{
// Получаем значения из singleton-объекта универсального свойства содержащее тип T
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

@ -2,18 +2,24 @@
using IceCreamShopContracts.ViewModels; using IceCreamShopContracts.ViewModels;
using AbstractIceCreamShopDataModels.Models; using AbstractIceCreamShopDataModels.Models;
using System.Xml.Linq; using System.Xml.Linq;
using System.Runtime.Serialization;
namespace IceCreamShopFileImplement.Models namespace IceCreamShopFileImplement.Models
{ {
public class Client : IClientModel [DataContract]
public class Client : IClientModel
{ {
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 int Id { get; private set; } [DataMember]
public int Id { get; private set; }
public static Client? Create(ClientBindingModel model) public static Client? Create(ClientBindingModel model)
{ {

View File

@ -7,14 +7,21 @@ using System.Linq;
using System.Text; using System.Text;
using System.Threading.Tasks; using System.Threading.Tasks;
using System.Xml.Linq; using System.Xml.Linq;
using System.Runtime.Serialization;
namespace IceCreamShopFileImplement.Models namespace IceCreamShopFileImplement.Models
{ {
public class Component : IComponentModel [DataContract]
public class Component : IComponentModel
{ {
public int Id { get; private set; } [DataMember]
public string ComponentName { get; private set; } = string.Empty; public int Id { get; private set; }
public double Cost { get; set; }
[DataMember]
public string ComponentName { get; private set; } = string.Empty;
[DataMember]
public double Cost { get; set; }
public static Component? Create(ComponentBindingModel model) public static Component? Create(ComponentBindingModel model)
{ {
if (model == null) if (model == null)

View File

@ -7,17 +7,26 @@ using System.Linq;
using System.Text; using System.Text;
using System.Threading.Tasks; using System.Threading.Tasks;
using System.Xml.Linq; using System.Xml.Linq;
using System.Runtime.Serialization;
namespace IceCreamShopFileImplement.Models namespace IceCreamShopFileImplement.Models
{ {
public class IceCream : IIceCreamModel [DataContract]
public class IceCream : IIceCreamModel
{ {
public int Id { get; private set; } [DataMember]
public string IceCreamName { get; private set; } = string.Empty; public int Id { get; private set; }
public double Price { get; private set; }
[DataMember]
public string IceCreamName { get; private set; } = string.Empty;
[DataMember]
public double Price { get; private set; }
public Dictionary<int, int> Components { get; private set; } = new(); public Dictionary<int, int> Components { get; private set; } = new();
private Dictionary<int, (IComponentModel, int)>? _iceCreamComponents = null; private Dictionary<int, (IComponentModel, int)>? _iceCreamComponents = null;
public Dictionary<int, (IComponentModel, int)> IceCreamComponents
[DataMember]
public Dictionary<int, (IComponentModel, int)> IceCreamComponents
{ {
get get
{ {

View File

@ -2,19 +2,26 @@
using IceCreamShopContracts.ViewModels; using IceCreamShopContracts.ViewModels;
using AbstractIceCreamShopDataModels.Models; using AbstractIceCreamShopDataModels.Models;
using System.Xml.Linq; using System.Xml.Linq;
using System.Runtime.Serialization;
namespace IceCreamShopFileImplement.Models namespace IceCreamShopFileImplement.Models
{ {
[DataContract]
public class Implementer : IImplementerModel public class Implementer : IImplementerModel
{ {
[DataMember]
public int Id { get; private set; } public int Id { get; private set; }
[DataMember]
public string ImplementerFIO { get; private set; } = string.Empty; public string ImplementerFIO { get; private set; } = string.Empty;
[DataMember]
public string Password { get; private set; } = string.Empty; public string Password { get; private set; } = string.Empty;
[DataMember]
public int WorkExperience { get; private set; } public int WorkExperience { get; private set; }
[DataMember]
public int Qualification { get; private set; } public int Qualification { get; private set; }
public static Implementer? Create(XElement element) public static Implementer? Create(XElement element)

View File

@ -1,23 +1,31 @@
using AbstractIceCreamShopDataModels.Models; using AbstractIceCreamShopDataModels.Models;
using IceCreamShopContracts.BindingModels; using IceCreamShopContracts.BindingModels;
using IceCreamShopContracts.ViewModels; using IceCreamShopContracts.ViewModels;
using System.Runtime.Serialization;
using System.Xml.Linq; using System.Xml.Linq;
namespace IceCreamShopFileImplement.Models namespace IceCreamShopFileImplement.Models
{ {
public class MessageInfo : IMessageInfoModel [DataContract]
public class MessageInfo : IMessageInfoModel
{ {
public string MessageId { get; private set; } = string.Empty; [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) public static MessageInfo? Create(MessageInfoBindingModel model)
{ {

View File

@ -9,28 +9,39 @@ using System.Threading.Tasks;
using AbstractIceCreamShopDataModels.Enums; using AbstractIceCreamShopDataModels.Enums;
using System.Xml.Linq; using System.Xml.Linq;
using System.Reflection.Metadata; using System.Reflection.Metadata;
using System.Runtime.Serialization;
namespace IceCreamShopFileImplement.Models namespace IceCreamShopFileImplement.Models
{ {
public class Order : IOrderModel [DataContract]
public class Order : IOrderModel
{ {
public int Id { get; private set; } [DataMember]
public int Id { get; private set; }
public int IceCreamId { get; private set; } [DataMember]
public int IceCreamId { get; private set; }
public int? ImplementerId { get; set; } [DataMember]
public int? ImplementerId { get; set; }
public int ClientId { get; set; } [DataMember]
public int ClientId { get; set; }
public int Count { get; private set; } [DataMember]
public int Count { get; private set; }
public double Sum { get; private set; } [DataMember]
public double Sum { get; private set; }
public OrderStatus Status { get; private set; } = OrderStatus.Неизвестен; [DataMember]
public OrderStatus Status { get; private set; } = OrderStatus.Неизвестен;
public DateTime DateCreate { get; private set; } = DateTime.Now; [DataMember]
public DateTime DateCreate { get; private set; } = DateTime.Now;
public DateTime? DateImplement { get; private set; } [DataMember]
public DateTime? DateImplement { get; private set; }
public static Order? Create(OrderBindingModel? model) public static Order? Create(OrderBindingModel? model)
{ {
if (model == null) if (model == null)

View File

@ -1,18 +1,24 @@
using IceCreamShopContracts.BindingModels; using IceCreamShopContracts.BindingModels;
using IceCreamShopContracts.ViewModels; using IceCreamShopContracts.ViewModels;
using AbstractIceCreamShopDataModels.Models; using AbstractIceCreamShopDataModels.Models;
using System.Runtime.Serialization;
namespace IceCreamShopListImplement.Models namespace IceCreamShopListImplement.Models
{ {
public class Client : IClientModel [DataContract]
public class Client : IClientModel
{ {
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 int Id { get; private set; } [DataMember]
public int Id { get; private set; }
public static Client? Create(ClientBindingModel model) public static Client? Create(ClientBindingModel model)
{ {

View File

@ -6,14 +6,21 @@ using System.Threading.Tasks;
using IceCreamShopContracts.BindingModels; using IceCreamShopContracts.BindingModels;
using IceCreamShopContracts.ViewModels; using IceCreamShopContracts.ViewModels;
using AbstractIceCreamShopDataModels.Models; using AbstractIceCreamShopDataModels.Models;
using System.Runtime.Serialization;
namespace IceCreamShopListImplement.Models namespace IceCreamShopListImplement.Models
{ {
public class Component : IComponentModel [DataContract]
public class Component : IComponentModel
{ {
public int Id { get; private set; } [DataMember]
public string ComponentName { get; private set; } = string.Empty; public int Id { get; private set; }
public double Cost { get; set; }
[DataMember]
public string ComponentName { get; private set; } = string.Empty;
[DataMember]
public double Cost { get; set; }
public static Component? Create(ComponentBindingModel? model) public static Component? Create(ComponentBindingModel? model)
{ {
if (model == null) if (model == null)

View File

@ -4,18 +4,27 @@ using IceCreamShopContracts.ViewModels;
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Linq; using System.Linq;
using System.Runtime.Serialization;
using System.Text; using System.Text;
using System.Threading.Tasks; using System.Threading.Tasks;
namespace IceCreamShopListImplement.Models namespace IceCreamShopListImplement.Models
{ {
public class IceCream : IIceCreamModel [DataContract]
public class IceCream : IIceCreamModel
{ {
public int Id { get; private set; } [DataMember]
public string IceCreamName { get; private set; } = string.Empty; public int Id { get; private set; }
public double Price { get; private set; }
public Dictionary<int, (IComponentModel, int)> IceCreamComponents [DataMember]
public string IceCreamName { get; private set; } = string.Empty;
[DataMember]
public double Price { get; private set; }
[DataMember]
public Dictionary<int, (IComponentModel, int)> IceCreamComponents
{ {
get; get;
private set; private set;

View File

@ -1,19 +1,26 @@
using IceCreamShopContracts.BindingModels; using IceCreamShopContracts.BindingModels;
using IceCreamShopContracts.ViewModels; using IceCreamShopContracts.ViewModels;
using AbstractIceCreamShopDataModels.Models; using AbstractIceCreamShopDataModels.Models;
using System.Runtime.Serialization;
namespace IceCreamShopListImplement.Models namespace IceCreamShopListImplement.Models
{ {
[DataContract]
public class Implementer : IImplementerModel public class Implementer : IImplementerModel
{ {
[DataMember]
public int Id { get; private set; } public int Id { get; private set; }
[DataMember]
public string ImplementerFIO { get; private set; } = string.Empty; public string ImplementerFIO { get; private set; } = string.Empty;
[DataMember]
public string Password { get; private set; } = string.Empty; public string Password { get; private set; } = string.Empty;
[DataMember]
public int WorkExperience { get; private set; } public int WorkExperience { get; private set; }
[DataMember]
public int Qualification { get; private set; } public int Qualification { get; private set; }
public static Implementer? Create(ImplementerBindingModel model) public static Implementer? Create(ImplementerBindingModel model)

View File

@ -1,22 +1,30 @@
using AbstractIceCreamShopDataModels.Models; using AbstractIceCreamShopDataModels.Models;
using IceCreamShopContracts.BindingModels; using IceCreamShopContracts.BindingModels;
using IceCreamShopContracts.ViewModels; using IceCreamShopContracts.ViewModels;
using System.Runtime.Serialization;
namespace IceCreamShopListImplement.Models namespace IceCreamShopListImplement.Models
{ {
public class MessageInfo : IMessageInfoModel [DataContract]
public class MessageInfo : IMessageInfoModel
{ {
public string MessageId { get; private set; } = string.Empty; [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) public static MessageInfo? Create(MessageInfoBindingModel model)
{ {

View File

@ -9,28 +9,39 @@ using AbstractIceCreamShopDataModels.Models;
using AbstractIceCreamShopDataModels.Enums; using AbstractIceCreamShopDataModels.Enums;
using System.Data; using System.Data;
using System.Reflection; using System.Reflection;
using System.Runtime.Serialization;
namespace IceCreamShopListImplement.Models namespace IceCreamShopListImplement.Models
{ {
public class Order : IOrderModel [DataContract]
public class Order : IOrderModel
{ {
public int Id { get; private set; } [DataMember]
public int Id { get; private set; }
public int IceCreamId { get; private set; } [DataMember]
public int IceCreamId { 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 Count { get; private set; } [DataMember]
public int Count { get; private set; }
public double Sum { get; private set; } [DataMember]
public double Sum { get; private set; }
public OrderStatus Status { get; private set; } = OrderStatus.Неизвестен; [DataMember]
public OrderStatus Status { get; private set; } = OrderStatus.Неизвестен;
public DateTime DateCreate { get; private set; } = DateTime.Now; [DataMember]
public DateTime DateCreate { get; private set; } = DateTime.Now;
public DateTime? DateImplement { get; private set; } [DataMember]
public DateTime? DateImplement { get; private set; }
public static Order? Create (OrderBindingModel? model) public static Order? Create (OrderBindingModel? model)
{ {