diff --git a/FurnitureAssembly/FurnitureAssemFileImplement/Implements/BackUpInfo.cs b/FurnitureAssembly/FurnitureAssemFileImplement/Implements/BackUpInfo.cs new file mode 100644 index 0000000..5ffab2c --- /dev/null +++ b/FurnitureAssembly/FurnitureAssemFileImplement/Implements/BackUpInfo.cs @@ -0,0 +1,30 @@ +using FurnitureAssemblyContracts.StoragesContracts; +using System.Reflection; + +namespace FurnitureAssemFileImplement.Implements +{ + public class BackUpInfo : IBackUpInfo + { + public List? GetList() where T : class, new() + { + DataFileSingleton dataFileSingleton = DataFileSingleton.GetInstance(); + return (List?) dataFileSingleton.GetType().GetProperties() + .FirstOrDefault(x => x.PropertyType.IsGenericType && x.PropertyType.GetGenericArguments()[0] == typeof(T))? + .GetValue(dataFileSingleton); + } + + 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; + } + } +} diff --git a/FurnitureAssembly/FurnitureAssemFileImplement/Models/Client.cs b/FurnitureAssembly/FurnitureAssemFileImplement/Models/Client.cs index d7b6e6a..31c39d2 100644 --- a/FurnitureAssembly/FurnitureAssemFileImplement/Models/Client.cs +++ b/FurnitureAssembly/FurnitureAssemFileImplement/Models/Client.cs @@ -4,20 +4,23 @@ using FurnitureAssemblyDataModels.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 FurnitureAssemFileImplement.Models { + [DataContract] public class Client : IClientModel { + [DataMember] public int Id { get; private set; } - + [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) diff --git a/FurnitureAssembly/FurnitureAssemFileImplement/Models/Component.cs b/FurnitureAssembly/FurnitureAssemFileImplement/Models/Component.cs index ce0dbca..1a81bf5 100644 --- a/FurnitureAssembly/FurnitureAssemFileImplement/Models/Component.cs +++ b/FurnitureAssembly/FurnitureAssemFileImplement/Models/Component.cs @@ -1,14 +1,19 @@ using FurnitureAssemblyContracts.BindingModels; using FurnitureAssemblyContracts.ViewModels; using FurnitureAssemblyDataModels.Models; +using System.Runtime.Serialization; using System.Xml.Linq; namespace FurnitureAssemFileImplement.Models { + [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) diff --git a/FurnitureAssembly/FurnitureAssemFileImplement/Models/Furniture.cs b/FurnitureAssembly/FurnitureAssemFileImplement/Models/Furniture.cs index 6689a82..f4a1d80 100644 --- a/FurnitureAssembly/FurnitureAssemFileImplement/Models/Furniture.cs +++ b/FurnitureAssembly/FurnitureAssemFileImplement/Models/Furniture.cs @@ -1,17 +1,23 @@ using FurnitureAssemblyContracts.BindingModels; using FurnitureAssemblyContracts.ViewModels; using FurnitureAssemblyDataModels.Models; +using System.Runtime.Serialization; using System.Xml.Linq; namespace FurnitureAssemFileImplement.Models { + [DataContract] public class Furniture : IFurnitureModel { + [DataMember] public int Id { get; private set; } + [DataMember] public string FurnitureName { get; private set; } = string.Empty; - public double Price { get; private set; } + [DataMember] + public double Price { get; private set; } public Dictionary Components { get; private set; } = new(); private Dictionary? _furnitureComponents = null; + [DataMember] public Dictionary FurnitureComponents { get diff --git a/FurnitureAssembly/FurnitureAssemFileImplement/Models/Implementer.cs b/FurnitureAssembly/FurnitureAssemFileImplement/Models/Implementer.cs index b0071be..11327f5 100644 --- a/FurnitureAssembly/FurnitureAssemFileImplement/Models/Implementer.cs +++ b/FurnitureAssembly/FurnitureAssemFileImplement/Models/Implementer.cs @@ -1,19 +1,23 @@ using FurnitureAssemblyContracts.BindingModels; using FurnitureAssemblyContracts.ViewModels; using FurnitureAssemblyDataModels.Models; +using System.Runtime.Serialization; using System.Xml.Linq; namespace FurnitureAssemFileImplement.Models { + [DataContract] public class Implementer : IImplementerModel { + [DataMember] public int Id { get; private set; } + [DataMember] public string ImplementerFIO { get; private set; } = string.Empty; - + [DataMember] public string Password { get; private set; } = string.Empty; - + [DataMember] public int WorkExperience { get; private set; } - + [DataMember] public int Qualification { get; private set; } public static Implementer? Create(ImplementerBindingModel? model) diff --git a/FurnitureAssembly/FurnitureAssemFileImplement/Models/MessageInfo.cs b/FurnitureAssembly/FurnitureAssemFileImplement/Models/MessageInfo.cs index f051bf3..0e20dae 100644 --- a/FurnitureAssembly/FurnitureAssemFileImplement/Models/MessageInfo.cs +++ b/FurnitureAssembly/FurnitureAssemFileImplement/Models/MessageInfo.cs @@ -1,22 +1,25 @@ using FurnitureAssemblyContracts.BindingModels; using FurnitureAssemblyContracts.ViewModels; using FurnitureAssemblyDataModels.Models; +using System.Runtime.Serialization; using System.Xml.Linq; namespace FurnitureAssemFileImplement.Models { + [DataContract] public class MessageInfo : IMessageInfoModel { + [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) @@ -71,5 +74,7 @@ namespace FurnitureAssemFileImplement.Models new XElement("Body", Body), new XElement("Subject", Subject) ); + + public int Id => throw new NotImplementedException(); } } diff --git a/FurnitureAssembly/FurnitureAssemFileImplement/Models/Order.cs b/FurnitureAssembly/FurnitureAssemFileImplement/Models/Order.cs index 7e92e6e..8e86daf 100644 --- a/FurnitureAssembly/FurnitureAssemFileImplement/Models/Order.cs +++ b/FurnitureAssembly/FurnitureAssemFileImplement/Models/Order.cs @@ -7,32 +7,34 @@ using System.Collections.Generic; using System.Diagnostics; using System.Linq; using System.Reflection; +using System.Runtime.Serialization; using System.Text; using System.Threading.Tasks; using System.Xml.Linq; namespace FurnitureAssemFileImplement.Models { + [DataContract] public class Order : IOrderModel { + [DataMember] public int FurnitureId { get; private set; } - public string FurnitureName { get; private set; } = string.Empty; - + [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; } - + [DataMember] public int Id { get; private set; } - + [DataMember] public int ClientId { get; private set; } - + [DataMember] public int? ImplementerId { get; private set; } = null; public static Order? Create(OrderBindingModel? model) diff --git a/FurnitureAssembly/FurnitureAssembly/FormMain.Designer.cs b/FurnitureAssembly/FurnitureAssembly/FormMain.Designer.cs index 2087b46..3de3ff0 100644 --- a/FurnitureAssembly/FurnitureAssembly/FormMain.Designer.cs +++ b/FurnitureAssembly/FurnitureAssembly/FormMain.Designer.cs @@ -44,6 +44,7 @@ this.списокЗаказовToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); this.doWorkToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); this.mailToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); + this.CreateBackUpToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); ((System.ComponentModel.ISupportInitialize)(this.dataGridView)).BeginInit(); this.menuStrip1.SuspendLayout(); this.SuspendLayout(); @@ -93,7 +94,8 @@ this.справочникиToolStripMenuItem, this.отчетыToolStripMenuItem, this.doWorkToolStripMenuItem, - this.mailToolStripMenuItem}); + this.mailToolStripMenuItem, + this.CreateBackUpToolStripMenuItem}); this.menuStrip1.Location = new System.Drawing.Point(0, 0); this.menuStrip1.Name = "menuStrip1"; this.menuStrip1.Size = new System.Drawing.Size(1065, 24); @@ -184,6 +186,13 @@ this.mailToolStripMenuItem.Text = "Письма"; this.mailToolStripMenuItem.Click += new System.EventHandler(this.mailToolStripMenuItem_Click); // + // CreateBackUpToolStripMenuItem + // + this.CreateBackUpToolStripMenuItem.Name = "CreateBackUpToolStripMenuItem"; + this.CreateBackUpToolStripMenuItem.Size = new System.Drawing.Size(97, 20); + this.CreateBackUpToolStripMenuItem.Text = "Создать Бэкап"; + this.CreateBackUpToolStripMenuItem.Click += new System.EventHandler(this.CreateBackUpToolStripMenuItem_Click); + // // FormMain // this.AutoScaleDimensions = new System.Drawing.SizeF(7F, 15F); @@ -224,5 +233,6 @@ private ToolStripMenuItem ImplementersToolStripMenuItem; private ToolStripMenuItem doWorkToolStripMenuItem; private ToolStripMenuItem mailToolStripMenuItem; + private ToolStripMenuItem CreateBackUpToolStripMenuItem; } } \ No newline at end of file diff --git a/FurnitureAssembly/FurnitureAssembly/FormMain.cs b/FurnitureAssembly/FurnitureAssembly/FormMain.cs index d47b0eb..902d9be 100644 --- a/FurnitureAssembly/FurnitureAssembly/FormMain.cs +++ b/FurnitureAssembly/FurnitureAssembly/FormMain.cs @@ -20,13 +20,15 @@ namespace FurnitureAssembly private readonly IOrderLogic _orderLogic; private readonly IReportLogic _reportLogic; private readonly IWorkProcess _workModeling; - public FormMain(ILogger logger, IOrderLogic orderLogic, IReportLogic reportLogic, IWorkProcess workModeling) + private readonly IBackUpLogic _backUpLogic; + public FormMain(ILogger logger, IOrderLogic orderLogic, IReportLogic reportLogic, IWorkProcess workModeling, IBackUpLogic backUpLogic) { InitializeComponent(); _logger = logger; _orderLogic = orderLogic; _reportLogic = reportLogic; _workModeling = workModeling; + _backUpLogic = backUpLogic; } private void FormMain_Load(object sender, EventArgs e) { @@ -221,5 +223,30 @@ namespace FurnitureAssembly form.ShowDialog(); } } + + private void CreateBackUpToolStripMenuItem_Click(object sender, EventArgs e) + { + try + { + if (_backUpLogic != null) + { + var fbd = new FolderBrowserDialog(); + if (fbd.ShowDialog() == DialogResult.OK) + { + _backUpLogic.CreateBackUp(new BackUpSaveBinidngModel + { + FolderName = fbd.SelectedPath + }); + MessageBox.Show("Бекап создан", "Сообщение", + MessageBoxButtons.OK, MessageBoxIcon.Information); + } + } + } + catch (Exception ex) + { + MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, + MessageBoxIcon.Error); + } + } } } diff --git a/FurnitureAssembly/FurnitureAssembly/Program.cs b/FurnitureAssembly/FurnitureAssembly/Program.cs index 775c796..10c4b47 100644 --- a/FurnitureAssembly/FurnitureAssembly/Program.cs +++ b/FurnitureAssembly/FurnitureAssembly/Program.cs @@ -74,6 +74,8 @@ namespace FurnitureAssembly services.AddTransient(); services.AddTransient(); services.AddTransient(); + services.AddTransient(); + services.AddTransient(); services.AddTransient(); @@ -85,6 +87,7 @@ namespace FurnitureAssembly services.AddTransient(); services.AddSingleton(); + services.AddTransient(); services.AddTransient(); diff --git a/FurnitureAssembly/FurnitureAssemblyBusinessLogic/BackUpLogic.cs b/FurnitureAssembly/FurnitureAssemblyBusinessLogic/BackUpLogic.cs new file mode 100644 index 0000000..ef5ed08 --- /dev/null +++ b/FurnitureAssembly/FurnitureAssemblyBusinessLogic/BackUpLogic.cs @@ -0,0 +1,97 @@ +using FurnitureAssemblyContracts.BindingModels; +using FurnitureAssemblyContracts.BusinessLogicsContarcts; +using FurnitureAssemblyContracts.StoragesContracts; +using FurnitureAssemblyDataModels; +using Microsoft.Extensions.Logging; +using System.IO.Compression; +using System.Reflection; +using System.Runtime.Serialization.Json; + +namespace FurnitureAssemblyBusinessLogic +{ + public class BackUpLogic : IBackUpLogic + { + private readonly ILogger _logger; + private readonly IBackUpInfo _backUpInfo; + public BackUpLogic(ILogger logger, IBackUpInfo backUpInfo) + { + _logger = logger; + _backUpInfo = backUpInfo; + } + public void CreateBackUp(BackUpSaveBinidngModel model) + { + if (_backUpInfo == null) + { + return; + } + try + { + _logger.LogDebug("Clear folder"); + // зачистка папки и удаление старого архива + var dirInfo = new DirectoryInfo(model.FolderName); + if (dirInfo.Exists) + { + foreach (var file in dirInfo.GetFiles()) + { + file.Delete(); + } + } + _logger.LogDebug("Delete archive"); + string fileName = $"{model.FolderName}.zip"; + if (File.Exists(fileName)) + { + File.Delete(fileName); + } + // берем метод для сохранения + _logger.LogDebug("Get assembly"); + var typeIId = typeof(IId); + var assembly = typeIId.Assembly; + if (assembly == null) + { + throw new ArgumentNullException("Сборка не найдена", + nameof(assembly)); + } + var types = assembly.GetTypes(); + var method = GetType().GetMethod("SaveToFile", BindingFlags.NonPublic | BindingFlags.Instance); + _logger.LogDebug("Find {count} types", types.Length); + foreach (var type in types) + { + if (type.IsInterface && type.GetInterface(typeIId.Name) != null) + { + var modelType = _backUpInfo.GetTypeByModelInterface(type.Name); + if (modelType == null) + { + throw new InvalidOperationException($"Не найден класс - модель для { type.Name }"); + } + _logger.LogDebug("Call SaveToFile method for {name} type", type.Name); + // вызываем метод на выполнение + method?.MakeGenericMethod(modelType).Invoke(this, new + object[] { model.FolderName }); + } + } + _logger.LogDebug("Create zip and remove folder"); + // архивируем + ZipFile.CreateFromDirectory(model.FolderName, fileName); + // удаляем папку + dirInfo.Delete(true); + } + catch (Exception) + { + throw; + } + } + private void SaveToFile(string folderName) where T : class, new() + { + var records = _backUpInfo.GetList(); + if (records == null) + { + _logger.LogWarning("{type} type get null list", typeof(T).Name); + return; + } + var jsonFormatter = new DataContractJsonSerializer(typeof(List)); + using var fs = new FileStream(string.Format("{0}/{1}.json", + folderName, typeof(T).Name), FileMode.OpenOrCreate); + jsonFormatter.WriteObject(fs, records); + } + } +} diff --git a/FurnitureAssembly/FurnitureAssemblyContracts/BindingModels/BackUpSaveBinidngModel.cs b/FurnitureAssembly/FurnitureAssemblyContracts/BindingModels/BackUpSaveBinidngModel.cs new file mode 100644 index 0000000..23320f7 --- /dev/null +++ b/FurnitureAssembly/FurnitureAssemblyContracts/BindingModels/BackUpSaveBinidngModel.cs @@ -0,0 +1,7 @@ +namespace FurnitureAssemblyContracts.BindingModels +{ + public class BackUpSaveBinidngModel + { + public string FolderName { get; set; } = string.Empty; + } +} diff --git a/FurnitureAssembly/FurnitureAssemblyContracts/BindingModels/MessageInfoBindingModel.cs b/FurnitureAssembly/FurnitureAssemblyContracts/BindingModels/MessageInfoBindingModel.cs index 10e611a..d96f499 100644 --- a/FurnitureAssembly/FurnitureAssemblyContracts/BindingModels/MessageInfoBindingModel.cs +++ b/FurnitureAssembly/FurnitureAssemblyContracts/BindingModels/MessageInfoBindingModel.cs @@ -15,5 +15,7 @@ namespace FurnitureAssemblyContracts.BindingModels public string Subject { get; set; } = string.Empty; public string Body { get; set; } = string.Empty; + + public int Id => throw new NotImplementedException(); } } diff --git a/FurnitureAssembly/FurnitureAssemblyContracts/BusinessLogicsContarcts/IBackUpLogic.cs b/FurnitureAssembly/FurnitureAssemblyContracts/BusinessLogicsContarcts/IBackUpLogic.cs new file mode 100644 index 0000000..c0f25b3 --- /dev/null +++ b/FurnitureAssembly/FurnitureAssemblyContracts/BusinessLogicsContarcts/IBackUpLogic.cs @@ -0,0 +1,9 @@ +using FurnitureAssemblyContracts.BindingModels; + +namespace FurnitureAssemblyContracts.BusinessLogicsContarcts +{ + public interface IBackUpLogic + { + void CreateBackUp(BackUpSaveBinidngModel model); + } +} diff --git a/FurnitureAssembly/FurnitureAssemblyContracts/StoragesContracts/IBackUpInfo.cs b/FurnitureAssembly/FurnitureAssemblyContracts/StoragesContracts/IBackUpInfo.cs new file mode 100644 index 0000000..f770812 --- /dev/null +++ b/FurnitureAssembly/FurnitureAssemblyContracts/StoragesContracts/IBackUpInfo.cs @@ -0,0 +1,8 @@ +namespace FurnitureAssemblyContracts.StoragesContracts +{ + public interface IBackUpInfo + { + List? GetList() where T : class, new(); + Type? GetTypeByModelInterface(string modelInterfaceName); + } +} diff --git a/FurnitureAssembly/FurnitureAssemblyContracts/ViewModels/MessageInfoViewModel.cs b/FurnitureAssembly/FurnitureAssemblyContracts/ViewModels/MessageInfoViewModel.cs index 5a90aac..659ffda 100644 --- a/FurnitureAssembly/FurnitureAssemblyContracts/ViewModels/MessageInfoViewModel.cs +++ b/FurnitureAssembly/FurnitureAssemblyContracts/ViewModels/MessageInfoViewModel.cs @@ -18,5 +18,7 @@ namespace FurnitureAssemblyContracts.ViewModels public string Subject { get; set; } = string.Empty; [Column(title: "Текст", gridViewAutoSize: GridViewAutoSize.Fill, isUseAutoSize: true)] public string Body { get; set; } = string.Empty; + + public int Id => throw new NotImplementedException(); } } diff --git a/FurnitureAssembly/FurnitureAssemblyDataModels/Models/IMessageInfoModel.cs b/FurnitureAssembly/FurnitureAssemblyDataModels/Models/IMessageInfoModel.cs index 6139889..b8eb1b3 100644 --- a/FurnitureAssembly/FurnitureAssemblyDataModels/Models/IMessageInfoModel.cs +++ b/FurnitureAssembly/FurnitureAssemblyDataModels/Models/IMessageInfoModel.cs @@ -1,6 +1,6 @@ namespace FurnitureAssemblyDataModels.Models { - public interface IMessageInfoModel + public interface IMessageInfoModel : IId { string MessageId { get; } int? ClientId { get; } diff --git a/FurnitureAssembly/FurnitureAssemblyDatabaseImplement/Implements/BackUpInfo.cs b/FurnitureAssembly/FurnitureAssemblyDatabaseImplement/Implements/BackUpInfo.cs new file mode 100644 index 0000000..e2bf4b8 --- /dev/null +++ b/FurnitureAssembly/FurnitureAssemblyDatabaseImplement/Implements/BackUpInfo.cs @@ -0,0 +1,26 @@ +using FurnitureAssemblyContracts.StoragesContracts; + +namespace FurnitureAssemblyDatabaseImplement.Implements +{ + public class BackUpInfo : IBackUpInfo + { + public List? GetList() where T : class, new() + { + using var context = new FurnitureAssemblyDatabase(); + return context.Set().ToList(); + } + 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; + } + } +} diff --git a/FurnitureAssembly/FurnitureAssemblyDatabaseImplement/Models/Client.cs b/FurnitureAssembly/FurnitureAssemblyDatabaseImplement/Models/Client.cs index bfc1dc9..c6aee58 100644 --- a/FurnitureAssembly/FurnitureAssemblyDatabaseImplement/Models/Client.cs +++ b/FurnitureAssembly/FurnitureAssemblyDatabaseImplement/Models/Client.cs @@ -3,17 +3,23 @@ using FurnitureAssemblyContracts.ViewModels; using FurnitureAssemblyDataModels.Models; using System.ComponentModel.DataAnnotations; using System.ComponentModel.DataAnnotations.Schema; +using System.Runtime.Serialization; namespace FurnitureAssemblyDatabaseImplement.Models { + [DataContract] public class Client : IClientModel { + [DataMember] public int Id { get; private set; } [Required] + [DataMember] public string ClientFIO { get; private set; } = string.Empty; [Required] + [DataMember] public string Email { get; private set; } = string.Empty; [Required] + [DataMember] public string Password { get; private set; } = string.Empty; [ForeignKey("ClientId")] diff --git a/FurnitureAssembly/FurnitureAssemblyDatabaseImplement/Models/Component.cs b/FurnitureAssembly/FurnitureAssemblyDatabaseImplement/Models/Component.cs index 1ec3c8a..73634d2 100644 --- a/FurnitureAssembly/FurnitureAssemblyDatabaseImplement/Models/Component.cs +++ b/FurnitureAssembly/FurnitureAssemblyDatabaseImplement/Models/Component.cs @@ -4,15 +4,20 @@ using FurnitureAssemblyContracts.ViewModels; using FurnitureAssemblyDataModels.Models; using System.ComponentModel.DataAnnotations.Schema; using System.ComponentModel.DataAnnotations; +using System.Runtime.Serialization; namespace FurnitureAssemblyDatabaseImplement.Models { + [DataContract] public class Component : IComponentModel { + [DataMember] public int Id { get; private set; } [Required] + [DataMember] public string ComponentName { get; private set; } = string.Empty; [Required] + [DataMember] public double Cost { get; set; } [ForeignKey("ComponentId")] public virtual List FurnitureComponents { get; set; } = new(); diff --git a/FurnitureAssembly/FurnitureAssemblyDatabaseImplement/Models/Furniture.cs b/FurnitureAssembly/FurnitureAssemblyDatabaseImplement/Models/Furniture.cs index 992dc97..ffdfe7d 100644 --- a/FurnitureAssembly/FurnitureAssemblyDatabaseImplement/Models/Furniture.cs +++ b/FurnitureAssembly/FurnitureAssemblyDatabaseImplement/Models/Furniture.cs @@ -6,20 +6,26 @@ 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 FurnitureAssemblyDatabaseImplement.Models { + [DataContract] public class Furniture : IFurnitureModel { + [DataMember] public int Id { get; set; } [Required] + [DataMember] public string FurnitureName { get; set; } = string.Empty; [Required] + [DataMember] public double Price { get; set; } private Dictionary? _furnitureComponents = null; [NotMapped] + [DataMember] public Dictionary FurnitureComponents { get diff --git a/FurnitureAssembly/FurnitureAssemblyDatabaseImplement/Models/Implementer.cs b/FurnitureAssembly/FurnitureAssemblyDatabaseImplement/Models/Implementer.cs index ba2ad20..f52fcab 100644 --- a/FurnitureAssembly/FurnitureAssemblyDatabaseImplement/Models/Implementer.cs +++ b/FurnitureAssembly/FurnitureAssemblyDatabaseImplement/Models/Implementer.cs @@ -3,19 +3,26 @@ using FurnitureAssemblyContracts.ViewModels; using FurnitureAssemblyDataModels.Models; using System.ComponentModel.DataAnnotations; using System.ComponentModel.DataAnnotations.Schema; +using System.Runtime.Serialization; namespace FurnitureAssemblyDatabaseImplement.Models { + [DataContract] public class Implementer : IImplementerModel { + [DataMember] public int Id { get; private set; } [Required] + [DataMember] public string ImplementerFIO { get; private set; } = string.Empty; [Required] + [DataMember] public string Password { get; private set; } = string.Empty; [Required] + [DataMember] public int WorkExperience { get; private set; } [Required] + [DataMember] public int Qualification { get; private set; } [ForeignKey("ImplementerId")] diff --git a/FurnitureAssembly/FurnitureAssemblyDatabaseImplement/Models/MessageInfo.cs b/FurnitureAssembly/FurnitureAssemblyDatabaseImplement/Models/MessageInfo.cs index 291789b..c3dd42e 100644 --- a/FurnitureAssembly/FurnitureAssemblyDatabaseImplement/Models/MessageInfo.cs +++ b/FurnitureAssembly/FurnitureAssemblyDatabaseImplement/Models/MessageInfo.cs @@ -2,22 +2,25 @@ using FurnitureAssemblyContracts.ViewModels; using FurnitureAssemblyDataModels.Models; using System.ComponentModel.DataAnnotations; +using System.Runtime.Serialization; namespace FurnitureAssemblyDatabaseImplement.Models { + [DataContract] public class MessageInfo : IMessageInfoModel { [Key] + [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 virtual Client? Client { get; private set; } @@ -49,5 +52,6 @@ namespace FurnitureAssemblyDatabaseImplement.Models DateDelivery = DateDelivery, }; + public int Id => throw new NotImplementedException(); } } diff --git a/FurnitureAssembly/FurnitureAssemblyDatabaseImplement/Models/Order.cs b/FurnitureAssembly/FurnitureAssemblyDatabaseImplement/Models/Order.cs index 5f8782f..7e541b1 100644 --- a/FurnitureAssembly/FurnitureAssemblyDatabaseImplement/Models/Order.cs +++ b/FurnitureAssembly/FurnitureAssemblyDatabaseImplement/Models/Order.cs @@ -8,32 +8,41 @@ using System.ComponentModel.DataAnnotations; using System.ComponentModel.DataAnnotations.Schema; using System.Diagnostics; using System.Linq; +using System.Runtime.Serialization; using System.Text; using System.Threading.Tasks; namespace FurnitureAssemblyDatabaseImplement.Models { + [DataContract] public class Order : IOrderModel { + [DataMember] public int Id { get; private set; } [Required] + [DataMember] public int FurnitureId { 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; } [Required] + [DataMember] public int ClientId { get; private set; } public virtual Client Client { get; set; } - + [DataMember] public int? ImplementerId { get; private set; } public virtual Implementer? Implementer { get; set; } diff --git a/FurnitureAssembly/FurnitureAssemblyListImplement/Models/MessageInfo.cs b/FurnitureAssembly/FurnitureAssemblyListImplement/Models/MessageInfo.cs index 332bb9f..8888064 100644 --- a/FurnitureAssembly/FurnitureAssemblyListImplement/Models/MessageInfo.cs +++ b/FurnitureAssembly/FurnitureAssemblyListImplement/Models/MessageInfo.cs @@ -44,5 +44,7 @@ namespace FurnitureAssemblyListImplement.Models SenderName = SenderName, DateDelivery = DateDelivery, }; + + public int Id => throw new NotImplementedException(); } }