From 258d18d5d786fdd078951f8c44245f7210823bbf Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=94=D0=B0=D0=BC=D0=B8=D1=80=20=D0=9D=D1=83=D0=B3=D0=B0?= =?UTF-8?q?=D0=B5=D0=B2?= Date: Mon, 29 May 2023 14:56:08 +0400 Subject: [PATCH] LabWork07 --- .../Controllers/ClientController.cs | 139 +++++++----- .../BlackmithWorkshopRestApi/Program.cs | 20 +- .../BlackmithWorkshopRestApi/appsettings.json | 11 +- BlacksmithWorkshop/BlacksmithWorkshop.sln | 4 +- .../BlacksmithWorkshopBusinessLogic.csproj | 12 +- .../BusinessLogic/MessageInfoLogic.cs | 57 +++++ .../MailWorker/AbstractMailWorker.cs | 107 +++++++++ .../MailWorker/MailKitWorker.cs | 91 ++++++++ .../BlacksmithWorkshopClientApp/APIClient.cs | 78 +++---- .../Controllers/HomeController.cs | 12 + .../BlacksmithWorkshopClientApp/Program.cs | 16 +- .../Views/Home/Enter.cshtml | 2 +- .../Views/Home/Mails.cshtml | 51 +++++ .../Views/Shared/_Layout.cshtml | 5 +- .../BindingModels/MailConfigBindingModel.cs | 24 ++ .../BindingModels/MailSendInfoBindingModel.cs | 19 ++ .../BindingModels/MessageInfoBindingModel.cs | 24 ++ .../IMessageInfoLogic.cs | 18 ++ .../SearchModels/MessageInfoSearchModel.cs | 15 ++ .../StoragesContracts/IClientStorage.cs | 18 +- .../StoragesContracts/IMessageInfoStorage.cs | 22 ++ .../ViewModels/MessageInfoViewModel.cs | 29 +++ .../Models/IMessageInfoModel.cs | 23 ++ .../BlacksmithWorkshopDatabase.cs | 12 +- .../Implements/ClientStorage.cs | 40 ++-- .../Implements/MessageInfoStorage.cs | 67 ++++++ .../20230227172536_InitMigration.Designer.cs | 170 -------------- ...20230228043436_SecondMigration.Designer.cs | 171 -------------- .../20230228043436_SecondMigration.cs | 69 ------ .../Migrations/20230327063526_FifthLabWork.cs | 70 ------ .../20230425191751_InitMigration.Designer.cs | 214 ------------------ .../20230425191751_InitMigration.cs | 68 ------ ...cs => 20230509134224_SevenLab.Designer.cs} | 90 +++++++- ...igration.cs => 20230509134224_SevenLab.cs} | 105 ++++++++- ...BlacksmithWorkshopDatabaseModelSnapshot.cs | 86 ++++++- .../Models/Client.cs | 7 +- .../Models/MessageInfo.cs | 62 +++++ .../Models/Order.cs | 123 +++++----- .../DataFileSingleton.cs | 6 + .../Implements/MessageInfoStorage.cs | 76 +++++++ .../Models/MessageInfo.cs | 98 ++++++++ .../DataListSingleton.cs | 5 + .../Implements/MessageInfoStorage.cs | 88 +++++++ .../Models/MessageInfo.cs | 73 ++++++ .../BlacksmithWorkshopView/App.config | 11 + .../FormMails.Designer.cs | 63 ++++++ .../BlacksmithWorkshopView/FormMails.cs | 60 +++++ .../BlacksmithWorkshopView/FormMails.resx | 120 ++++++++++ .../BlacksmithWorkshopView/Program.cs | 38 +++- 49 files changed, 1806 insertions(+), 983 deletions(-) create mode 100644 BlacksmithWorkshop/BlacksmithWorkshopBusinessLogic/BusinessLogic/MessageInfoLogic.cs create mode 100644 BlacksmithWorkshop/BlacksmithWorkshopBusinessLogic/MailWorker/AbstractMailWorker.cs create mode 100644 BlacksmithWorkshop/BlacksmithWorkshopBusinessLogic/MailWorker/MailKitWorker.cs create mode 100644 BlacksmithWorkshop/BlacksmithWorkshopClientApp/Views/Home/Mails.cshtml create mode 100644 BlacksmithWorkshop/BlacksmithWorkshopContracts/BindingModels/MailConfigBindingModel.cs create mode 100644 BlacksmithWorkshop/BlacksmithWorkshopContracts/BindingModels/MailSendInfoBindingModel.cs create mode 100644 BlacksmithWorkshop/BlacksmithWorkshopContracts/BindingModels/MessageInfoBindingModel.cs create mode 100644 BlacksmithWorkshop/BlacksmithWorkshopContracts/BusinessLogicsContracts/IMessageInfoLogic.cs create mode 100644 BlacksmithWorkshop/BlacksmithWorkshopContracts/SearchModels/MessageInfoSearchModel.cs create mode 100644 BlacksmithWorkshop/BlacksmithWorkshopContracts/StoragesContracts/IMessageInfoStorage.cs create mode 100644 BlacksmithWorkshop/BlacksmithWorkshopContracts/ViewModels/MessageInfoViewModel.cs create mode 100644 BlacksmithWorkshop/BlacksmithWorkshopDataModels/Models/IMessageInfoModel.cs create mode 100644 BlacksmithWorkshop/BlacksmithWorkshopDatabaseImplement/Implements/MessageInfoStorage.cs delete mode 100644 BlacksmithWorkshop/BlacksmithWorkshopDatabaseImplement/Migrations/20230227172536_InitMigration.Designer.cs delete mode 100644 BlacksmithWorkshop/BlacksmithWorkshopDatabaseImplement/Migrations/20230228043436_SecondMigration.Designer.cs delete mode 100644 BlacksmithWorkshop/BlacksmithWorkshopDatabaseImplement/Migrations/20230228043436_SecondMigration.cs delete mode 100644 BlacksmithWorkshop/BlacksmithWorkshopDatabaseImplement/Migrations/20230327063526_FifthLabWork.cs delete mode 100644 BlacksmithWorkshop/BlacksmithWorkshopDatabaseImplement/Migrations/20230425191751_InitMigration.Designer.cs delete mode 100644 BlacksmithWorkshop/BlacksmithWorkshopDatabaseImplement/Migrations/20230425191751_InitMigration.cs rename BlacksmithWorkshop/BlacksmithWorkshopDatabaseImplement/Migrations/{20230327063526_FifthLabWork.Designer.cs => 20230509134224_SevenLab.Designer.cs} (70%) rename BlacksmithWorkshop/BlacksmithWorkshopDatabaseImplement/Migrations/{20230227172536_InitMigration.cs => 20230509134224_SevenLab.cs} (52%) create mode 100644 BlacksmithWorkshop/BlacksmithWorkshopDatabaseImplement/Models/MessageInfo.cs create mode 100644 BlacksmithWorkshop/BlacksmithWorkshopFileImplement/Implements/MessageInfoStorage.cs create mode 100644 BlacksmithWorkshop/BlacksmithWorkshopFileImplement/Models/MessageInfo.cs create mode 100644 BlacksmithWorkshop/BlacksmithWorkshopListImplement/Implements/MessageInfoStorage.cs create mode 100644 BlacksmithWorkshop/BlacksmithWorkshopListImplement/Models/MessageInfo.cs create mode 100644 BlacksmithWorkshop/BlacksmithWorkshopView/App.config create mode 100644 BlacksmithWorkshop/BlacksmithWorkshopView/FormMails.Designer.cs create mode 100644 BlacksmithWorkshop/BlacksmithWorkshopView/FormMails.cs create mode 100644 BlacksmithWorkshop/BlacksmithWorkshopView/FormMails.resx diff --git a/BlacksmithWorkshop/BlackmithWorkshopRestApi/Controllers/ClientController.cs b/BlacksmithWorkshop/BlackmithWorkshopRestApi/Controllers/ClientController.cs index 3c4d1aa..3415e0b 100644 --- a/BlacksmithWorkshop/BlackmithWorkshopRestApi/Controllers/ClientController.cs +++ b/BlacksmithWorkshop/BlackmithWorkshopRestApi/Controllers/ClientController.cs @@ -6,68 +6,89 @@ using Microsoft.AspNetCore.Mvc; namespace BlacksmithWorkshopRestApi.Controllers { - //указание у контроллера, что Route будет строиться не только по наванию контроллера, но и по названию метода (так как у нас два Post-метода) - [Route("api/[controller]/[action]")] - [ApiController] - public class ClientController : Controller - { - private readonly ILogger _logger; + //указание у контроллера, что Route будет строиться не только по наванию контроллера, но и по названию метода (так как у нас два Post-метода) + [Route("api/[controller]/[action]")] + [ApiController] + public class ClientController : Controller + { + private readonly ILogger _logger; - private readonly IClientLogic _logic; + private readonly IClientLogic _logic; - public ClientController(IClientLogic logic, ILogger logger) - { - _logger = logger; - _logic = logic; - } + private readonly IMessageInfoLogic _mailLogic; - [HttpGet] - public ClientViewModel? Login(string login, string password) - { - try - { - //попытка найти запись по переданным логину и паролю - return _logic.ReadElement(new ClientSearchModel - { - Email = login, - Password = password - }); - } - catch (Exception ex) - { - _logger.LogError(ex, "Ошибка входа в систему"); - throw; - } - } + public ClientController(IClientLogic logic, IMessageInfoLogic mailLogic, ILogger logger) + { + _logger = logger; + _logic = logic; + _mailLogic = mailLogic; + } - [HttpPost] - public void Register(ClientBindingModel model) - { - try - { - //создание клиента - _logic.Create(model); - } - catch (Exception ex) - { - _logger.LogError(ex, "Ошибка регистрации"); - throw; - } - } - [HttpPost] - public void UpdateData(ClientBindingModel model) - { - try - { - //изменение клиента - _logic.Update(model); - } - catch (Exception ex) - { - _logger.LogError(ex, "Ошибка обновления данных"); - throw; - } - } - } + [HttpGet] + public ClientViewModel? Login(string login, string password) + { + try + { + //попытка найти запись по переданным логину и паролю + return _logic.ReadElement(new ClientSearchModel + { + Email = login, + Password = password + }); + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка входа в систему"); + throw; + } + } + + [HttpPost] + public void Register(ClientBindingModel model) + { + try + { + //создание клиента + _logic.Create(model); + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка регистрации"); + throw; + } + } + + [HttpPost] + public void UpdateData(ClientBindingModel model) + { + try + { + //изменение клиента + _logic.Update(model); + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка обновления данных"); + throw; + } + } + + [HttpGet] + public List? GetMessages(int clientId) + { + try + { + return _mailLogic.ReadList(new MessageInfoSearchModel + { + ClientId = clientId + }); + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка получения писем клиента"); + throw; + } + } + } } \ No newline at end of file diff --git a/BlacksmithWorkshop/BlackmithWorkshopRestApi/Program.cs b/BlacksmithWorkshop/BlackmithWorkshopRestApi/Program.cs index ca62755..1c7219d 100644 --- a/BlacksmithWorkshop/BlackmithWorkshopRestApi/Program.cs +++ b/BlacksmithWorkshop/BlackmithWorkshopRestApi/Program.cs @@ -1,4 +1,6 @@ using BlacksmithWorkshopBusinessLogic.BusinessLogic; +using BlacksmithWorkshopBusinessLogic.MailWorker; +using BlacksmithWorkshopContracts.BindingModels; using BlacksmithWorkshopContracts.BusinessLogicsContracts; using BlacksmithWorkshopContracts.StoragesContracts; using BlacksmithWorkshopDatabaseImplement.Implements; @@ -15,11 +17,15 @@ builder.Services.AddTransient(); builder.Services.AddTransient(); builder.Services.AddTransient(); builder.Services.AddTransient(); +builder.Services.AddTransient(); builder.Services.AddTransient(); builder.Services.AddTransient(); builder.Services.AddTransient(); builder.Services.AddTransient(); +builder.Services.AddTransient(); + +builder.Services.AddSingleton(); builder.Services.AddControllers(); @@ -34,6 +40,18 @@ builder.Services.AddSwaggerGen(c => var app = builder.Build(); +var mailSender = app.Services.GetService(); + +mailSender?.MailConfig(new MailConfigBindingModel +{ + MailLogin = builder.Configuration?.GetSection("MailLogin")?.Value?.ToString() ?? string.Empty, + MailPassword = builder.Configuration?.GetSection("MailPassword")?.Value?.ToString() ?? string.Empty, + SmtpClientHost = builder.Configuration?.GetSection("SmtpClientHost")?.Value?.ToString() ?? string.Empty, + SmtpClientPort = Convert.ToInt32(builder.Configuration?.GetSection("SmtpClientPort")?.Value?.ToString()), + PopHost = builder.Configuration?.GetSection("PopHost")?.Value?.ToString() ?? string.Empty, + PopPort = Convert.ToInt32(builder.Configuration?.GetSection("PopPort")?.Value?.ToString()) +}); + // Configure the HTTP request pipeline. if (app.Environment.IsDevelopment()) { @@ -49,4 +67,4 @@ app.UseAuthorization(); app.MapControllers(); -app.Run(); (); \ No newline at end of file +app.Run(); \ No newline at end of file diff --git a/BlacksmithWorkshop/BlackmithWorkshopRestApi/appsettings.json b/BlacksmithWorkshop/BlackmithWorkshopRestApi/appsettings.json index 10f68b8..3b17f8d 100644 --- a/BlacksmithWorkshop/BlackmithWorkshopRestApi/appsettings.json +++ b/BlacksmithWorkshop/BlackmithWorkshopRestApi/appsettings.json @@ -5,5 +5,12 @@ "Microsoft.AspNetCore": "Warning" } }, - "AllowedHosts": "*" -} + "AllowedHosts": "*", + + "SmtpClientHost": "smtp.gmail.com", + "SmtpClientPort": "587", + "PopHost": "pop.gmail.com", + "PopPort": "995", + "MailLogin": "dnugaev344@gmail.com", + "MailPassword": "stdo ruec qtkz axar" +} \ No newline at end of file diff --git a/BlacksmithWorkshop/BlacksmithWorkshop.sln b/BlacksmithWorkshop/BlacksmithWorkshop.sln index f709c18..53d112a 100644 --- a/BlacksmithWorkshop/BlacksmithWorkshop.sln +++ b/BlacksmithWorkshop/BlacksmithWorkshop.sln @@ -17,9 +17,9 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "BlacksmithWorkshopFileImple EndProject Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "BlacksmithWorkshopDatabaseImplement", "BlacksmithWorkshopDatabaseImplement\BlacksmithWorkshopDatabaseImplement.csproj", "{F4FDBF1E-8279-406D-ADF0-F1FFDF1C88E3}" EndProject -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "BlackmithWorkshopRestApi", "BlackmithWorkshopRestApi\BlackmithWorkshopRestApi.csproj", "{A859121D-9F87-4639-BC4F-748CEAC2FA99}" +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "BlackmithWorkshopRestApi", "BlackmithWorkshopRestApi\BlackmithWorkshopRestApi.csproj", "{A859121D-9F87-4639-BC4F-748CEAC2FA99}" EndProject -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "BlacksmithWorkshopClientApp", "BlacksmithWorkshopClientApp\BlacksmithWorkshopClientApp.csproj", "{7DB32CAB-61D8-4C32-9975-7E740C817B18}" +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "BlacksmithWorkshopClientApp", "BlacksmithWorkshopClientApp\BlacksmithWorkshopClientApp.csproj", "{7DB32CAB-61D8-4C32-9975-7E740C817B18}" EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution diff --git a/BlacksmithWorkshop/BlacksmithWorkshopBusinessLogic/BlacksmithWorkshopBusinessLogic.csproj b/BlacksmithWorkshop/BlacksmithWorkshopBusinessLogic/BlacksmithWorkshopBusinessLogic.csproj index 5f82f34..a72b0d1 100644 --- a/BlacksmithWorkshop/BlacksmithWorkshopBusinessLogic/BlacksmithWorkshopBusinessLogic.csproj +++ b/BlacksmithWorkshop/BlacksmithWorkshopBusinessLogic/BlacksmithWorkshopBusinessLogic.csproj @@ -6,12 +6,12 @@ enable - - - - - - + + + + + + diff --git a/BlacksmithWorkshop/BlacksmithWorkshopBusinessLogic/BusinessLogic/MessageInfoLogic.cs b/BlacksmithWorkshop/BlacksmithWorkshopBusinessLogic/BusinessLogic/MessageInfoLogic.cs new file mode 100644 index 0000000..41e9f6d --- /dev/null +++ b/BlacksmithWorkshop/BlacksmithWorkshopBusinessLogic/BusinessLogic/MessageInfoLogic.cs @@ -0,0 +1,57 @@ +using BlacksmithWorkshopContracts.BindingModels; +using BlacksmithWorkshopContracts.BusinessLogicsContracts; +using BlacksmithWorkshopContracts.SearchModels; +using BlacksmithWorkshopContracts.StoragesContracts; +using BlacksmithWorkshopContracts.ViewModels; +using Microsoft.Extensions.Logging; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace BlacksmithWorkshopBusinessLogic.BusinessLogic +{ + public class MessageInfoLogic : IMessageInfoLogic + { + private readonly ILogger _logger; + + private readonly IMessageInfoStorage _messageInfoStorage; + + public MessageInfoLogic(ILogger logger, IMessageInfoStorage messageInfoStorage) + { + _logger = logger; + _messageInfoStorage = messageInfoStorage; + } + + public List? ReadList(MessageInfoSearchModel? model) + { + _logger.LogInformation("ReadList. MessageId:{MessageId}", model?.MessageId); + + //list хранит весь список в случае, если model пришло со значением null на вход метода + var list = model == null ? _messageInfoStorage.GetFullList() : _messageInfoStorage.GetFilteredList(model); + + if (list == null) + { + _logger.LogWarning("ReadList return null list"); + return null; + } + + _logger.LogInformation("ReadList. Count:{Count}", list.Count); + + return list.OrderByDescending(x => x.DateDelivery).ToList(); + } + + public bool Create(MessageInfoBindingModel model) + { + if (_messageInfoStorage.Insert(model) == null) + { + _logger.LogWarning("Insert operation failed"); + + return false; + } + + return true; + } + } +} \ No newline at end of file diff --git a/BlacksmithWorkshop/BlacksmithWorkshopBusinessLogic/MailWorker/AbstractMailWorker.cs b/BlacksmithWorkshop/BlacksmithWorkshopBusinessLogic/MailWorker/AbstractMailWorker.cs new file mode 100644 index 0000000..378f30c --- /dev/null +++ b/BlacksmithWorkshop/BlacksmithWorkshopBusinessLogic/MailWorker/AbstractMailWorker.cs @@ -0,0 +1,107 @@ +using BlacksmithWorkshopContracts.BindingModels; +using BlacksmithWorkshopContracts.BusinessLogicsContracts; +using Microsoft.Extensions.Logging; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace BlacksmithWorkshopBusinessLogic.MailWorker +{ + public abstract class AbstractMailWorker + { + protected string _mailLogin = string.Empty; + + protected string _mailPassword = string.Empty; + + protected string _smtpClientHost = string.Empty; + + protected int _smtpClientPort; + + protected string _popHost = string.Empty; + + protected int _popPort; + + private readonly IMessageInfoLogic _messageInfoLogic; + + private readonly IClientLogic _clientLogic; + + private readonly ILogger _logger; + + public AbstractMailWorker(ILogger logger, IMessageInfoLogic messageInfoLogic, IClientLogic clientLogic) + { + _logger = logger; + _messageInfoLogic = messageInfoLogic; + _clientLogic = clientLogic; + } + + public void MailConfig(MailConfigBindingModel config) + { + _mailLogin = config.MailLogin; + _mailPassword = config.MailPassword; + _smtpClientHost = config.SmtpClientHost; + _smtpClientPort = config.SmtpClientPort; + _popHost = config.PopHost; + _popPort = config.PopPort; + + _logger.LogDebug("Config: {login}, {password}, {clientHost}, {clientPOrt}, { popHost}, { popPort}", + _mailLogin, _mailPassword, _smtpClientHost, _smtpClientPort, _popHost, _popPort); + } + + public async void MailSendAsync(MailSendInfoBindingModel info) + { + if (string.IsNullOrEmpty(_mailLogin) || string.IsNullOrEmpty(_mailPassword)) + { + return; + } + + if (string.IsNullOrEmpty(_smtpClientHost) || _smtpClientPort == 0) + { + return; + } + + if (string.IsNullOrEmpty(info.MailAddress) || string.IsNullOrEmpty(info.Subject) || string.IsNullOrEmpty(info.Text)) + { + return; + } + + _logger.LogDebug("Send Mail: {To}, {Subject}", info.MailAddress, info.Subject); + + await SendMailAsync(info); + } + + public async void MailCheck() + { + if (string.IsNullOrEmpty(_mailLogin) || string.IsNullOrEmpty(_mailPassword)) + { + return; + } + + if (string.IsNullOrEmpty(_popHost) || _popPort == 0) + { + return; + } + + if (_messageInfoLogic == null) + { + return; + } + + var list = await ReceiveMailAsync(); + + _logger.LogDebug("Check Mail: {Count} new mails", list.Count); + + foreach (var mail in list) + { + mail.ClientId = _clientLogic.ReadElement(new() { Email = mail.SenderName })?.Id; + + _messageInfoLogic.Create(mail); + } + } + + protected abstract Task SendMailAsync(MailSendInfoBindingModel info); + + protected abstract Task> ReceiveMailAsync(); + } +} \ No newline at end of file diff --git a/BlacksmithWorkshop/BlacksmithWorkshopBusinessLogic/MailWorker/MailKitWorker.cs b/BlacksmithWorkshop/BlacksmithWorkshopBusinessLogic/MailWorker/MailKitWorker.cs new file mode 100644 index 0000000..00f3aa4 --- /dev/null +++ b/BlacksmithWorkshop/BlacksmithWorkshopBusinessLogic/MailWorker/MailKitWorker.cs @@ -0,0 +1,91 @@ +using BlacksmithWorkshopContracts.BindingModels; +using BlacksmithWorkshopContracts.BusinessLogicsContracts; +using Microsoft.Extensions.Logging; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Net.Mail; +using System.Net; +using System.Text; +using System.Threading.Tasks; +using MailKit.Net.Pop3; +using MailKit.Security; + +namespace BlacksmithWorkshopBusinessLogic.MailWorker +{ + public class MailKitWorker : AbstractMailWorker + { + public MailKitWorker(ILogger logger, IMessageInfoLogic messageInfoLogic, IClientLogic clientLogic) + : base(logger, messageInfoLogic, clientLogic) { } + + protected override async Task SendMailAsync(MailSendInfoBindingModel info) + { + using var objMailMessage = new MailMessage(); + + using var objSmtpClient = new SmtpClient(_smtpClientHost, _smtpClientPort); + + try + { + objMailMessage.From = new MailAddress(_mailLogin); + objMailMessage.To.Add(new MailAddress(info.MailAddress)); + objMailMessage.Subject = info.Subject; + objMailMessage.Body = info.Text; + objMailMessage.SubjectEncoding = Encoding.UTF8; + objMailMessage.BodyEncoding = Encoding.UTF8; + + objSmtpClient.UseDefaultCredentials = false; + objSmtpClient.EnableSsl = true; + objSmtpClient.DeliveryMethod = SmtpDeliveryMethod.Network; + objSmtpClient.Credentials = new NetworkCredential(_mailLogin, _mailPassword); + + await Task.Run(() => objSmtpClient.Send(objMailMessage)); + } + catch (Exception) + { + throw; + } + } + + protected override async Task> ReceiveMailAsync() + { + var list = new List(); + + using var client = new Pop3Client(); + + await Task.Run(() => + { + try + { + client.Connect(_popHost, _popPort, SecureSocketOptions.SslOnConnect); + + client.Authenticate(_mailLogin, _mailPassword); + + for (int i = 0; i < client.Count; i++) + { + var message = client.GetMessage(i); + + foreach (var mail in message.From.Mailboxes) + { + list.Add(new MessageInfoBindingModel + { + DateDelivery = message.Date.DateTime, + MessageId = message.MessageId, + SenderName = mail.Address, + Subject = message.Subject, + Body = message.TextBody + }); + } + } + } + catch (AuthenticationException) + { } + finally + { + client.Disconnect(true); + } + }); + + return list; + } + } +} \ No newline at end of file diff --git a/BlacksmithWorkshop/BlacksmithWorkshopClientApp/APIClient.cs b/BlacksmithWorkshop/BlacksmithWorkshopClientApp/APIClient.cs index 88057fe..e750d48 100644 --- a/BlacksmithWorkshop/BlacksmithWorkshopClientApp/APIClient.cs +++ b/BlacksmithWorkshop/BlacksmithWorkshopClientApp/APIClient.cs @@ -5,51 +5,51 @@ using System.Text; namespace BlacksmithWorkshopClientApp { - //класс, который общается с RestAPI. Под клиентом тут подразумевается клиент, общающийся с API, а не созданный нами - public class APIClient - { - private static readonly HttpClient _client = new(); + //класс, который общается с RestAPI. Под клиентом тут подразумевается клиент, общающийся с API, а не созданный нами + public class APIClient + { + private static readonly HttpClient _client = new(); - //поле, хранящее клиента, которого необходимо авторизовать - public static ClientViewModel? Client { get; set; } = null; + //поле, хранящее клиента, которого необходимо авторизовать + public static ClientViewModel? Client { get; set; } = null; - public static void Connect(IConfiguration configuration) - { - _client.BaseAddress = new Uri(configuration["IPAddress"]); - _client.DefaultRequestHeaders.Accept.Clear(); - _client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json")); - } + public static void Connect(IConfiguration configuration) + { + _client.BaseAddress = new Uri(configuration["IPAddress"]); + _client.DefaultRequestHeaders.Accept.Clear(); + _client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json")); + } - //Get-запрос - public static T? GetRequest(string requestUrl) - { - var response = _client.GetAsync(requestUrl); - var result = response.Result.Content.ReadAsStringAsync().Result; + //Get-запрос + public static T? GetRequest(string requestUrl) + { + var response = _client.GetAsync(requestUrl); + var result = response.Result.Content.ReadAsStringAsync().Result; - if (response.Result.IsSuccessStatusCode) - { - return JsonConvert.DeserializeObject(result); - } - else - { - throw new Exception(result); - } - } + if (response.Result.IsSuccessStatusCode) + { + return JsonConvert.DeserializeObject(result); + } + else + { + throw new Exception(result); + } + } - //Post-запрос - public static void PostRequest(string requestUrl, T model) - { - var json = JsonConvert.SerializeObject(model); - var data = new StringContent(json, Encoding.UTF8, "application/json"); + //Post-запрос + public static void PostRequest(string requestUrl, T model) + { + var json = JsonConvert.SerializeObject(model); + var data = new StringContent(json, Encoding.UTF8, "application/json"); - var response = _client.PostAsync(requestUrl, data); + var response = _client.PostAsync(requestUrl, data); - var result = response.Result.Content.ReadAsStringAsync().Result; + var result = response.Result.Content.ReadAsStringAsync().Result; - if (!response.Result.IsSuccessStatusCode) - { - throw new Exception(result); - } - } - } + if (!response.Result.IsSuccessStatusCode) + { + throw new Exception(result); + } + } + } } \ No newline at end of file diff --git a/BlacksmithWorkshop/BlacksmithWorkshopClientApp/Controllers/HomeController.cs b/BlacksmithWorkshop/BlacksmithWorkshopClientApp/Controllers/HomeController.cs index 7f6cc3e..3c59edd 100644 --- a/BlacksmithWorkshop/BlacksmithWorkshopClientApp/Controllers/HomeController.cs +++ b/BlacksmithWorkshop/BlacksmithWorkshopClientApp/Controllers/HomeController.cs @@ -174,5 +174,17 @@ namespace BlacksmithWorkshopClientApp.Controllers return count * (manuf?.Price ?? 1); } + + //для работы с письмами + [HttpGet] + public IActionResult Mails() + { + if (APIClient.Client == null) + { + return Redirect("~/Home/Enter"); + } + + return View(APIClient.GetRequest>($"api/client/getmessages?clientId={APIClient.Client.Id}")); + } } } \ No newline at end of file diff --git a/BlacksmithWorkshop/BlacksmithWorkshopClientApp/Program.cs b/BlacksmithWorkshop/BlacksmithWorkshopClientApp/Program.cs index 0727468..ba1358f 100644 --- a/BlacksmithWorkshop/BlacksmithWorkshopClientApp/Program.cs +++ b/BlacksmithWorkshop/BlacksmithWorkshopClientApp/Program.cs @@ -1,3 +1,5 @@ +using BlacksmithWorkshopClientApp; + var builder = WebApplication.CreateBuilder(args); // Add services to the container. @@ -5,12 +7,14 @@ builder.Services.AddControllersWithViews(); var app = builder.Build(); +APIClient.Connect(builder.Configuration); + // Configure the HTTP request pipeline. if (!app.Environment.IsDevelopment()) { - app.UseExceptionHandler("/Home/Error"); - // The default HSTS value is 30 days. You may want to change this for production scenarios, see https://aka.ms/aspnetcore-hsts. - app.UseHsts(); + app.UseExceptionHandler("/Home/Error"); + // The default HSTS value is 30 days. You may want to change this for production scenarios, see https://aka.ms/aspnetcore-hsts. + app.UseHsts(); } app.UseHttpsRedirection(); @@ -21,7 +25,7 @@ app.UseRouting(); app.UseAuthorization(); app.MapControllerRoute( - name: "default", - pattern: "{controller=Home}/{action=Index}/{id?}"); + name: "default", + pattern: "{controller=Home}/{action=Index}/{id?}"); -app.Run(); +app.Run(); \ No newline at end of file diff --git a/BlacksmithWorkshop/BlacksmithWorkshopClientApp/Views/Home/Enter.cshtml b/BlacksmithWorkshop/BlacksmithWorkshopClientApp/Views/Home/Enter.cshtml index 8e277d4..a4f390b 100644 --- a/BlacksmithWorkshop/BlacksmithWorkshopClientApp/Views/Home/Enter.cshtml +++ b/BlacksmithWorkshop/BlacksmithWorkshopClientApp/Views/Home/Enter.cshtml @@ -9,7 +9,7 @@
Логин:
-
diff --git a/BlacksmithWorkshop/BlacksmithWorkshopClientApp/Views/Home/Mails.cshtml b/BlacksmithWorkshop/BlacksmithWorkshopClientApp/Views/Home/Mails.cshtml new file mode 100644 index 0000000..154b7a0 --- /dev/null +++ b/BlacksmithWorkshop/BlacksmithWorkshopClientApp/Views/Home/Mails.cshtml @@ -0,0 +1,51 @@ +@using BlacksmithWorkshopContracts.ViewModels + +@model List + +@{ + ViewData["Title"] = "Mails"; +} + +
+

Заказы

+
+
+ @{ + if (Model == null) + { +

Авторизируйтесь

+ return; + } + + + + + + + + + + @foreach (var item in Model) + { + + + + + + } + +
+ Дата письма + + Заголовок + + Текст +
+ @Html.DisplayFor(modelItem => item.DateDelivery) + + @Html.DisplayFor(modelItem => item.Subject) + + @Html.DisplayFor(modelItem => item.Body) +
+ } +
\ No newline at end of file diff --git a/BlacksmithWorkshop/BlacksmithWorkshopClientApp/Views/Shared/_Layout.cshtml b/BlacksmithWorkshop/BlacksmithWorkshopClientApp/Views/Shared/_Layout.cshtml index 8f78997..55b6c8a 100644 --- a/BlacksmithWorkshop/BlacksmithWorkshopClientApp/Views/Shared/_Layout.cshtml +++ b/BlacksmithWorkshop/BlacksmithWorkshopClientApp/Views/Shared/_Layout.cshtml @@ -28,6 +28,9 @@ + @@ -55,4 +58,4 @@ @await RenderSectionAsync("Scripts", required: false) - + \ No newline at end of file diff --git a/BlacksmithWorkshop/BlacksmithWorkshopContracts/BindingModels/MailConfigBindingModel.cs b/BlacksmithWorkshop/BlacksmithWorkshopContracts/BindingModels/MailConfigBindingModel.cs new file mode 100644 index 0000000..60dce86 --- /dev/null +++ b/BlacksmithWorkshop/BlacksmithWorkshopContracts/BindingModels/MailConfigBindingModel.cs @@ -0,0 +1,24 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace BlacksmithWorkshopContracts.BindingModels +{ + //один из двух классов для передачи данных по почте + public class MailConfigBindingModel + { + public string MailLogin { get; set; } = string.Empty; + + public string MailPassword { get; set; } = string.Empty; + + public string SmtpClientHost { get; set; } = string.Empty; + + public int SmtpClientPort { get; set; } + + public string PopHost { get; set; } = string.Empty; + + public int PopPort { get; set; } + } +} \ No newline at end of file diff --git a/BlacksmithWorkshop/BlacksmithWorkshopContracts/BindingModels/MailSendInfoBindingModel.cs b/BlacksmithWorkshop/BlacksmithWorkshopContracts/BindingModels/MailSendInfoBindingModel.cs new file mode 100644 index 0000000..c66daea --- /dev/null +++ b/BlacksmithWorkshop/BlacksmithWorkshopContracts/BindingModels/MailSendInfoBindingModel.cs @@ -0,0 +1,19 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace BlacksmithWorkshopContracts.BindingModels +{ + //один из двух классов для обмена информацией по почте + public class MailSendInfoBindingModel + { + public string MailAddress { get; set; } = string.Empty; + + public string Subject { get; set; } = string.Empty; + + public string Text { get; set; } = string.Empty; + } + +} \ No newline at end of file diff --git a/BlacksmithWorkshop/BlacksmithWorkshopContracts/BindingModels/MessageInfoBindingModel.cs b/BlacksmithWorkshop/BlacksmithWorkshopContracts/BindingModels/MessageInfoBindingModel.cs new file mode 100644 index 0000000..0436419 --- /dev/null +++ b/BlacksmithWorkshop/BlacksmithWorkshopContracts/BindingModels/MessageInfoBindingModel.cs @@ -0,0 +1,24 @@ +using BlacksmithWorkshopDataModels.Models; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace BlacksmithWorkshopContracts.BindingModels +{ + public class MessageInfoBindingModel : IMessageInfoModel + { + public string MessageId { get; set; } = string.Empty; + + public int? ClientId { get; set; } + + public string SenderName { get; set; } = string.Empty; + + public DateTime DateDelivery { get; set; } = DateTime.Now; + + public string Subject { get; set; } = string.Empty; + + public string Body { get; set; } = string.Empty; + } +} \ No newline at end of file diff --git a/BlacksmithWorkshop/BlacksmithWorkshopContracts/BusinessLogicsContracts/IMessageInfoLogic.cs b/BlacksmithWorkshop/BlacksmithWorkshopContracts/BusinessLogicsContracts/IMessageInfoLogic.cs new file mode 100644 index 0000000..9bf2168 --- /dev/null +++ b/BlacksmithWorkshop/BlacksmithWorkshopContracts/BusinessLogicsContracts/IMessageInfoLogic.cs @@ -0,0 +1,18 @@ +using BlacksmithWorkshopContracts.BindingModels; +using BlacksmithWorkshopContracts.SearchModels; +using BlacksmithWorkshopContracts.ViewModels; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace BlacksmithWorkshopContracts.BusinessLogicsContracts +{ + public interface IMessageInfoLogic + { + List? ReadList(MessageInfoSearchModel? model); + + bool Create(MessageInfoBindingModel model); + } +} \ No newline at end of file diff --git a/BlacksmithWorkshop/BlacksmithWorkshopContracts/SearchModels/MessageInfoSearchModel.cs b/BlacksmithWorkshop/BlacksmithWorkshopContracts/SearchModels/MessageInfoSearchModel.cs new file mode 100644 index 0000000..e61ec8d --- /dev/null +++ b/BlacksmithWorkshop/BlacksmithWorkshopContracts/SearchModels/MessageInfoSearchModel.cs @@ -0,0 +1,15 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace BlacksmithWorkshopContracts.SearchModels +{ + public class MessageInfoSearchModel + { + public string? MessageId { get; set; } + + public int? ClientId { get; set; } + } +} \ No newline at end of file diff --git a/BlacksmithWorkshop/BlacksmithWorkshopContracts/StoragesContracts/IClientStorage.cs b/BlacksmithWorkshop/BlacksmithWorkshopContracts/StoragesContracts/IClientStorage.cs index 8b5d2d8..d8cf355 100644 --- a/BlacksmithWorkshop/BlacksmithWorkshopContracts/StoragesContracts/IClientStorage.cs +++ b/BlacksmithWorkshop/BlacksmithWorkshopContracts/StoragesContracts/IClientStorage.cs @@ -9,18 +9,18 @@ using System.Threading.Tasks; namespace BlacksmithWorkshopContracts.StoragesContracts { - public interface IClientStorage - { - List GetFullList(); + public interface IClientStorage + { + List GetFullList(); - List GetFilteredList(ClientSearchModel model); + List GetFilteredList(ClientSearchModel model); - ClientViewModel? GetElement(ClientSearchModel model); + ClientViewModel? GetElement(ClientSearchModel model); - ClientViewModel? Insert(ClientBindingModel model); + ClientViewModel? Insert(ClientBindingModel model); - ClientViewModel? Update(ClientBindingModel model); + ClientViewModel? Update(ClientBindingModel model); - ClientViewModel? Delete(ClientBindingModel model); - } + ClientViewModel? Delete(ClientBindingModel model); + } } \ No newline at end of file diff --git a/BlacksmithWorkshop/BlacksmithWorkshopContracts/StoragesContracts/IMessageInfoStorage.cs b/BlacksmithWorkshop/BlacksmithWorkshopContracts/StoragesContracts/IMessageInfoStorage.cs new file mode 100644 index 0000000..a718cf5 --- /dev/null +++ b/BlacksmithWorkshop/BlacksmithWorkshopContracts/StoragesContracts/IMessageInfoStorage.cs @@ -0,0 +1,22 @@ +using BlacksmithWorkshopContracts.BindingModels; +using BlacksmithWorkshopContracts.SearchModels; +using BlacksmithWorkshopContracts.ViewModels; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace BlacksmithWorkshopContracts.StoragesContracts +{ + public interface IMessageInfoStorage + { + List GetFullList(); + + List GetFilteredList(MessageInfoSearchModel model); + + MessageInfoViewModel? GetElement(MessageInfoSearchModel model); + + MessageInfoViewModel? Insert(MessageInfoBindingModel model); + } +} \ No newline at end of file diff --git a/BlacksmithWorkshop/BlacksmithWorkshopContracts/ViewModels/MessageInfoViewModel.cs b/BlacksmithWorkshop/BlacksmithWorkshopContracts/ViewModels/MessageInfoViewModel.cs new file mode 100644 index 0000000..3973c63 --- /dev/null +++ b/BlacksmithWorkshop/BlacksmithWorkshopContracts/ViewModels/MessageInfoViewModel.cs @@ -0,0 +1,29 @@ +using BlacksmithWorkshopDataModels.Models; +using System; +using System.Collections.Generic; +using System.ComponentModel; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace BlacksmithWorkshopContracts.ViewModels +{ + public class MessageInfoViewModel : IMessageInfoModel + { + public string MessageId { get; set; } = string.Empty; + + public int? ClientId { get; set; } + + [DisplayName("Отправитель")] + public string SenderName { get; set; } = string.Empty; + + [DisplayName("Дата отправки")] + public DateTime DateDelivery { get; set; } = DateTime.Now; + + [DisplayName("Заголовок")] + public string Subject { get; set; } = string.Empty; + + [DisplayName("Текст")] + public string Body { get; set; } = string.Empty; + } +} \ No newline at end of file diff --git a/BlacksmithWorkshop/BlacksmithWorkshopDataModels/Models/IMessageInfoModel.cs b/BlacksmithWorkshop/BlacksmithWorkshopDataModels/Models/IMessageInfoModel.cs new file mode 100644 index 0000000..2882524 --- /dev/null +++ b/BlacksmithWorkshop/BlacksmithWorkshopDataModels/Models/IMessageInfoModel.cs @@ -0,0 +1,23 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace BlacksmithWorkshopDataModels.Models +{ + public interface IMessageInfoModel + { + string MessageId { get; } + + int? ClientId { get; } + + string SenderName { get; } + + DateTime DateDelivery { get; } + + string Subject { get; } + + string Body { get; } + } +} \ No newline at end of file diff --git a/BlacksmithWorkshop/BlacksmithWorkshopDatabaseImplement/BlacksmithWorkshopDatabase.cs b/BlacksmithWorkshop/BlacksmithWorkshopDatabaseImplement/BlacksmithWorkshopDatabase.cs index 754d80d..0316b47 100644 --- a/BlacksmithWorkshop/BlacksmithWorkshopDatabaseImplement/BlacksmithWorkshopDatabase.cs +++ b/BlacksmithWorkshop/BlacksmithWorkshopDatabaseImplement/BlacksmithWorkshopDatabase.cs @@ -21,17 +21,19 @@ namespace BlacksmithWorkshopDatabaseImplement base.OnConfiguring(optionsBuilder); } - public virtual DbSet WorkPieces { set; get; } + public virtual DbSet WorkPieces { set; get; } - public virtual DbSet Manufactures { set; get; } + public virtual DbSet Manufactures { set; get; } - public virtual DbSet ManufactureWorkPieces { set; get; } + public virtual DbSet ManufactureWorkPieces { set; get; } - public virtual DbSet Orders { set; get; } + public virtual DbSet Orders { set; get; } - public virtual DbSet Clients { get; set; } + public virtual DbSet Clients { get; set; } public virtual DbSet Implementers { set; get; } + + public virtual DbSet Messages { set; get; } } } diff --git a/BlacksmithWorkshop/BlacksmithWorkshopDatabaseImplement/Implements/ClientStorage.cs b/BlacksmithWorkshop/BlacksmithWorkshopDatabaseImplement/Implements/ClientStorage.cs index 828aaa2..97f07a4 100644 --- a/BlacksmithWorkshop/BlacksmithWorkshopDatabaseImplement/Implements/ClientStorage.cs +++ b/BlacksmithWorkshop/BlacksmithWorkshopDatabaseImplement/Implements/ClientStorage.cs @@ -12,10 +12,10 @@ using System.Threading.Tasks; namespace BlacksmithWorkshopDatabaseImplement.Implements { - public class ClientStorage : IClientStorage - { - public ClientViewModel? Delete(ClientBindingModel model) - { + public class ClientStorage : IClientStorage + { + public ClientViewModel? Delete(ClientBindingModel model) + { using var context = new BlacksmithWorkshopDatabase(); var element = context.Clients @@ -38,18 +38,19 @@ namespace BlacksmithWorkshopDatabaseImplement.Implements return null; } - public ClientViewModel? GetElement(ClientSearchModel model) - { + public ClientViewModel? GetElement(ClientSearchModel model) + { using var context = new BlacksmithWorkshopDatabase(); if (model.Id.HasValue) { return context.Clients .Include(x => x.Orders) - .FirstOrDefault(x => model.Id.HasValue && x.Id == model.Id) + .FirstOrDefault(x => x.Id == model.Id) ?.GetViewModel; } - else if (!string.IsNullOrEmpty(model.Email) && !string.IsNullOrEmpty(model.Password)) + + if (!string.IsNullOrEmpty(model.Email) && !string.IsNullOrEmpty(model.Password)) { return context.Clients .Include(x => x.Orders) @@ -57,7 +58,12 @@ namespace BlacksmithWorkshopDatabaseImplement.Implements ?.GetViewModel; } - return new(); + if (!string.IsNullOrEmpty(model.Email)) + return context.Clients + .FirstOrDefault(x => x.Email == model.Email) + ?.GetViewModel; + + return null; } public List GetFilteredList(ClientSearchModel model) @@ -76,8 +82,8 @@ namespace BlacksmithWorkshopDatabaseImplement.Implements .ToList(); } - public List GetFullList() - { + public List GetFullList() + { using var context = new BlacksmithWorkshopDatabase(); return context.Clients @@ -86,8 +92,8 @@ namespace BlacksmithWorkshopDatabaseImplement.Implements .ToList(); } - public ClientViewModel? Insert(ClientBindingModel model) - { + public ClientViewModel? Insert(ClientBindingModel model) + { var newClient = Client.Create(model); if (newClient == null) @@ -106,8 +112,8 @@ namespace BlacksmithWorkshopDatabaseImplement.Implements ?.GetViewModel; } - public ClientViewModel? Update(ClientBindingModel model) - { + public ClientViewModel? Update(ClientBindingModel model) + { using var context = new BlacksmithWorkshopDatabase(); var order = context.Clients .Include(x => x.Orders) @@ -126,5 +132,5 @@ namespace BlacksmithWorkshopDatabaseImplement.Implements .FirstOrDefault(x => x.Id == model.Id) ?.GetViewModel; } - } -} + } +} \ No newline at end of file diff --git a/BlacksmithWorkshop/BlacksmithWorkshopDatabaseImplement/Implements/MessageInfoStorage.cs b/BlacksmithWorkshop/BlacksmithWorkshopDatabaseImplement/Implements/MessageInfoStorage.cs new file mode 100644 index 0000000..d298e89 --- /dev/null +++ b/BlacksmithWorkshop/BlacksmithWorkshopDatabaseImplement/Implements/MessageInfoStorage.cs @@ -0,0 +1,67 @@ +using BlacksmithWorkshopContracts.BindingModels; +using BlacksmithWorkshopContracts.SearchModels; +using BlacksmithWorkshopContracts.StoragesContracts; +using BlacksmithWorkshopContracts.ViewModels; +using BlacksmithWorkshopDatabaseImplement.Models; +using Microsoft.EntityFrameworkCore; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace BlacksmithWorkshopDatabaseImplement.Implements +{ + public class MessageInfoStorage : IMessageInfoStorage + { + public MessageInfoViewModel? GetElement(MessageInfoSearchModel model) + { + if (string.IsNullOrEmpty(model.MessageId)) + { + return null; + } + + using var context = new BlacksmithWorkshopDatabase(); + + return context.Messages + .FirstOrDefault(x => (x.MessageId == model.MessageId)) + ?.GetViewModel; + } + + public List GetFilteredList(MessageInfoSearchModel model) + { + using var context = new BlacksmithWorkshopDatabase(); + + return context.Messages + .Where(x => x.ClientId.HasValue && x.ClientId == model.ClientId) + .Select(x => x.GetViewModel) + .ToList(); + } + + public List GetFullList() + { + using var context = new BlacksmithWorkshopDatabase(); + + return context.Messages + .Select(x => x.GetViewModel) + .ToList(); + } + + public MessageInfoViewModel? Insert(MessageInfoBindingModel model) + { + using var context = new BlacksmithWorkshopDatabase(); + + var newMessage = MessageInfo.Create(model); + + if (newMessage == null) + { + return null; + } + + context.Messages.Add(newMessage); + context.SaveChanges(); + + return newMessage.GetViewModel; + } + } +} \ No newline at end of file diff --git a/BlacksmithWorkshop/BlacksmithWorkshopDatabaseImplement/Migrations/20230227172536_InitMigration.Designer.cs b/BlacksmithWorkshop/BlacksmithWorkshopDatabaseImplement/Migrations/20230227172536_InitMigration.Designer.cs deleted file mode 100644 index fc42141..0000000 --- a/BlacksmithWorkshop/BlacksmithWorkshopDatabaseImplement/Migrations/20230227172536_InitMigration.Designer.cs +++ /dev/null @@ -1,170 +0,0 @@ -// -using System; -using BlacksmithWorkshopDatabaseImplement; -using Microsoft.EntityFrameworkCore; -using Microsoft.EntityFrameworkCore.Infrastructure; -using Microsoft.EntityFrameworkCore.Metadata; -using Microsoft.EntityFrameworkCore.Migrations; -using Microsoft.EntityFrameworkCore.Storage.ValueConversion; - -#nullable disable - -namespace BlacksmithWorkshopDatabaseImplement.Migrations -{ - [DbContext(typeof(BlacksmithWorkshopDatabase))] - [Migration("20230227172536_InitMigration")] - partial class InitMigration - { - /// - protected override void BuildTargetModel(ModelBuilder modelBuilder) - { -#pragma warning disable 612, 618 - modelBuilder - .HasAnnotation("ProductVersion", "7.0.3") - .HasAnnotation("Relational:MaxIdentifierLength", 128); - - SqlServerModelBuilderExtensions.UseIdentityColumns(modelBuilder); - - modelBuilder.Entity("BlacksmithWorkshopDatabaseImplement.Models.Manufacture", b => - { - b.Property("Id") - .ValueGeneratedOnAdd() - .HasColumnType("int"); - - SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); - - b.Property("ManufactureName") - .IsRequired() - .HasColumnType("nvarchar(max)"); - - b.Property("Price") - .HasColumnType("float"); - - b.HasKey("Id"); - - b.ToTable("Manufactures"); - }); - - modelBuilder.Entity("BlacksmithWorkshopDatabaseImplement.Models.ManufactureWorkPiece", b => - { - b.Property("Id") - .ValueGeneratedOnAdd() - .HasColumnType("int"); - - SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); - - b.Property("Count") - .HasColumnType("int"); - - b.Property("ManufactureId") - .HasColumnType("int"); - - b.Property("WorkPieceId") - .HasColumnType("int"); - - b.HasKey("Id"); - - b.HasIndex("ManufactureId"); - - b.HasIndex("WorkPieceId"); - - b.ToTable("ManufactureWorkPieces"); - }); - - modelBuilder.Entity("BlacksmithWorkshopDatabaseImplement.Models.Order", b => - { - b.Property("Id") - .ValueGeneratedOnAdd() - .HasColumnType("int"); - - SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); - - b.Property("Count") - .HasColumnType("int"); - - b.Property("DateCreate") - .HasColumnType("datetime2"); - - b.Property("DateImplement") - .HasColumnType("datetime2"); - - b.Property("ManufactureId") - .HasColumnType("int"); - - b.Property("ProductId") - .HasColumnType("int"); - - b.Property("Status") - .HasColumnType("int"); - - b.Property("Sum") - .HasColumnType("float"); - - b.HasKey("Id"); - - b.HasIndex("ProductId"); - - b.ToTable("Orders"); - }); - - modelBuilder.Entity("BlacksmithWorkshopDatabaseImplement.Models.WorkPiece", b => - { - b.Property("Id") - .ValueGeneratedOnAdd() - .HasColumnType("int"); - - SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); - - b.Property("Cost") - .HasColumnType("float"); - - b.Property("WorkPieceName") - .IsRequired() - .HasColumnType("nvarchar(max)"); - - b.HasKey("Id"); - - b.ToTable("WorkPieces"); - }); - - modelBuilder.Entity("BlacksmithWorkshopDatabaseImplement.Models.ManufactureWorkPiece", b => - { - b.HasOne("BlacksmithWorkshopDatabaseImplement.Models.Manufacture", "Manufacture") - .WithMany("WorkPieces") - .HasForeignKey("ManufactureId") - .OnDelete(DeleteBehavior.Cascade) - .IsRequired(); - - b.HasOne("BlacksmithWorkshopDatabaseImplement.Models.WorkPiece", "WorkPiece") - .WithMany("ManufactureWorkPieces") - .HasForeignKey("WorkPieceId") - .OnDelete(DeleteBehavior.Cascade) - .IsRequired(); - - b.Navigation("Manufacture"); - - b.Navigation("WorkPiece"); - }); - - modelBuilder.Entity("BlacksmithWorkshopDatabaseImplement.Models.Order", b => - { - b.HasOne("BlacksmithWorkshopDatabaseImplement.Models.Manufacture", null) - .WithMany("Orders") - .HasForeignKey("ProductId"); - }); - - modelBuilder.Entity("BlacksmithWorkshopDatabaseImplement.Models.Manufacture", b => - { - b.Navigation("Orders"); - - b.Navigation("WorkPieces"); - }); - - modelBuilder.Entity("BlacksmithWorkshopDatabaseImplement.Models.WorkPiece", b => - { - b.Navigation("ManufactureWorkPieces"); - }); -#pragma warning restore 612, 618 - } - } -} diff --git a/BlacksmithWorkshop/BlacksmithWorkshopDatabaseImplement/Migrations/20230228043436_SecondMigration.Designer.cs b/BlacksmithWorkshop/BlacksmithWorkshopDatabaseImplement/Migrations/20230228043436_SecondMigration.Designer.cs deleted file mode 100644 index 0cef030..0000000 --- a/BlacksmithWorkshop/BlacksmithWorkshopDatabaseImplement/Migrations/20230228043436_SecondMigration.Designer.cs +++ /dev/null @@ -1,171 +0,0 @@ -// -using System; -using BlacksmithWorkshopDatabaseImplement; -using Microsoft.EntityFrameworkCore; -using Microsoft.EntityFrameworkCore.Infrastructure; -using Microsoft.EntityFrameworkCore.Metadata; -using Microsoft.EntityFrameworkCore.Migrations; -using Microsoft.EntityFrameworkCore.Storage.ValueConversion; - -#nullable disable - -namespace BlacksmithWorkshopDatabaseImplement.Migrations -{ - [DbContext(typeof(BlacksmithWorkshopDatabase))] - [Migration("20230228043436_SecondMigration")] - partial class SecondMigration - { - /// - protected override void BuildTargetModel(ModelBuilder modelBuilder) - { -#pragma warning disable 612, 618 - modelBuilder - .HasAnnotation("ProductVersion", "7.0.3") - .HasAnnotation("Relational:MaxIdentifierLength", 128); - - SqlServerModelBuilderExtensions.UseIdentityColumns(modelBuilder); - - modelBuilder.Entity("BlacksmithWorkshopDatabaseImplement.Models.Manufacture", b => - { - b.Property("Id") - .ValueGeneratedOnAdd() - .HasColumnType("int"); - - SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); - - b.Property("ManufactureName") - .IsRequired() - .HasColumnType("nvarchar(max)"); - - b.Property("Price") - .HasColumnType("float"); - - b.HasKey("Id"); - - b.ToTable("Manufactures"); - }); - - modelBuilder.Entity("BlacksmithWorkshopDatabaseImplement.Models.ManufactureWorkPiece", b => - { - b.Property("Id") - .ValueGeneratedOnAdd() - .HasColumnType("int"); - - SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); - - b.Property("Count") - .HasColumnType("int"); - - b.Property("ManufactureId") - .HasColumnType("int"); - - b.Property("WorkPieceId") - .HasColumnType("int"); - - b.HasKey("Id"); - - b.HasIndex("ManufactureId"); - - b.HasIndex("WorkPieceId"); - - b.ToTable("ManufactureWorkPieces"); - }); - - modelBuilder.Entity("BlacksmithWorkshopDatabaseImplement.Models.Order", b => - { - b.Property("Id") - .ValueGeneratedOnAdd() - .HasColumnType("int"); - - SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); - - b.Property("Count") - .HasColumnType("int"); - - b.Property("DateCreate") - .HasColumnType("datetime2"); - - b.Property("DateImplement") - .HasColumnType("datetime2"); - - b.Property("ManufactureId") - .HasColumnType("int"); - - b.Property("Status") - .HasColumnType("int"); - - b.Property("Sum") - .HasColumnType("float"); - - b.HasKey("Id"); - - b.HasIndex("ManufactureId"); - - b.ToTable("Orders"); - }); - - modelBuilder.Entity("BlacksmithWorkshopDatabaseImplement.Models.WorkPiece", b => - { - b.Property("Id") - .ValueGeneratedOnAdd() - .HasColumnType("int"); - - SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); - - b.Property("Cost") - .HasColumnType("float"); - - b.Property("WorkPieceName") - .IsRequired() - .HasColumnType("nvarchar(max)"); - - b.HasKey("Id"); - - b.ToTable("WorkPieces"); - }); - - modelBuilder.Entity("BlacksmithWorkshopDatabaseImplement.Models.ManufactureWorkPiece", b => - { - b.HasOne("BlacksmithWorkshopDatabaseImplement.Models.Manufacture", "Manufacture") - .WithMany("WorkPieces") - .HasForeignKey("ManufactureId") - .OnDelete(DeleteBehavior.Cascade) - .IsRequired(); - - b.HasOne("BlacksmithWorkshopDatabaseImplement.Models.WorkPiece", "WorkPiece") - .WithMany("ManufactureWorkPieces") - .HasForeignKey("WorkPieceId") - .OnDelete(DeleteBehavior.Cascade) - .IsRequired(); - - b.Navigation("Manufacture"); - - b.Navigation("WorkPiece"); - }); - - modelBuilder.Entity("BlacksmithWorkshopDatabaseImplement.Models.Order", b => - { - b.HasOne("BlacksmithWorkshopDatabaseImplement.Models.Manufacture", "Manufacture") - .WithMany("Orders") - .HasForeignKey("ManufactureId") - .OnDelete(DeleteBehavior.Cascade) - .IsRequired(); - - b.Navigation("Manufacture"); - }); - - modelBuilder.Entity("BlacksmithWorkshopDatabaseImplement.Models.Manufacture", b => - { - b.Navigation("Orders"); - - b.Navigation("WorkPieces"); - }); - - modelBuilder.Entity("BlacksmithWorkshopDatabaseImplement.Models.WorkPiece", b => - { - b.Navigation("ManufactureWorkPieces"); - }); -#pragma warning restore 612, 618 - } - } -} diff --git a/BlacksmithWorkshop/BlacksmithWorkshopDatabaseImplement/Migrations/20230228043436_SecondMigration.cs b/BlacksmithWorkshop/BlacksmithWorkshopDatabaseImplement/Migrations/20230228043436_SecondMigration.cs deleted file mode 100644 index c5e65a8..0000000 --- a/BlacksmithWorkshop/BlacksmithWorkshopDatabaseImplement/Migrations/20230228043436_SecondMigration.cs +++ /dev/null @@ -1,69 +0,0 @@ -using Microsoft.EntityFrameworkCore.Migrations; - -#nullable disable - -namespace BlacksmithWorkshopDatabaseImplement.Migrations -{ - /// - public partial class SecondMigration : Migration - { - /// - protected override void Up(MigrationBuilder migrationBuilder) - { - migrationBuilder.DropForeignKey( - name: "FK_Orders_Manufactures_ProductId", - table: "Orders"); - - migrationBuilder.DropIndex( - name: "IX_Orders_ProductId", - table: "Orders"); - - migrationBuilder.DropColumn( - name: "ProductId", - table: "Orders"); - - migrationBuilder.CreateIndex( - name: "IX_Orders_ManufactureId", - table: "Orders", - column: "ManufactureId"); - - migrationBuilder.AddForeignKey( - name: "FK_Orders_Manufactures_ManufactureId", - table: "Orders", - column: "ManufactureId", - principalTable: "Manufactures", - principalColumn: "Id", - onDelete: ReferentialAction.Cascade); - } - - /// - protected override void Down(MigrationBuilder migrationBuilder) - { - migrationBuilder.DropForeignKey( - name: "FK_Orders_Manufactures_ManufactureId", - table: "Orders"); - - migrationBuilder.DropIndex( - name: "IX_Orders_ManufactureId", - table: "Orders"); - - migrationBuilder.AddColumn( - name: "ProductId", - table: "Orders", - type: "int", - nullable: true); - - migrationBuilder.CreateIndex( - name: "IX_Orders_ProductId", - table: "Orders", - column: "ProductId"); - - migrationBuilder.AddForeignKey( - name: "FK_Orders_Manufactures_ProductId", - table: "Orders", - column: "ProductId", - principalTable: "Manufactures", - principalColumn: "Id"); - } - } -} diff --git a/BlacksmithWorkshop/BlacksmithWorkshopDatabaseImplement/Migrations/20230327063526_FifthLabWork.cs b/BlacksmithWorkshop/BlacksmithWorkshopDatabaseImplement/Migrations/20230327063526_FifthLabWork.cs deleted file mode 100644 index 19c2a58..0000000 --- a/BlacksmithWorkshop/BlacksmithWorkshopDatabaseImplement/Migrations/20230327063526_FifthLabWork.cs +++ /dev/null @@ -1,70 +0,0 @@ -using Microsoft.EntityFrameworkCore.Migrations; - -#nullable disable - -namespace BlacksmithWorkshopDatabaseImplement.Migrations -{ - /// - public partial class FifthLabWork : Migration - { - /// - protected override void Up(MigrationBuilder migrationBuilder) - { - migrationBuilder.Sql("DELETE FROM [dbo].[Orders]"); - - migrationBuilder.AddColumn( - name: "ClientId", - table: "Orders", - type: "int", - nullable: false, - defaultValue: 0); - - migrationBuilder.CreateTable( - name: "Clients", - columns: table => new - { - Id = table.Column(type: "int", nullable: false) - .Annotation("SqlServer:Identity", "1, 1"), - ClientFIO = table.Column(type: "nvarchar(max)", nullable: false), - Email = table.Column(type: "nvarchar(max)", nullable: false), - Password = table.Column(type: "nvarchar(max)", nullable: false) - }, - constraints: table => - { - table.PrimaryKey("PK_Clients", x => x.Id); - }); - - migrationBuilder.CreateIndex( - name: "IX_Orders_ClientId", - table: "Orders", - column: "ClientId"); - - migrationBuilder.AddForeignKey( - name: "FK_Orders_Clients_ClientId", - table: "Orders", - column: "ClientId", - principalTable: "Clients", - principalColumn: "Id", - onDelete: ReferentialAction.Cascade); - } - - /// - protected override void Down(MigrationBuilder migrationBuilder) - { - migrationBuilder.DropForeignKey( - name: "FK_Orders_Clients_ClientId", - table: "Orders"); - - migrationBuilder.DropTable( - name: "Clients"); - - migrationBuilder.DropIndex( - name: "IX_Orders_ClientId", - table: "Orders"); - - migrationBuilder.DropColumn( - name: "ClientId", - table: "Orders"); - } - } -} diff --git a/BlacksmithWorkshop/BlacksmithWorkshopDatabaseImplement/Migrations/20230425191751_InitMigration.Designer.cs b/BlacksmithWorkshop/BlacksmithWorkshopDatabaseImplement/Migrations/20230425191751_InitMigration.Designer.cs deleted file mode 100644 index be14298..0000000 --- a/BlacksmithWorkshop/BlacksmithWorkshopDatabaseImplement/Migrations/20230425191751_InitMigration.Designer.cs +++ /dev/null @@ -1,214 +0,0 @@ -// -using System; -using BlacksmithWorkshopDatabaseImplement; -using Microsoft.EntityFrameworkCore; -using Microsoft.EntityFrameworkCore.Infrastructure; -using Microsoft.EntityFrameworkCore.Metadata; -using Microsoft.EntityFrameworkCore.Migrations; -using Microsoft.EntityFrameworkCore.Storage.ValueConversion; - -#nullable disable - -namespace BlacksmithWorkshopDatabaseImplement.Migrations -{ - [DbContext(typeof(BlacksmithWorkshopDatabase))] - [Migration("20230425191751_InitMigration2")] - partial class InitMigration2 - { - /// - protected override void BuildTargetModel(ModelBuilder modelBuilder) - { -#pragma warning disable 612, 618 - modelBuilder - .HasAnnotation("ProductVersion", "7.0.4") - .HasAnnotation("Relational:MaxIdentifierLength", 128); - - SqlServerModelBuilderExtensions.UseIdentityColumns(modelBuilder); - - modelBuilder.Entity("BlacksmithWorkshopDatabaseImplement.Models.Client", b => - { - b.Property("Id") - .ValueGeneratedOnAdd() - .HasColumnType("int"); - - SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); - - b.Property("ClientFIO") - .IsRequired() - .HasColumnType("nvarchar(max)"); - - b.Property("Email") - .IsRequired() - .HasColumnType("nvarchar(max)"); - - b.Property("Password") - .IsRequired() - .HasColumnType("nvarchar(max)"); - - b.HasKey("Id"); - - b.ToTable("Clients"); - }); - - modelBuilder.Entity("BlacksmithWorkshopDatabaseImplement.Models.Manufacture", b => - { - b.Property("Id") - .ValueGeneratedOnAdd() - .HasColumnType("int"); - - SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); - - b.Property("ManufactureName") - .IsRequired() - .HasColumnType("nvarchar(max)"); - - b.Property("Price") - .HasColumnType("float"); - - b.HasKey("Id"); - - b.ToTable("Manufactures"); - }); - - modelBuilder.Entity("BlacksmithWorkshopDatabaseImplement.Models.ManufactureWorkPiece", b => - { - b.Property("Id") - .ValueGeneratedOnAdd() - .HasColumnType("int"); - - SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); - - b.Property("Count") - .HasColumnType("int"); - - b.Property("ManufactureId") - .HasColumnType("int"); - - b.Property("WorkPieceId") - .HasColumnType("int"); - - b.HasKey("Id"); - - b.HasIndex("ManufactureId"); - - b.HasIndex("WorkPieceId"); - - b.ToTable("ManufactureWorkPieces"); - }); - - modelBuilder.Entity("BlacksmithWorkshopDatabaseImplement.Models.Order", b => - { - b.Property("Id") - .ValueGeneratedOnAdd() - .HasColumnType("int"); - - SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); - - b.Property("ClientId") - .HasColumnType("int"); - - b.Property("Count") - .HasColumnType("int"); - - b.Property("DateCreate") - .HasColumnType("datetime2"); - - b.Property("DateImplement") - .HasColumnType("datetime2"); - - b.Property("ManufactureId") - .HasColumnType("int"); - - b.Property("Status") - .HasColumnType("int"); - - b.Property("Sum") - .HasColumnType("float"); - - b.HasKey("Id"); - - b.HasIndex("ClientId"); - - b.HasIndex("ManufactureId"); - - b.ToTable("Orders"); - }); - - modelBuilder.Entity("BlacksmithWorkshopDatabaseImplement.Models.WorkPiece", b => - { - b.Property("Id") - .ValueGeneratedOnAdd() - .HasColumnType("int"); - - SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); - - b.Property("Cost") - .HasColumnType("float"); - - b.Property("WorkPieceName") - .IsRequired() - .HasColumnType("nvarchar(max)"); - - b.HasKey("Id"); - - b.ToTable("WorkPieces"); - }); - - modelBuilder.Entity("BlacksmithWorkshopDatabaseImplement.Models.ManufactureWorkPiece", b => - { - b.HasOne("BlacksmithWorkshopDatabaseImplement.Models.Manufacture", "Manufacture") - .WithMany("WorkPieces") - .HasForeignKey("ManufactureId") - .OnDelete(DeleteBehavior.Cascade) - .IsRequired(); - - b.HasOne("BlacksmithWorkshopDatabaseImplement.Models.WorkPiece", "WorkPiece") - .WithMany("ManufactureWorkPieces") - .HasForeignKey("WorkPieceId") - .OnDelete(DeleteBehavior.Cascade) - .IsRequired(); - - b.Navigation("Manufacture"); - - b.Navigation("WorkPiece"); - }); - - modelBuilder.Entity("BlacksmithWorkshopDatabaseImplement.Models.Order", b => - { - b.HasOne("BlacksmithWorkshopDatabaseImplement.Models.Client", "Client") - .WithMany("Orders") - .HasForeignKey("ClientId") - .OnDelete(DeleteBehavior.Cascade) - .IsRequired(); - - b.HasOne("BlacksmithWorkshopDatabaseImplement.Models.Manufacture", "Manufacture") - .WithMany("Orders") - .HasForeignKey("ManufactureId") - .OnDelete(DeleteBehavior.Cascade) - .IsRequired(); - - b.Navigation("Client"); - - b.Navigation("Manufacture"); - }); - - modelBuilder.Entity("BlacksmithWorkshopDatabaseImplement.Models.Client", b => - { - b.Navigation("Orders"); - }); - - modelBuilder.Entity("BlacksmithWorkshopDatabaseImplement.Models.Manufacture", b => - { - b.Navigation("Orders"); - - b.Navigation("WorkPieces"); - }); - - modelBuilder.Entity("BlacksmithWorkshopDatabaseImplement.Models.WorkPiece", b => - { - b.Navigation("ManufactureWorkPieces"); - }); -#pragma warning restore 612, 618 - } - } -} diff --git a/BlacksmithWorkshop/BlacksmithWorkshopDatabaseImplement/Migrations/20230425191751_InitMigration.cs b/BlacksmithWorkshop/BlacksmithWorkshopDatabaseImplement/Migrations/20230425191751_InitMigration.cs deleted file mode 100644 index eff323c..0000000 --- a/BlacksmithWorkshop/BlacksmithWorkshopDatabaseImplement/Migrations/20230425191751_InitMigration.cs +++ /dev/null @@ -1,68 +0,0 @@ -using Microsoft.EntityFrameworkCore.Migrations; - -#nullable disable - -namespace BlacksmithWorkshopDatabaseImplement.Migrations -{ - /// - public partial class InitMigration2 : Migration - { - /// - protected override void Up(MigrationBuilder migrationBuilder) - { - migrationBuilder.AddColumn( - name: "ClientId", - table: "Orders", - type: "int", - nullable: false, - defaultValue: 0); - - migrationBuilder.CreateTable( - name: "Clients", - columns: table => new - { - Id = table.Column(type: "int", nullable: false) - .Annotation("SqlServer:Identity", "1, 1"), - ClientFIO = table.Column(type: "nvarchar(max)", nullable: false), - Email = table.Column(type: "nvarchar(max)", nullable: false), - Password = table.Column(type: "nvarchar(max)", nullable: false) - }, - constraints: table => - { - table.PrimaryKey("PK_Clients", x => x.Id); - }); - - migrationBuilder.CreateIndex( - name: "IX_Orders_ClientId", - table: "Orders", - column: "ClientId"); - - migrationBuilder.AddForeignKey( - name: "FK_Orders_Clients_ClientId", - table: "Orders", - column: "ClientId", - principalTable: "Clients", - principalColumn: "Id", - onDelete: ReferentialAction.Cascade); - } - - /// - protected override void Down(MigrationBuilder migrationBuilder) - { - migrationBuilder.DropForeignKey( - name: "FK_Orders_Clients_ClientId", - table: "Orders"); - - migrationBuilder.DropTable( - name: "Clients"); - - migrationBuilder.DropIndex( - name: "IX_Orders_ClientId", - table: "Orders"); - - migrationBuilder.DropColumn( - name: "ClientId", - table: "Orders"); - } - } -} diff --git a/BlacksmithWorkshop/BlacksmithWorkshopDatabaseImplement/Migrations/20230327063526_FifthLabWork.Designer.cs b/BlacksmithWorkshop/BlacksmithWorkshopDatabaseImplement/Migrations/20230509134224_SevenLab.Designer.cs similarity index 70% rename from BlacksmithWorkshop/BlacksmithWorkshopDatabaseImplement/Migrations/20230327063526_FifthLabWork.Designer.cs rename to BlacksmithWorkshop/BlacksmithWorkshopDatabaseImplement/Migrations/20230509134224_SevenLab.Designer.cs index 3a0ec6d..60f98a2 100644 --- a/BlacksmithWorkshop/BlacksmithWorkshopDatabaseImplement/Migrations/20230327063526_FifthLabWork.Designer.cs +++ b/BlacksmithWorkshop/BlacksmithWorkshopDatabaseImplement/Migrations/20230509134224_SevenLab.Designer.cs @@ -12,15 +12,15 @@ using Microsoft.EntityFrameworkCore.Storage.ValueConversion; namespace BlacksmithWorkshopDatabaseImplement.Migrations { [DbContext(typeof(BlacksmithWorkshopDatabase))] - [Migration("20230327063526_FifthLabWork")] - partial class FifthLabWork + [Migration("20230509134224_SevenLab")] + partial class SevenLab { /// protected override void BuildTargetModel(ModelBuilder modelBuilder) { #pragma warning disable 612, 618 modelBuilder - .HasAnnotation("ProductVersion", "7.0.4") + .HasAnnotation("ProductVersion", "7.0.3") .HasAnnotation("Relational:MaxIdentifierLength", 128); SqlServerModelBuilderExtensions.UseIdentityColumns(modelBuilder); @@ -50,6 +50,33 @@ namespace BlacksmithWorkshopDatabaseImplement.Migrations b.ToTable("Clients"); }); + modelBuilder.Entity("BlacksmithWorkshopDatabaseImplement.Models.Implementer", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("int"); + + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); + + b.Property("ImplementerFIO") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.Property("Password") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.Property("Qualification") + .HasColumnType("int"); + + b.Property("WorkExperience") + .HasColumnType("int"); + + b.HasKey("Id"); + + b.ToTable("Implementers"); + }); + modelBuilder.Entity("BlacksmithWorkshopDatabaseImplement.Models.Manufacture", b => { b.Property("Id") @@ -96,6 +123,36 @@ namespace BlacksmithWorkshopDatabaseImplement.Migrations b.ToTable("ManufactureWorkPieces"); }); + modelBuilder.Entity("BlacksmithWorkshopDatabaseImplement.Models.MessageInfo", b => + { + b.Property("MessageId") + .HasColumnType("nvarchar(450)"); + + b.Property("Body") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.Property("ClientId") + .HasColumnType("int"); + + b.Property("DateDelivery") + .HasColumnType("datetime2"); + + b.Property("SenderName") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.Property("Subject") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.HasKey("MessageId"); + + b.HasIndex("ClientId"); + + b.ToTable("Messages"); + }); + modelBuilder.Entity("BlacksmithWorkshopDatabaseImplement.Models.Order", b => { b.Property("Id") @@ -116,6 +173,9 @@ namespace BlacksmithWorkshopDatabaseImplement.Migrations b.Property("DateImplement") .HasColumnType("datetime2"); + b.Property("ImplementerId") + .HasColumnType("int"); + b.Property("ManufactureId") .HasColumnType("int"); @@ -129,6 +189,8 @@ namespace BlacksmithWorkshopDatabaseImplement.Migrations b.HasIndex("ClientId"); + b.HasIndex("ImplementerId"); + b.HasIndex("ManufactureId"); b.ToTable("Orders"); @@ -173,6 +235,15 @@ namespace BlacksmithWorkshopDatabaseImplement.Migrations b.Navigation("WorkPiece"); }); + modelBuilder.Entity("BlacksmithWorkshopDatabaseImplement.Models.MessageInfo", b => + { + b.HasOne("BlacksmithWorkshopDatabaseImplement.Models.Client", "Client") + .WithMany("MessageInfos") + .HasForeignKey("ClientId"); + + b.Navigation("Client"); + }); + modelBuilder.Entity("BlacksmithWorkshopDatabaseImplement.Models.Order", b => { b.HasOne("BlacksmithWorkshopDatabaseImplement.Models.Client", "Client") @@ -181,6 +252,10 @@ namespace BlacksmithWorkshopDatabaseImplement.Migrations .OnDelete(DeleteBehavior.Cascade) .IsRequired(); + b.HasOne("BlacksmithWorkshopDatabaseImplement.Models.Implementer", "Implementer") + .WithMany("Orders") + .HasForeignKey("ImplementerId"); + b.HasOne("BlacksmithWorkshopDatabaseImplement.Models.Manufacture", "Manufacture") .WithMany("Orders") .HasForeignKey("ManufactureId") @@ -189,10 +264,19 @@ namespace BlacksmithWorkshopDatabaseImplement.Migrations b.Navigation("Client"); + b.Navigation("Implementer"); + b.Navigation("Manufacture"); }); modelBuilder.Entity("BlacksmithWorkshopDatabaseImplement.Models.Client", b => + { + b.Navigation("MessageInfos"); + + b.Navigation("Orders"); + }); + + modelBuilder.Entity("BlacksmithWorkshopDatabaseImplement.Models.Implementer", b => { b.Navigation("Orders"); }); diff --git a/BlacksmithWorkshop/BlacksmithWorkshopDatabaseImplement/Migrations/20230227172536_InitMigration.cs b/BlacksmithWorkshop/BlacksmithWorkshopDatabaseImplement/Migrations/20230509134224_SevenLab.cs similarity index 52% rename from BlacksmithWorkshop/BlacksmithWorkshopDatabaseImplement/Migrations/20230227172536_InitMigration.cs rename to BlacksmithWorkshop/BlacksmithWorkshopDatabaseImplement/Migrations/20230509134224_SevenLab.cs index c1fbbc3..bb5a7c5 100644 --- a/BlacksmithWorkshop/BlacksmithWorkshopDatabaseImplement/Migrations/20230227172536_InitMigration.cs +++ b/BlacksmithWorkshop/BlacksmithWorkshopDatabaseImplement/Migrations/20230509134224_SevenLab.cs @@ -6,11 +6,42 @@ using Microsoft.EntityFrameworkCore.Migrations; namespace BlacksmithWorkshopDatabaseImplement.Migrations { /// - public partial class InitMigration : Migration + public partial class SevenLab : Migration { /// protected override void Up(MigrationBuilder migrationBuilder) { + migrationBuilder.CreateTable( + name: "Clients", + columns: table => new + { + Id = table.Column(type: "int", nullable: false) + .Annotation("SqlServer:Identity", "1, 1"), + ClientFIO = table.Column(type: "nvarchar(max)", nullable: false), + Email = table.Column(type: "nvarchar(max)", nullable: false), + Password = table.Column(type: "nvarchar(max)", nullable: false) + }, + constraints: table => + { + table.PrimaryKey("PK_Clients", x => x.Id); + }); + + migrationBuilder.CreateTable( + name: "Implementers", + columns: table => new + { + Id = table.Column(type: "int", nullable: false) + .Annotation("SqlServer:Identity", "1, 1"), + ImplementerFIO = table.Column(type: "nvarchar(max)", nullable: false), + Password = table.Column(type: "nvarchar(max)", nullable: false), + WorkExperience = table.Column(type: "int", nullable: false), + Qualification = table.Column(type: "int", nullable: false) + }, + constraints: table => + { + table.PrimaryKey("PK_Implementers", x => x.Id); + }); + migrationBuilder.CreateTable( name: "Manufactures", columns: table => new @@ -39,6 +70,27 @@ namespace BlacksmithWorkshopDatabaseImplement.Migrations table.PrimaryKey("PK_WorkPieces", x => x.Id); }); + migrationBuilder.CreateTable( + name: "Messages", + columns: table => new + { + MessageId = table.Column(type: "nvarchar(450)", nullable: false), + ClientId = table.Column(type: "int", nullable: true), + SenderName = table.Column(type: "nvarchar(max)", nullable: false), + DateDelivery = table.Column(type: "datetime2", nullable: false), + Subject = table.Column(type: "nvarchar(max)", nullable: false), + Body = table.Column(type: "nvarchar(max)", nullable: false) + }, + constraints: table => + { + table.PrimaryKey("PK_Messages", x => x.MessageId); + table.ForeignKey( + name: "FK_Messages_Clients_ClientId", + column: x => x.ClientId, + principalTable: "Clients", + principalColumn: "Id"); + }); + migrationBuilder.CreateTable( name: "Orders", columns: table => new @@ -46,21 +98,34 @@ namespace BlacksmithWorkshopDatabaseImplement.Migrations Id = table.Column(type: "int", nullable: false) .Annotation("SqlServer:Identity", "1, 1"), ManufactureId = table.Column(type: "int", nullable: false), + ClientId = table.Column(type: "int", nullable: false), + ImplementerId = table.Column(type: "int", nullable: true), Count = table.Column(type: "int", nullable: false), Sum = table.Column(type: "float", nullable: false), Status = table.Column(type: "int", nullable: false), DateCreate = table.Column(type: "datetime2", nullable: false), - DateImplement = table.Column(type: "datetime2", nullable: true), - ProductId = table.Column(type: "int", nullable: true) + DateImplement = table.Column(type: "datetime2", nullable: true) }, constraints: table => { table.PrimaryKey("PK_Orders", x => x.Id); table.ForeignKey( - name: "FK_Orders_Manufactures_ProductId", - column: x => x.ProductId, - principalTable: "Manufactures", + name: "FK_Orders_Clients_ClientId", + column: x => x.ClientId, + principalTable: "Clients", + principalColumn: "Id", + onDelete: ReferentialAction.Cascade); + table.ForeignKey( + name: "FK_Orders_Implementers_ImplementerId", + column: x => x.ImplementerId, + principalTable: "Implementers", principalColumn: "Id"); + table.ForeignKey( + name: "FK_Orders_Manufactures_ManufactureId", + column: x => x.ManufactureId, + principalTable: "Manufactures", + principalColumn: "Id", + onDelete: ReferentialAction.Cascade); }); migrationBuilder.CreateTable( @@ -101,9 +166,24 @@ namespace BlacksmithWorkshopDatabaseImplement.Migrations column: "WorkPieceId"); migrationBuilder.CreateIndex( - name: "IX_Orders_ProductId", + name: "IX_Messages_ClientId", + table: "Messages", + column: "ClientId"); + + migrationBuilder.CreateIndex( + name: "IX_Orders_ClientId", table: "Orders", - column: "ProductId"); + column: "ClientId"); + + migrationBuilder.CreateIndex( + name: "IX_Orders_ImplementerId", + table: "Orders", + column: "ImplementerId"); + + migrationBuilder.CreateIndex( + name: "IX_Orders_ManufactureId", + table: "Orders", + column: "ManufactureId"); } /// @@ -112,12 +192,21 @@ namespace BlacksmithWorkshopDatabaseImplement.Migrations migrationBuilder.DropTable( name: "ManufactureWorkPieces"); + migrationBuilder.DropTable( + name: "Messages"); + migrationBuilder.DropTable( name: "Orders"); migrationBuilder.DropTable( name: "WorkPieces"); + migrationBuilder.DropTable( + name: "Clients"); + + migrationBuilder.DropTable( + name: "Implementers"); + migrationBuilder.DropTable( name: "Manufactures"); } diff --git a/BlacksmithWorkshop/BlacksmithWorkshopDatabaseImplement/Migrations/BlacksmithWorkshopDatabaseModelSnapshot.cs b/BlacksmithWorkshop/BlacksmithWorkshopDatabaseImplement/Migrations/BlacksmithWorkshopDatabaseModelSnapshot.cs index e3bcdf1..55b99cf 100644 --- a/BlacksmithWorkshop/BlacksmithWorkshopDatabaseImplement/Migrations/BlacksmithWorkshopDatabaseModelSnapshot.cs +++ b/BlacksmithWorkshop/BlacksmithWorkshopDatabaseImplement/Migrations/BlacksmithWorkshopDatabaseModelSnapshot.cs @@ -17,7 +17,7 @@ namespace BlacksmithWorkshopDatabaseImplement.Migrations { #pragma warning disable 612, 618 modelBuilder - .HasAnnotation("ProductVersion", "7.0.4") + .HasAnnotation("ProductVersion", "7.0.3") .HasAnnotation("Relational:MaxIdentifierLength", 128); SqlServerModelBuilderExtensions.UseIdentityColumns(modelBuilder); @@ -47,6 +47,33 @@ namespace BlacksmithWorkshopDatabaseImplement.Migrations b.ToTable("Clients"); }); + modelBuilder.Entity("BlacksmithWorkshopDatabaseImplement.Models.Implementer", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("int"); + + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); + + b.Property("ImplementerFIO") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.Property("Password") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.Property("Qualification") + .HasColumnType("int"); + + b.Property("WorkExperience") + .HasColumnType("int"); + + b.HasKey("Id"); + + b.ToTable("Implementers"); + }); + modelBuilder.Entity("BlacksmithWorkshopDatabaseImplement.Models.Manufacture", b => { b.Property("Id") @@ -93,6 +120,36 @@ namespace BlacksmithWorkshopDatabaseImplement.Migrations b.ToTable("ManufactureWorkPieces"); }); + modelBuilder.Entity("BlacksmithWorkshopDatabaseImplement.Models.MessageInfo", b => + { + b.Property("MessageId") + .HasColumnType("nvarchar(450)"); + + b.Property("Body") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.Property("ClientId") + .HasColumnType("int"); + + b.Property("DateDelivery") + .HasColumnType("datetime2"); + + b.Property("SenderName") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.Property("Subject") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.HasKey("MessageId"); + + b.HasIndex("ClientId"); + + b.ToTable("Messages"); + }); + modelBuilder.Entity("BlacksmithWorkshopDatabaseImplement.Models.Order", b => { b.Property("Id") @@ -113,6 +170,9 @@ namespace BlacksmithWorkshopDatabaseImplement.Migrations b.Property("DateImplement") .HasColumnType("datetime2"); + b.Property("ImplementerId") + .HasColumnType("int"); + b.Property("ManufactureId") .HasColumnType("int"); @@ -126,6 +186,8 @@ namespace BlacksmithWorkshopDatabaseImplement.Migrations b.HasIndex("ClientId"); + b.HasIndex("ImplementerId"); + b.HasIndex("ManufactureId"); b.ToTable("Orders"); @@ -170,6 +232,15 @@ namespace BlacksmithWorkshopDatabaseImplement.Migrations b.Navigation("WorkPiece"); }); + modelBuilder.Entity("BlacksmithWorkshopDatabaseImplement.Models.MessageInfo", b => + { + b.HasOne("BlacksmithWorkshopDatabaseImplement.Models.Client", "Client") + .WithMany("MessageInfos") + .HasForeignKey("ClientId"); + + b.Navigation("Client"); + }); + modelBuilder.Entity("BlacksmithWorkshopDatabaseImplement.Models.Order", b => { b.HasOne("BlacksmithWorkshopDatabaseImplement.Models.Client", "Client") @@ -178,6 +249,10 @@ namespace BlacksmithWorkshopDatabaseImplement.Migrations .OnDelete(DeleteBehavior.Cascade) .IsRequired(); + b.HasOne("BlacksmithWorkshopDatabaseImplement.Models.Implementer", "Implementer") + .WithMany("Orders") + .HasForeignKey("ImplementerId"); + b.HasOne("BlacksmithWorkshopDatabaseImplement.Models.Manufacture", "Manufacture") .WithMany("Orders") .HasForeignKey("ManufactureId") @@ -186,10 +261,19 @@ namespace BlacksmithWorkshopDatabaseImplement.Migrations b.Navigation("Client"); + b.Navigation("Implementer"); + b.Navigation("Manufacture"); }); modelBuilder.Entity("BlacksmithWorkshopDatabaseImplement.Models.Client", b => + { + b.Navigation("MessageInfos"); + + b.Navigation("Orders"); + }); + + modelBuilder.Entity("BlacksmithWorkshopDatabaseImplement.Models.Implementer", b => { b.Navigation("Orders"); }); diff --git a/BlacksmithWorkshop/BlacksmithWorkshopDatabaseImplement/Models/Client.cs b/BlacksmithWorkshop/BlacksmithWorkshopDatabaseImplement/Models/Client.cs index 118cf94..5369a34 100644 --- a/BlacksmithWorkshop/BlacksmithWorkshopDatabaseImplement/Models/Client.cs +++ b/BlacksmithWorkshop/BlacksmithWorkshopDatabaseImplement/Models/Client.cs @@ -28,6 +28,9 @@ namespace BlacksmithWorkshopDatabaseImplement.Models [ForeignKey("ClientId")] public virtual List Orders { get; set; } = new(); + [ForeignKey("ClientId")] + public virtual List MessageInfos { get; set; } = new(); + public static Client? Create(ClientBindingModel model) { if (model == null) @@ -39,7 +42,7 @@ namespace BlacksmithWorkshopDatabaseImplement.Models { Id = model.Id, ClientFIO = model.ClientFIO, - Email = model.Email, + Email = model.Email, Password = model.Password }; } @@ -75,4 +78,4 @@ namespace BlacksmithWorkshopDatabaseImplement.Models Password = Password }; } -} +} \ No newline at end of file diff --git a/BlacksmithWorkshop/BlacksmithWorkshopDatabaseImplement/Models/MessageInfo.cs b/BlacksmithWorkshop/BlacksmithWorkshopDatabaseImplement/Models/MessageInfo.cs new file mode 100644 index 0000000..98544af --- /dev/null +++ b/BlacksmithWorkshop/BlacksmithWorkshopDatabaseImplement/Models/MessageInfo.cs @@ -0,0 +1,62 @@ +using BlacksmithWorkshopContracts.BindingModels; +using BlacksmithWorkshopContracts.ViewModels; +using BlacksmithWorkshopDataModels.Models; +using System; +using System.Collections.Generic; +using System.ComponentModel.DataAnnotations; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace BlacksmithWorkshopDatabaseImplement.Models +{ + public class MessageInfo : IMessageInfoModel + { + [Key] + public string MessageId { get; set; } = string.Empty; + + public int? ClientId { get; set; } + + [Required] + public string SenderName { get; set; } = string.Empty; + + [Required] + public DateTime DateDelivery { get; set; } = DateTime.Now; + + [Required] + public string Subject { get; set; } = string.Empty; + + [Required] + public string Body { get; set; } = string.Empty; + + public virtual Client? Client { get; set; } + + public static MessageInfo? Create(MessageInfoBindingModel model) + { + if (model == null) + { + return null; + } + + return new MessageInfo() + { + MessageId = model.MessageId, + ClientId = model.ClientId, + SenderName = model.SenderName, + Body = model.Body, + DateDelivery = model.DateDelivery, + Subject = model.Subject + }; + } + + public MessageInfoViewModel GetViewModel => new() + { + MessageId = MessageId, + ClientId = ClientId, + SenderName = SenderName, + Body = Body, + DateDelivery = DateDelivery, + Subject = Subject + }; + } +} \ No newline at end of file diff --git a/BlacksmithWorkshop/BlacksmithWorkshopDatabaseImplement/Models/Order.cs b/BlacksmithWorkshop/BlacksmithWorkshopDatabaseImplement/Models/Order.cs index a39b1ca..d899de2 100644 --- a/BlacksmithWorkshop/BlacksmithWorkshopDatabaseImplement/Models/Order.cs +++ b/BlacksmithWorkshop/BlacksmithWorkshopDatabaseImplement/Models/Order.cs @@ -12,79 +12,88 @@ using System.Xml.Linq; namespace BlacksmithWorkshopDatabaseImplement.Models { - public class Order : IOrderModel - { - public int Id { get; private set; } + public class Order : IOrderModel + { + public int Id { get; private set; } - [Required] - public int ManufactureId { get; private set; } + [Required] + public int ManufactureId { get; private set; } [Required] public int ClientId { get; private set; } + public int? ImplementerId { get; private set; } + [Required] - public int Count { get; private set; } + public int Count { get; private set; } - [Required] - public double Sum { get; private set; } + [Required] + public double Sum { get; private set; } - [Required] - public OrderStatus Status { get; private set; } = OrderStatus.Неизвестен; + [Required] + public OrderStatus Status { get; private set; } = OrderStatus.Неизвестен; - [Required] - public DateTime DateCreate { get; private set; } = DateTime.Now; + [Required] + public DateTime DateCreate { get; private set; } = DateTime.Now; - public DateTime? DateImplement { get; private set; } + public DateTime? DateImplement { get; private set; } - //для передачи названия изделия - public virtual Manufacture Manufacture { get; set; } + //для передачи названия изделия + public virtual Manufacture Manufacture { get; set; } - //для передачи имени клиента - public virtual Client Client { get; set; } + //для передачи имени клиента + public virtual Client Client { get; set; } - public static Order? Create(OrderBindingModel model) - { - if (model == null) - { - return null; - } + //для передачи имени исполнителя + public virtual Implementer? Implementer { get; set; } - return new Order() - { - Id = model.Id, - ManufactureId = model.ManufactureId, - ClientId = model.ClientId, - Count = model.Count, - Sum = model.Sum, - Status = model.Status, - DateCreate = model.DateCreate, - DateImplement = model.DateImplement - }; - } + public static Order? Create(OrderBindingModel model) + { + if (model == null) + { + return null; + } - public void Update(OrderBindingModel model) - { - if (model == null) - { - return; - } + return new Order() + { + Id = model.Id, + ManufactureId = model.ManufactureId, + ClientId = model.ClientId, + ImplementerId = model.ImplementerId, + Count = model.Count, + Sum = model.Sum, + Status = model.Status, + DateCreate = model.DateCreate, + DateImplement = model.DateImplement + }; + } - Status = model.Status; - DateImplement = model.DateImplement; - } + public void Update(OrderBindingModel model) + { + if (model == null) + { + return; + } - public OrderViewModel GetViewModel => new() - { - Id = Id, - ManufactureId = ManufactureId, - ClientId = ClientId, - Count = Count, - Sum = Sum, - Status = Status, - DateCreate = DateCreate, - DateImplement = DateImplement, - ManufactureName = Manufacture.ManufactureName, - ClientFIO = Client.ClientFIO + ImplementerId = model.ImplementerId; + Status = model.Status; + DateImplement = model.DateImplement; + } + + public OrderViewModel GetViewModel => new() + { + Id = Id, + ManufactureId = ManufactureId, + ClientId = ClientId, + ImplementerId = ImplementerId, + Count = Count, + Sum = Sum, + Status = Status, + DateCreate = DateCreate, + DateImplement = DateImplement, + ManufactureName = Manufacture.ManufactureName, + ClientFIO = Client.ClientFIO, + ImplementerFIO = Implementer?.ImplementerFIO }; } -} +} \ No newline at end of file diff --git a/BlacksmithWorkshop/BlacksmithWorkshopFileImplement/DataFileSingleton.cs b/BlacksmithWorkshop/BlacksmithWorkshopFileImplement/DataFileSingleton.cs index 72759fb..4276d0c 100644 --- a/BlacksmithWorkshop/BlacksmithWorkshopFileImplement/DataFileSingleton.cs +++ b/BlacksmithWorkshop/BlacksmithWorkshopFileImplement/DataFileSingleton.cs @@ -22,6 +22,8 @@ namespace BlacksmithWorkshopFileImplement private readonly string ImplementerFileName = "Implementer.xml"; + private readonly string MessageFileName = "Message.xml"; + public List WorkPieces { get; private set; } public List Orders { get; private set; } @@ -32,6 +34,8 @@ namespace BlacksmithWorkshopFileImplement public List Implementers { get; private set; } + public List Messages { get; private set; } + public static DataFileSingleton GetInstance() { if (instance == null) @@ -52,6 +56,7 @@ namespace BlacksmithWorkshopFileImplement public void SaveImplementers() => SaveData(Implementers, ImplementerFileName, "Implementers", x => x.GetXElement); + public void SaveMessages() => SaveData(Messages, MessageFileName, "Messages", x => x.GetXElement); private DataFileSingleton() { WorkPieces = LoadData(WorkPieceFileName, "WorkPiece", x => WorkPiece.Create(x)!)!; @@ -59,6 +64,7 @@ namespace BlacksmithWorkshopFileImplement Orders = LoadData(OrderFileName, "Order", x => Order.Create(x)!)!; Clients = LoadData(ClientFileName, "Client", x => Client.Create(x)!)!; Implementers = LoadData(ImplementerFileName, "Implementer", x => Implementer.Create(x)!)!; + Messages = LoadData(MessageFileName, "Messages", x => MessageInfo.Create(x)!)!; } private static List? LoadData(string filename, string xmlNodeName, Func selectFunction) diff --git a/BlacksmithWorkshop/BlacksmithWorkshopFileImplement/Implements/MessageInfoStorage.cs b/BlacksmithWorkshop/BlacksmithWorkshopFileImplement/Implements/MessageInfoStorage.cs new file mode 100644 index 0000000..4da1754 --- /dev/null +++ b/BlacksmithWorkshop/BlacksmithWorkshopFileImplement/Implements/MessageInfoStorage.cs @@ -0,0 +1,76 @@ +using BlacksmithWorkshopContracts.BindingModels; +using BlacksmithWorkshopContracts.SearchModels; +using BlacksmithWorkshopContracts.StoragesContracts; +using BlacksmithWorkshopContracts.ViewModels; +using BlacksmithWorkshopFileImplement.Models; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace BlacksmithWorkshopFileImplement.Implements +{ + public class MessageInfoStorage : IMessageInfoStorage + { + private readonly DataFileSingleton source; + + public MessageInfoStorage() + { + source = DataFileSingleton.GetInstance(); + } + + public List GetFullList() + { + return source.Messages.Select(x => GetViewModel(x)).ToList(); + } + + public List GetFilteredList(MessageInfoSearchModel model) + { + if (!model.ClientId.HasValue) + { + return source.Messages + .Select(x => GetViewModel(x)) + .ToList(); + } + + return source.Messages + .Where(x => x.ClientId == model.ClientId) + .Select(x => GetViewModel(x)) + .ToList(); + } + + public MessageInfoViewModel? GetElement(MessageInfoSearchModel model) + { + if (!model.ClientId.HasValue) + { + return null; + } + + return source.Messages.FirstOrDefault(x => (model.ClientId.HasValue && x.ClientId == model.ClientId))?.GetViewModel; + } + + public MessageInfoViewModel? Insert(MessageInfoBindingModel model) + { + model.MessageId = source.Messages.Count > 0 ? Convert.ToString(source.Messages.Count + 1) : "1"; + + var newMessage = MessageInfo.Create(model); + + if (newMessage == null) + { + return null; + } + + source.Messages.Add(newMessage); + source.SaveOrders(); + + return GetViewModel(newMessage); + } + + //для загрузки названий и имён в заказ + private MessageInfoViewModel GetViewModel(MessageInfo message) + { + return message.GetViewModel; + } + } +} \ No newline at end of file diff --git a/BlacksmithWorkshop/BlacksmithWorkshopFileImplement/Models/MessageInfo.cs b/BlacksmithWorkshop/BlacksmithWorkshopFileImplement/Models/MessageInfo.cs new file mode 100644 index 0000000..61398e1 --- /dev/null +++ b/BlacksmithWorkshop/BlacksmithWorkshopFileImplement/Models/MessageInfo.cs @@ -0,0 +1,98 @@ +using BlacksmithWorkshopContracts.BindingModels; +using BlacksmithWorkshopContracts.ViewModels; +using BlacksmithWorkshopDataModels.Models; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Reflection; +using System.Runtime.CompilerServices; +using System.Text; +using System.Threading.Tasks; +using System.Xml.Linq; + +namespace BlacksmithWorkshopFileImplement.Models +{ + public class MessageInfo : IMessageInfoModel + { + public string MessageId { get; private set; } = string.Empty; + + public int? ClientId { get; private set; } + + public string SenderName { get; private set; } = string.Empty; + + public DateTime DateDelivery { get; private set; } = DateTime.Now; + + public string Subject { get; private set; } = string.Empty; + + public string Body { get; private set; } = string.Empty; + + public static MessageInfo? Create(MessageInfoBindingModel model) + { + if (model == null) + { + return null; + } + + return new MessageInfo() + { + MessageId = model.MessageId, + ClientId = model.ClientId, + SenderName = model.SenderName, + Body = model.Body, + Subject = model.Subject, + DateDelivery = model.DateDelivery + }; + } + + public static MessageInfo? Create(XElement element) + { + if (element == null) + { + return null; + } + + return new MessageInfo() + { + MessageId = element.Element("MessageId")!.Value, + ClientId = Convert.ToInt32(element.Attribute("ClientId")!.Value), + SenderName = element.Element("SenderName")!.Value, + Body = element.Element("Body")!.Value, + Subject = element.Element("Subject")!.Value, + DateDelivery = Convert.ToDateTime(element.Element("DateDelivery")!.Value) + }; + } + + public void Update(MessageInfoBindingModel model) + { + if (model == null) + { + return; + } + + MessageId = model.MessageId; + ClientId = model.ClientId; + SenderName = model.SenderName; + Body = model.Body; + Subject = model.Subject; + DateDelivery = model.DateDelivery; + } + + public MessageInfoViewModel GetViewModel => new() + { + MessageId = MessageId, + ClientId = ClientId, + SenderName = SenderName, + Body = Body, + Subject = Subject, + DateDelivery = DateDelivery + }; + + public XElement GetXElement => new("MessageInfo", + new XAttribute("MessageId", MessageId), + new XElement("ClientId", ClientId.ToString()), + new XElement("SenderName", SenderName), + new XElement("Body", Body), + new XElement("Subject", Subject), + new XElement("DateDelivery", DateDelivery.ToString())); + } +} \ No newline at end of file diff --git a/BlacksmithWorkshop/BlacksmithWorkshopListImplement/DataListSingleton.cs b/BlacksmithWorkshop/BlacksmithWorkshopListImplement/DataListSingleton.cs index 4ca4522..d3e3fd1 100644 --- a/BlacksmithWorkshop/BlacksmithWorkshopListImplement/DataListSingleton.cs +++ b/BlacksmithWorkshop/BlacksmithWorkshopListImplement/DataListSingleton.cs @@ -27,6 +27,10 @@ namespace BlacksmithWorkshopListImplement //список для хранения исполнителей public List Implementers { get; set; } + //список для хранения писем + public List MessageInfos { get; set; } + + public DataListSingleton() { WorkPieces = new List(); @@ -34,6 +38,7 @@ namespace BlacksmithWorkshopListImplement Orders = new List(); Clients = new List(); Implementers = new List(); + MessageInfos = new List(); } public static DataListSingleton GetInstance() diff --git a/BlacksmithWorkshop/BlacksmithWorkshopListImplement/Implements/MessageInfoStorage.cs b/BlacksmithWorkshop/BlacksmithWorkshopListImplement/Implements/MessageInfoStorage.cs new file mode 100644 index 0000000..846ced1 --- /dev/null +++ b/BlacksmithWorkshop/BlacksmithWorkshopListImplement/Implements/MessageInfoStorage.cs @@ -0,0 +1,88 @@ +using BlacksmithWorkshopContracts.BindingModels; +using BlacksmithWorkshopContracts.SearchModels; +using BlacksmithWorkshopContracts.StoragesContracts; +using BlacksmithWorkshopContracts.ViewModels; +using BlacksmithWorkshopListImplement.Models; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace BlacksmithWorkshopListImplement.Implements +{ + public class MessageInfoStorage : IMessageInfoStorage + { + //поле для работы со списком изделий + private readonly DataListSingleton _source; + + public MessageInfoStorage() + { + _source = DataListSingleton.GetInstance(); + } + + public List GetFullList() + { + var result = new List(); + + foreach (var messageInfo in _source.MessageInfos) + { + result.Add(messageInfo.GetViewModel); + } + + return result; + } + + public List GetFilteredList(MessageInfoSearchModel model) + { + var result = new List(); + + if (string.IsNullOrEmpty(model.MessageId)) + { + return result; + } + + foreach (var messageInfo in _source.MessageInfos) + { + if (messageInfo.ClientId == model.ClientId) + { + result.Add(messageInfo.GetViewModel); + } + } + + return result; + } + + public MessageInfoViewModel? GetElement(MessageInfoSearchModel model) + { + if (string.IsNullOrEmpty(model.MessageId)) + { + return null; + } + + foreach (var messageInfo in _source.MessageInfos) + { + if (messageInfo.MessageId == model.MessageId) + { + return messageInfo.GetViewModel; + } + } + + return null; + } + + public MessageInfoViewModel? Insert(MessageInfoBindingModel model) + { + var newMessage = MessageInfo.Create(model); + + if (newMessage == null) + { + return null; + } + + _source.MessageInfos.Add(newMessage); + + return newMessage.GetViewModel; + } + } +} \ No newline at end of file diff --git a/BlacksmithWorkshop/BlacksmithWorkshopListImplement/Models/MessageInfo.cs b/BlacksmithWorkshop/BlacksmithWorkshopListImplement/Models/MessageInfo.cs new file mode 100644 index 0000000..54117c8 --- /dev/null +++ b/BlacksmithWorkshop/BlacksmithWorkshopListImplement/Models/MessageInfo.cs @@ -0,0 +1,73 @@ +using BlacksmithWorkshopContracts.BindingModels; +using BlacksmithWorkshopContracts.ViewModels; +using BlacksmithWorkshopDataModels.Models; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Reflection; +using System.Text; +using System.Threading.Tasks; + +namespace BlacksmithWorkshopListImplement.Models +{ + public class MessageInfo : IMessageInfoModel + { + public string MessageId { get; private set; } = string.Empty; + + public int? ClientId { get; private set; } + + public string SenderName { get; private set; } = string.Empty; + + public DateTime DateDelivery { get; private set; } = DateTime.Now; + + public string Subject { get; private set; } = string.Empty; + + public string Body { get; private set; } = string.Empty; + + //метод для создания объекта от класса-компонента на основе класса-BindingModel + public static MessageInfo? Create(MessageInfoBindingModel? model) + { + if (model == null) + { + return null; + } + + return new MessageInfo() + { + MessageId = model.MessageId, + ClientId = model.ClientId, + SenderName = model.SenderName, + DateDelivery = model.DateDelivery, + Subject = model.Subject, + Body = model.Body + }; + } + + //метод изменения существующего объекта + public void Update(MessageInfoBindingModel? model) + { + if (model == null) + { + return; + } + + MessageId = model.MessageId; + ClientId = model.ClientId; + SenderName = model.SenderName; + DateDelivery = model.DateDelivery; + Subject = model.Subject; + Body = model.Body; + } + + //метод для создания объекта класса ViewModel на основе данных объекта класса-компонента + public MessageInfoViewModel GetViewModel => new() + { + MessageId = MessageId, + ClientId = ClientId, + SenderName = SenderName, + DateDelivery = DateDelivery, + Subject = Subject, + Body = Body + }; + } +} \ No newline at end of file diff --git a/BlacksmithWorkshop/BlacksmithWorkshopView/App.config b/BlacksmithWorkshop/BlacksmithWorkshopView/App.config new file mode 100644 index 0000000..3eb1032 --- /dev/null +++ b/BlacksmithWorkshop/BlacksmithWorkshopView/App.config @@ -0,0 +1,11 @@ + + + + + + + + + + + \ No newline at end of file diff --git a/BlacksmithWorkshop/BlacksmithWorkshopView/FormMails.Designer.cs b/BlacksmithWorkshop/BlacksmithWorkshopView/FormMails.Designer.cs new file mode 100644 index 0000000..1b0abda --- /dev/null +++ b/BlacksmithWorkshop/BlacksmithWorkshopView/FormMails.Designer.cs @@ -0,0 +1,63 @@ +namespace BlacksmithWorkshop +{ + partial class FormMails + { + /// + /// Required designer variable. + /// + private System.ComponentModel.IContainer components = null; + + /// + /// Clean up any resources being used. + /// + /// true if managed resources should be disposed; otherwise, false. + protected override void Dispose(bool disposing) + { + if (disposing && (components != null)) + { + components.Dispose(); + } + base.Dispose(disposing); + } + + #region Windows Form Designer generated code + + /// + /// Required method for Designer support - do not modify + /// the contents of this method with the code editor. + /// + private void InitializeComponent() + { + dataGridView = new DataGridView(); + ((System.ComponentModel.ISupportInitialize)dataGridView).BeginInit(); + SuspendLayout(); + // + // dataGridView + // + dataGridView.ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.AutoSize; + dataGridView.Dock = DockStyle.Fill; + dataGridView.Location = new Point(0, 0); + dataGridView.Name = "dataGridView"; + dataGridView.RowHeadersWidth = 51; + dataGridView.RowTemplate.Height = 29; + dataGridView.Size = new Size(800, 450); + dataGridView.TabIndex = 0; + // + // FormMails + // + AutoScaleDimensions = new SizeF(8F, 20F); + AutoScaleMode = AutoScaleMode.Font; + ClientSize = new Size(800, 450); + Controls.Add(dataGridView); + Name = "FormMails"; + Text = "Письма"; + Load += FormMails_Load; + ((System.ComponentModel.ISupportInitialize)dataGridView).EndInit(); + ResumeLayout(false); + } + + #endregion + + private DataGridView dataGridView; + } +} \ No newline at end of file diff --git a/BlacksmithWorkshop/BlacksmithWorkshopView/FormMails.cs b/BlacksmithWorkshop/BlacksmithWorkshopView/FormMails.cs new file mode 100644 index 0000000..78327b4 --- /dev/null +++ b/BlacksmithWorkshop/BlacksmithWorkshopView/FormMails.cs @@ -0,0 +1,60 @@ +using BlacksmithWorkshopBusinessLogic.BusinessLogic; +using BlacksmithWorkshopContracts.BusinessLogicsContracts; +using Microsoft.Extensions.Logging; +using System; +using System.Collections.Generic; +using System.ComponentModel; +using System.Data; +using System.Drawing; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using System.Windows.Forms; + +namespace BlacksmithWorkshop +{ + public partial class FormMails : Form + { + private readonly ILogger _logger; + + private readonly IMessageInfoLogic _messageLogic; + + public FormMails(ILogger logger, IMessageInfoLogic messageLogic) + { + InitializeComponent(); + + _logger = logger; + _messageLogic = messageLogic; + } + + private void FormMails_Load(object sender, EventArgs e) + { + LoadData(); + } + + private void LoadData() + { + _logger.LogInformation("Загрузка писем"); + + try + { + var list = _messageLogic.ReadList(null); + + if (list != null) + { + dataGridView.DataSource = list; + dataGridView.Columns["MessageId"].Visible = false; + dataGridView.Columns["ClientId"].Visible = false; + dataGridView.Columns["Body"].AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill; + } + + _logger.LogInformation("Успешная загрузка писем"); + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка загрузки писем"); + MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + } + } +} \ No newline at end of file diff --git a/BlacksmithWorkshop/BlacksmithWorkshopView/FormMails.resx b/BlacksmithWorkshop/BlacksmithWorkshopView/FormMails.resx new file mode 100644 index 0000000..1af7de1 --- /dev/null +++ b/BlacksmithWorkshop/BlacksmithWorkshopView/FormMails.resx @@ -0,0 +1,120 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + text/microsoft-resx + + + 2.0 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + \ No newline at end of file diff --git a/BlacksmithWorkshop/BlacksmithWorkshopView/Program.cs b/BlacksmithWorkshop/BlacksmithWorkshopView/Program.cs index 18be6f5..aa288e5 100644 --- a/BlacksmithWorkshop/BlacksmithWorkshopView/Program.cs +++ b/BlacksmithWorkshop/BlacksmithWorkshopView/Program.cs @@ -1,6 +1,8 @@ using BlacksmithWorkshopBusinessLogic.BusinessLogic; +using BlacksmithWorkshopBusinessLogic.MailWorker; using BlacksmithWorkshopBusinessLogic.OfficePackage; using BlacksmithWorkshopBusinessLogic.OfficePackage.Implements; +using BlacksmithWorkshopContracts.BindingModels; using BlacksmithWorkshopContracts.BusinessLogicsContracts; using BlacksmithWorkshopContracts.StoragesContracts; using BlacksmithWorkshopDatabaseImplement.Implements; @@ -28,6 +30,31 @@ namespace BlacksmithWorkshop var services = new ServiceCollection(); ConfigureServices(services); _serviceProvider = services.BuildServiceProvider(); + + try + { + var mailSender = _serviceProvider.GetService(); + mailSender?.MailConfig(new MailConfigBindingModel + { + MailLogin = System.Configuration.ConfigurationManager.AppSettings["MailLogin"] ?? string.Empty, + MailPassword = System.Configuration.ConfigurationManager.AppSettings["MailPassword"] ?? string.Empty, + SmtpClientHost = System.Configuration.ConfigurationManager.AppSettings["SmtpClientHost"] ?? string.Empty, + SmtpClientPort = Convert.ToInt32(System.Configuration.ConfigurationManager.AppSettings["SmtpClientPort"]), + PopHost = System.Configuration.ConfigurationManager.AppSettings["PopHost"] ?? string.Empty, + PopPort = Convert.ToInt32(System.Configuration.ConfigurationManager.AppSettings["PopPort"]) + }); + + // <20><> <20><> + var timer = new System.Threading.Timer(new TimerCallback(MailCheck!), null, 0, 100000); + } + catch (Exception ex) + { + var logger = _serviceProvider.GetService(); + + logger?.LogError(ex, "<22><> <20><> <20> <20><>"); + } + + Application.Run(_serviceProvider.GetRequiredService()); } @@ -44,6 +71,7 @@ namespace BlacksmithWorkshop services.AddTransient(); services.AddTransient(); services.AddTransient(); + services.AddTransient(); services.AddTransient(); services.AddTransient(); @@ -51,12 +79,15 @@ namespace BlacksmithWorkshop services.AddTransient(); services.AddTransient(); services.AddTransient(); - services.AddTransient(); + services.AddTransient(); services.AddTransient(); services.AddTransient(); services.AddTransient(); + services.AddTransient(); + services.AddSingleton(); + services.AddTransient(); services.AddTransient(); services.AddTransient(); @@ -65,10 +96,13 @@ namespace BlacksmithWorkshop services.AddTransient(); services.AddTransient(); services.AddTransient(); - services.AddTransient(); + services.AddTransient( ); services.AddTransient(); services.AddTransient(); services.AddTransient(); + services.AddTransient(); } + + private static void MailCheck(object obj) => ServiceProvider?.GetService()?.MailCheck(); } } \ No newline at end of file