diff --git a/Confectionery/ConfectioneryContracts/DI/UnityDependencyContainer.cs b/Confectionery/ConfectioneryContracts/DI/UnityDependencyContainer.cs new file mode 100644 index 0000000..91636b4 --- /dev/null +++ b/Confectionery/ConfectioneryContracts/DI/UnityDependencyContainer.cs @@ -0,0 +1,42 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using Unity.Microsoft.Logging; +using Unity; +using Microsoft.Extensions.Logging; + +namespace ConfectioneryContracts.DI +{ + public class UnityDependencyContainer : IDependencyContainer + { + private readonly IUnityContainer _container; + + public UnityDependencyContainer() + { + _container = new UnityContainer(); + } + + public void AddLogging(Action configure) + { + var factory = LoggerFactory.Create(configure); + _container.AddExtension(new LoggingExtension(factory)); + } + + public void RegisterType(bool isSingle) where U : class, T where T : class + { + _container.RegisterType(isSingle ? TypeLifetime.Singleton : TypeLifetime.Transient); + } + + public void RegisterType(bool isSingle) where T : class + { + _container.RegisterType(isSingle ? TypeLifetime.Singleton : TypeLifetime.Transient); + } + + public T Resolve() + { + return _container.Resolve(); + } + } +} diff --git a/Confectionery/ConfectioneryDataModels/IMessageInfoModel.cs b/Confectionery/ConfectioneryDataModels/IMessageInfoModel.cs index ac8025d..01536e5 100644 --- a/Confectionery/ConfectioneryDataModels/IMessageInfoModel.cs +++ b/Confectionery/ConfectioneryDataModels/IMessageInfoModel.cs @@ -6,7 +6,7 @@ using System.Threading.Tasks; namespace ConfectioneryDataModels.Models { - public interface IMessageInfoModel + public interface IMessageInfoModel : IId { string MessageId { get; } int? ClientId { get; } diff --git a/Confectionery/ConfectioneryDatabaseImplement/Client.cs b/Confectionery/ConfectioneryDatabaseImplement/Client.cs index 4362564..3d94f14 100644 --- a/Confectionery/ConfectioneryDatabaseImplement/Client.cs +++ b/Confectionery/ConfectioneryDatabaseImplement/Client.cs @@ -8,18 +8,23 @@ using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; +using System.Runtime.Serialization; namespace ConfectioneryDatabaseImplement.Models { + [DataContract] public class Client : IClientModel { - public int Id { get; private set; } - - [Required] + [DataMember] + public int Id { get; private set; } + [DataMember] + [Required] public string ClientFIO { get; set; } = string.Empty; - [Required] + [DataMember] + [Required] public string Email { get; set; } = string.Empty; - [Required] + [DataMember] + [Required] public string Password { get; set; } = string.Empty; [ForeignKey("ClientId")] diff --git a/Confectionery/ConfectioneryDatabaseImplement/Component.cs b/Confectionery/ConfectioneryDatabaseImplement/Component.cs index a350c35..8630406 100644 --- a/Confectionery/ConfectioneryDatabaseImplement/Component.cs +++ b/Confectionery/ConfectioneryDatabaseImplement/Component.cs @@ -3,15 +3,20 @@ using ConfectioneryContracts.ViewModels; using ConfectioneryDataModels.Models; using System.ComponentModel.DataAnnotations; using System.ComponentModel.DataAnnotations.Schema; +using System.Runtime.Serialization; namespace ConfectioneryDatabaseImplement.Models { + [DataContract] public class Component : IComponentModel { - public int Id { get; private set; } - [Required] + [DataMember] + public int Id { get; private set; } + [DataMember] + [Required] public string ComponentName { get; private set; } = string.Empty; - [Required] + [DataMember] + [Required] public double Cost { get; set; } [ForeignKey("ComponentId")] public virtual List PastryComponents { get; set; } = new(); diff --git a/Confectionery/ConfectioneryDatabaseImplement/DatabaseImplementationExtension.cs b/Confectionery/ConfectioneryDatabaseImplement/DatabaseImplementationExtension.cs new file mode 100644 index 0000000..5fb0f57 --- /dev/null +++ b/Confectionery/ConfectioneryDatabaseImplement/DatabaseImplementationExtension.cs @@ -0,0 +1,27 @@ +using ConfectioneryContracts.DI; +using ConfectioneryContracts.StoragesContracts; +using ConfectioneryDatabaseImplement.Implements; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace ConfectioneryDatabaseImplement +{ + public class DatabaseImplementationExtension : IImplementationExtension + { + public int Priority => 2; + + public void RegisterServices() + { + DependencyManager.Instance.RegisterType(); + DependencyManager.Instance.RegisterType(); + DependencyManager.Instance.RegisterType(); + DependencyManager.Instance.RegisterType(); + DependencyManager.Instance.RegisterType(); + DependencyManager.Instance.RegisterType(); + DependencyManager.Instance.RegisterType(); + } + } +} diff --git a/Confectionery/ConfectioneryDatabaseImplement/Implementer.cs b/Confectionery/ConfectioneryDatabaseImplement/Implementer.cs index 7282a3e..1b16f8f 100644 --- a/Confectionery/ConfectioneryDatabaseImplement/Implementer.cs +++ b/Confectionery/ConfectioneryDatabaseImplement/Implementer.cs @@ -8,22 +8,25 @@ using ConfectioneryContracts.ViewModels; using ConfectioneryDataModels.Models; using System.ComponentModel.DataAnnotations.Schema; using System.ComponentModel.DataAnnotations; +using System.Runtime.Serialization; namespace ConfectioneryDatabaseImplement.Models { + [DataContract] public class Implementer : IImplementerModel { + [DataMember] public int Id { get; set; } - + [DataMember] [Required] public string ImplementerFIO { get; set; } = string.Empty; - + [DataMember] [Required] public string Password { get; set; } = string.Empty; - + [DataMember] [Required] public int WorkExperience { get; set; } - + [DataMember] [Required] public int Qualification { get; set; } diff --git a/Confectionery/ConfectioneryDatabaseImplement/MessageInfo.cs b/Confectionery/ConfectioneryDatabaseImplement/MessageInfo.cs index 926aa49..bb22a39 100644 --- a/Confectionery/ConfectioneryDatabaseImplement/MessageInfo.cs +++ b/Confectionery/ConfectioneryDatabaseImplement/MessageInfo.cs @@ -8,28 +8,32 @@ using System.ComponentModel.DataAnnotations; using System.Linq; using System.Text; using System.Threading.Tasks; +using System.Runtime.Serialization; namespace ConfectioneryDatabaseImplement.Models { public class MessageInfo : IMessageInfoModel { + [NotMapped] + public int Id { get; private set; } + [DataMember] [Key] [DatabaseGenerated(DatabaseGeneratedOption.None)] public string MessageId { get; set; } = string.Empty; - + [DataMember] public int? ClientId { get; set; } public virtual Client? Client { get; set; } - + [DataMember] [Required] public string SenderName { get; set; } = string.Empty; - + [DataMember] [Required] public DateTime DateDelivery { get; set; } - + [DataMember] [Required] public string Subject { get; set; } = string.Empty; - + [DataMember] [Required] public string Body { get; set; } = string.Empty; diff --git a/Confectionery/ConfectioneryDatabaseImplement/Order.cs b/Confectionery/ConfectioneryDatabaseImplement/Order.cs index ab625d6..efe9279 100644 --- a/Confectionery/ConfectioneryDatabaseImplement/Order.cs +++ b/Confectionery/ConfectioneryDatabaseImplement/Order.cs @@ -6,41 +6,44 @@ 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 ConfectioneryDatabaseImplement.Models { + [DataContract] public class Order : IOrderModel { - public int Id { get; private set; } - [Required] - public int ClientId { get; private set; } - - public virtual Client Client { get; private set; } = new(); - - [Required] - public int PastryId { get; private set; } - - public virtual Pastry Pastry { get; set; } = new(); - public int? ImplementerId { get; private set; } - public virtual Implementer? Implementer { get; set; } = new(); - + [DataMember] + public int Id { get; set; } + [DataMember] [Required] - public int Count { get; private set; } + public int PastryId { get; set; } + [DataMember] + [Required] + public int ClientId { get; set; } + [DataMember] + public int? ImplementerId { get; private set; } + [DataMember] + [Required] + public int Count { get; set; } + [DataMember] + [Required] + public double Sum { get; set; } + [DataMember] + [Required] + public OrderStatus Status { get; set; } + [DataMember] + [Required] + public DateTime DateCreate { get; set; } + [DataMember] + public DateTime? DateImplement { get; set; } + public virtual Pastry Pastry { get; set; } + public virtual Client Client { get; set; } + public virtual Implementer? Implementer { get; set; } - [Required] - public double Sum { get; private set; } - - [Required] - public OrderStatus Status { get; private set; } = OrderStatus.Неизвестен; - - [Required] - public DateTime DateCreate { get; private set; } = DateTime.Now; - - public DateTime? DateImplement { get; private set; } - - public static Order Create(ConfectioneryDatabase context, OrderBindingModel model) + public static Order Create(ConfectioneryDatabase context, OrderBindingModel model) { return new Order() { diff --git a/Confectionery/ConfectioneryDatabaseImplement/Pastry.cs b/Confectionery/ConfectioneryDatabaseImplement/Pastry.cs index ea42b37..b2c3931 100644 --- a/Confectionery/ConfectioneryDatabaseImplement/Pastry.cs +++ b/Confectionery/ConfectioneryDatabaseImplement/Pastry.cs @@ -8,20 +8,26 @@ using ConfectioneryContracts.ViewModels; using ConfectioneryDataModels.Models; using System.ComponentModel.DataAnnotations; using System.ComponentModel.DataAnnotations.Schema; +using System.Runtime.Serialization; namespace ConfectioneryDatabaseImplement.Models { - public class Pastry : IPastryModel + [DataContract] + public class Pastry : IPastryModel { - public int Id { get; set; } - [Required] + [DataMember] + public int Id { get; set; } + [DataMember] + [Required] public string PastryName { get; set; } = string.Empty; - [Required] + [DataMember] + [Required] public double Price { get; set; } private Dictionary? _pastryComponents = null; - [NotMapped] - public Dictionary PastryComponents + [DataMember] + [NotMapped] + public Dictionary PastryComponents { get { diff --git a/Confectionery/ConfectioneryFileImplement/Client.cs b/Confectionery/ConfectioneryFileImplement/Client.cs index c87c19f..255342e 100644 --- a/Confectionery/ConfectioneryFileImplement/Client.cs +++ b/Confectionery/ConfectioneryFileImplement/Client.cs @@ -4,20 +4,29 @@ using ConfectioneryDataModels.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; -namespace ConfectioneryFileImplement +namespace ConfectioneryFileImplement.Models { - public class Client : IClientModel + [DataContract] + public class Client : IClientModel { - public int Id { get; set; } - public string ClientFIO { get; set; } = string.Empty; - public string Password { get; set; } = string.Empty; - public string Email { get; set; } = string.Empty; + [DataMember] + public int Id { get; private set; } - public static Client? Create(ClientBindingModel? model) + [DataMember] + public string ClientFIO { get; private set; } = string.Empty; + + [DataMember] + public string Email { get; private set; } = string.Empty; + + [DataMember] + public string Password { get; private set; } = string.Empty; + + public static Client? Create(ClientBindingModel? model) { if (model == null) { diff --git a/Confectionery/ConfectioneryFileImplement/Component.cs b/Confectionery/ConfectioneryFileImplement/Component.cs index 38ab4a0..1093b4a 100644 --- a/Confectionery/ConfectioneryFileImplement/Component.cs +++ b/Confectionery/ConfectioneryFileImplement/Component.cs @@ -1,16 +1,21 @@ using ConfectioneryContracts.BindingModels; using ConfectioneryContracts.ViewModels; using ConfectioneryDataModels.Models; +using System.Runtime.Serialization; using System.Xml.Linq; namespace ConfectioneryFileImplement.Models { - public class Component : IComponentModel - { - public int Id { get; private set; } - public string ComponentName { get; private set; } = string.Empty; - public double Cost { get; set; } - public static Component? Create(ComponentBindingModel model) + [DataContract] + public class Component : IComponentModel + { + [DataMember] + public int Id { get; private set; } + [DataMember] + public string ComponentName { get; private set; } = string.Empty; + [DataMember] + public double Cost { get; set; } + public static Component? Create(ComponentBindingModel model) { if (model == null) { diff --git a/Confectionery/ConfectioneryFileImplement/Implementer.cs b/Confectionery/ConfectioneryFileImplement/Implementer.cs index 586579a..3c34e3f 100644 --- a/Confectionery/ConfectioneryFileImplement/Implementer.cs +++ b/Confectionery/ConfectioneryFileImplement/Implementer.cs @@ -4,23 +4,26 @@ using ConfectioneryDataModels.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; namespace ConfectioneryFileImplement.Models { + [DataContract] public class Implementer : IImplementerModel { - public int Id { get; private set; } - - public string ImplementerFIO { get; private set; } = string.Empty; - - public string Password { get; private set; } = string.Empty; - - public int WorkExperience { get; private set; } - - public int Qualification { get; private set; } + [DataMember] + public int Id { get; set; } + [DataMember] + public string ImplementerFIO { get; set; } = string.Empty; + [DataMember] + public string Password { get; set; } = string.Empty; + [DataMember] + public int WorkExperience { get; set; } + [DataMember] + public int Qualification { get; set; } public static Implementer? Create(XElement element) { diff --git a/Confectionery/ConfectioneryFileImplement/MessageInfo.cs b/Confectionery/ConfectioneryFileImplement/MessageInfo.cs index 6889771..ac678c5 100644 --- a/Confectionery/ConfectioneryFileImplement/MessageInfo.cs +++ b/Confectionery/ConfectioneryFileImplement/MessageInfo.cs @@ -4,24 +4,29 @@ using ConfectioneryDataModels.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; namespace ConfectioneryFileImplement.Models { + [DataContract] public class MessageInfo : IMessageInfoModel { + [DataMember] + public int Id { get; private set; } + [DataMember] public string MessageId { get; private set; } = string.Empty; - + [DataMember] public int? ClientId { get; private set; } - + [DataMember] public string SenderName { get; private set; } = string.Empty; - + [DataMember] public DateTime DateDelivery { get; private set; } = DateTime.Now; - + [DataMember] public string Subject { get; private set; } = string.Empty; - + [DataMember] public string Body { get; private set; } = string.Empty; public static MessageInfo? Create(MessageInfoBindingModel model) diff --git a/Confectionery/ConfectioneryFileImplement/Order.cs b/Confectionery/ConfectioneryFileImplement/Order.cs index b607c93..90d62e8 100644 --- a/Confectionery/ConfectioneryFileImplement/Order.cs +++ b/Confectionery/ConfectioneryFileImplement/Order.cs @@ -3,22 +3,41 @@ using ConfectioneryDataModels.Models; using ConfectioneryContracts.BindingModels; using ConfectioneryContracts.ViewModels; using System.Xml.Linq; +using System.Runtime.Serialization; namespace ConfectioneryFileImplement.Models { - public class Order : IOrderModel - { - public int Id { get; private set; } - public int ClientId { get; private set; } - public int? ImplementerId { get; set; } - public int PastryId { get; private set; } - public int Count { get; private set; } - public double Sum { get; private set; } - public OrderStatus Status { get; private set; } = OrderStatus.Неизвестен; - public DateTime DateCreate { get; private set; } = DateTime.Now; - public DateTime? DateImplement { get; private set; } + [DataContract] + public class Order : IOrderModel + { + [DataMember] + public int Id { get; private set; } - public static Order? Create(OrderBindingModel? model) + [DataMember] + public int PastryId { get; private set; } + + [DataMember] + public int ClientId { get; private set; } + + [DataMember] + public int? ImplementerId { get; private set; } + + [DataMember] + public int Count { get; private set; } + + [DataMember] + public double Sum { get; private set; } + + [DataMember] + public OrderStatus Status { get; private set; } + + [DataMember] + public DateTime DateCreate { get; private set; } + + [DataMember] + public DateTime? DateImplement { get; private set; } + + public static Order? Create(OrderBindingModel? model) { if (model == null) { diff --git a/Confectionery/ConfectioneryFileImplement/Pastry.cs b/Confectionery/ConfectioneryFileImplement/Pastry.cs index 7611b91..11d315e 100644 --- a/Confectionery/ConfectioneryFileImplement/Pastry.cs +++ b/Confectionery/ConfectioneryFileImplement/Pastry.cs @@ -7,15 +7,20 @@ using ConfectioneryContracts.BindingModels; using ConfectioneryContracts.ViewModels; using ConfectioneryDataModels.Models; using System.Xml.Linq; +using System.Runtime.Serialization; namespace ConfectioneryFileImplement.Models { - public class Pastry : IPastryModel - { - public int Id { get; private set; } - public string PastryName { get; private set; } = string.Empty; - public double Price { get; private set; } - public Dictionary Components { get; private set; } = new(); + [DataContract] + public class Pastry : IPastryModel + { + [DataMember] + public int Id { get; private set; } + [DataMember] + public string PastryName { get; private set; } = string.Empty; + [DataMember] + public double Price { get; private set; } + public Dictionary Components { get; private set; } = new(); private Dictionary? _pastryComponents = null; public Dictionary PastryComponents diff --git a/Confectionery/ConfectioneryListImplement/MessageInfo.cs b/Confectionery/ConfectioneryListImplement/MessageInfo.cs index 81d7bad..6ff054b 100644 --- a/Confectionery/ConfectioneryListImplement/MessageInfo.cs +++ b/Confectionery/ConfectioneryListImplement/MessageInfo.cs @@ -11,6 +11,7 @@ namespace ConfectioneryListImplement.Models { public class MessageInfo : IMessageInfoModel { + public int Id => throw new NotImplementedException(); public string MessageId { get; private set; } = string.Empty; public int? ClientId { get; private set; } diff --git a/Confectionery/ImplementationExtensions/ConfectioneryContracts.dll b/Confectionery/ImplementationExtensions/ConfectioneryContracts.dll index 78cc89c..b0a6b41 100644 Binary files a/Confectionery/ImplementationExtensions/ConfectioneryContracts.dll and b/Confectionery/ImplementationExtensions/ConfectioneryContracts.dll differ diff --git a/Confectionery/ImplementationExtensions/ConfectioneryDataModels.dll b/Confectionery/ImplementationExtensions/ConfectioneryDataModels.dll index 3791485..6cf0490 100644 Binary files a/Confectionery/ImplementationExtensions/ConfectioneryDataModels.dll and b/Confectionery/ImplementationExtensions/ConfectioneryDataModels.dll differ diff --git a/Confectionery/ImplementationExtensions/ConfectioneryDatabaseImplement.dll b/Confectionery/ImplementationExtensions/ConfectioneryDatabaseImplement.dll index 6b1d54b..f79fe2a 100644 Binary files a/Confectionery/ImplementationExtensions/ConfectioneryDatabaseImplement.dll and b/Confectionery/ImplementationExtensions/ConfectioneryDatabaseImplement.dll differ diff --git a/Confectionery/ImplementationExtensions/ConfectioneryFileImplement.dll b/Confectionery/ImplementationExtensions/ConfectioneryFileImplement.dll index 2c4fb86..39a0994 100644 Binary files a/Confectionery/ImplementationExtensions/ConfectioneryFileImplement.dll and b/Confectionery/ImplementationExtensions/ConfectioneryFileImplement.dll differ diff --git a/Confectionery/ImplementationExtensions/ConfectioneryListImplement.dll b/Confectionery/ImplementationExtensions/ConfectioneryListImplement.dll index 82bfda7..df7155f 100644 Binary files a/Confectionery/ImplementationExtensions/ConfectioneryListImplement.dll and b/Confectionery/ImplementationExtensions/ConfectioneryListImplement.dll differ