diff --git a/FurnitureAssembly/FurnitureAssembly/App.config b/FurnitureAssembly/FurnitureAssembly/App.config index 2b5efdc..f04ac32 100644 --- a/FurnitureAssembly/FurnitureAssembly/App.config +++ b/FurnitureAssembly/FurnitureAssembly/App.config @@ -1,11 +1,11 @@  - - - + + + - - + + \ No newline at end of file diff --git a/FurnitureAssembly/FurnitureAssembly/FormMails.Designer.cs b/FurnitureAssembly/FurnitureAssembly/FormMails.Designer.cs index b9fa09f..5a6274c 100644 --- a/FurnitureAssembly/FurnitureAssembly/FormMails.Designer.cs +++ b/FurnitureAssembly/FurnitureAssembly/FormMails.Designer.cs @@ -28,12 +28,42 @@ /// private void InitializeComponent() { - this.components = new System.ComponentModel.Container(); - this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; - this.ClientSize = new System.Drawing.Size(800, 450); - this.Text = "FormMails"; + dataGridView = new DataGridView(); + ((System.ComponentModel.ISupportInitialize)dataGridView).BeginInit(); + SuspendLayout(); + // + // dataGridView + // + dataGridView.AllowUserToAddRows = false; + dataGridView.AllowUserToDeleteRows = false; + dataGridView.Anchor = AnchorStyles.Top | AnchorStyles.Bottom | AnchorStyles.Left | AnchorStyles.Right; + dataGridView.AutoSizeColumnsMode = DataGridViewAutoSizeColumnsMode.Fill; + dataGridView.ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.AutoSize; + dataGridView.Location = new Point(13, 1); + dataGridView.Margin = new Padding(4, 2, 4, 2); + dataGridView.Name = "dataGridView"; + dataGridView.RowHeadersVisible = false; + dataGridView.RowHeadersWidth = 82; + dataGridView.RowTemplate.Height = 41; + dataGridView.SelectionMode = DataGridViewSelectionMode.FullRowSelect; + dataGridView.Size = new Size(1351, 789); + dataGridView.TabIndex = 2; + // + // FormMails + // + AutoScaleDimensions = new SizeF(13F, 32F); + AutoScaleMode = AutoScaleMode.Font; + ClientSize = new Size(1526, 795); + Controls.Add(dataGridView); + Name = "FormMails"; + Text = "FormMails"; + Load += FormMails_Load; + ((System.ComponentModel.ISupportInitialize)dataGridView).EndInit(); + ResumeLayout(false); } #endregion + + private DataGridView dataGridView; } } \ No newline at end of file diff --git a/FurnitureAssembly/FurnitureAssembly/FormMails.cs b/FurnitureAssembly/FurnitureAssembly/FormMails.cs index 126ef45..ec66672 100644 --- a/FurnitureAssembly/FurnitureAssembly/FormMails.cs +++ b/FurnitureAssembly/FurnitureAssembly/FormMails.cs @@ -1,4 +1,6 @@ -using System; +using FurnitureAssemblyContracts.BusinessLogicsContracts; +using Microsoft.Extensions.Logging; +using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; @@ -12,9 +14,46 @@ namespace FurnitureAssemblyView { public partial class FormMails : Form { - public FormMails() + 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); + } } } } diff --git a/FurnitureAssembly/FurnitureAssembly/FormMails.resx b/FurnitureAssembly/FurnitureAssembly/FormMails.resx index 1af7de1..af32865 100644 --- a/FurnitureAssembly/FurnitureAssembly/FormMails.resx +++ b/FurnitureAssembly/FurnitureAssembly/FormMails.resx @@ -1,17 +1,17 @@  - diff --git a/FurnitureAssembly/FurnitureAssembly/FormMain.Designer.cs b/FurnitureAssembly/FurnitureAssembly/FormMain.Designer.cs index 2c0dd88..3944542 100644 --- a/FurnitureAssembly/FurnitureAssembly/FormMain.Designer.cs +++ b/FurnitureAssembly/FurnitureAssembly/FormMain.Designer.cs @@ -34,6 +34,7 @@ мебельToolStripMenuItem = new ToolStripMenuItem(); клиентыToolStripMenuItem = new ToolStripMenuItem(); исполнителиToolStripMenuItem = new ToolStripMenuItem(); + письмаToolStripMenuItem = new ToolStripMenuItem(); отчетыToolStripMenuItem = new ToolStripMenuItem(); списокМебелиToolStripMenuItem = new ToolStripMenuItem(); компонентыПоИзделиямToolStripMenuItem = new ToolStripMenuItem(); @@ -53,78 +54,84 @@ menuStrip1.Items.AddRange(new ToolStripItem[] { справочникиToolStripMenuItem, отчетыToolStripMenuItem, запускРаботToolStripMenuItem }); menuStrip1.Location = new Point(0, 0); menuStrip1.Name = "menuStrip1"; - menuStrip1.Padding = new Padding(3, 1, 0, 1); - menuStrip1.Size = new Size(878, 24); + menuStrip1.Size = new Size(1631, 42); menuStrip1.TabIndex = 0; menuStrip1.Text = "menuStrip1"; // // справочникиToolStripMenuItem // - справочникиToolStripMenuItem.DropDownItems.AddRange(new ToolStripItem[] { заготовкиToolStripMenuItem, мебельToolStripMenuItem, клиентыToolStripMenuItem, исполнителиToolStripMenuItem }); + справочникиToolStripMenuItem.DropDownItems.AddRange(new ToolStripItem[] { заготовкиToolStripMenuItem, мебельToolStripMenuItem, клиентыToolStripMenuItem, исполнителиToolStripMenuItem, письмаToolStripMenuItem }); справочникиToolStripMenuItem.Name = "справочникиToolStripMenuItem"; - справочникиToolStripMenuItem.Size = new Size(94, 22); + справочникиToolStripMenuItem.Size = new Size(184, 38); справочникиToolStripMenuItem.Text = "Справочники"; // // заготовкиToolStripMenuItem // заготовкиToolStripMenuItem.Name = "заготовкиToolStripMenuItem"; - заготовкиToolStripMenuItem.Size = new Size(149, 22); + заготовкиToolStripMenuItem.Size = new Size(359, 44); заготовкиToolStripMenuItem.Text = "Заготовки"; заготовкиToolStripMenuItem.Click += заготовкиToolStripMenuItem_Click; // // мебельToolStripMenuItem // мебельToolStripMenuItem.Name = "мебельToolStripMenuItem"; - мебельToolStripMenuItem.Size = new Size(149, 22); + мебельToolStripMenuItem.Size = new Size(359, 44); мебельToolStripMenuItem.Text = "Мебель"; мебельToolStripMenuItem.Click += мебельToolStripMenuItem_Click; // // клиентыToolStripMenuItem // клиентыToolStripMenuItem.Name = "клиентыToolStripMenuItem"; - клиентыToolStripMenuItem.Size = new Size(149, 22); + клиентыToolStripMenuItem.Size = new Size(359, 44); клиентыToolStripMenuItem.Text = "Клиенты"; клиентыToolStripMenuItem.Click += ClientsToolStripMenuItem_Click; // // исполнителиToolStripMenuItem // исполнителиToolStripMenuItem.Name = "исполнителиToolStripMenuItem"; - исполнителиToolStripMenuItem.Size = new Size(149, 22); + исполнителиToolStripMenuItem.Size = new Size(359, 44); исполнителиToolStripMenuItem.Text = "Исполнители"; исполнителиToolStripMenuItem.Click += ImplementersToolStripMenuItem_Click; // + // письмаToolStripMenuItem + // + письмаToolStripMenuItem.Name = "письмаToolStripMenuItem"; + письмаToolStripMenuItem.Size = new Size(359, 44); + письмаToolStripMenuItem.Text = "Письма"; + письмаToolStripMenuItem.Click += MailsToolStripMenuItem_Click; + // // отчетыToolStripMenuItem // отчетыToolStripMenuItem.DropDownItems.AddRange(new ToolStripItem[] { списокМебелиToolStripMenuItem, компонентыПоИзделиямToolStripMenuItem, списокЗаказовToolStripMenuItem }); отчетыToolStripMenuItem.Name = "отчетыToolStripMenuItem"; - отчетыToolStripMenuItem.Size = new Size(60, 22); + отчетыToolStripMenuItem.Size = new Size(116, 38); отчетыToolStripMenuItem.Text = "Отчеты"; // // списокМебелиToolStripMenuItem // списокМебелиToolStripMenuItem.Name = "списокМебелиToolStripMenuItem"; - списокМебелиToolStripMenuItem.Size = new Size(218, 22); + списокМебелиToolStripMenuItem.Size = new Size(437, 44); списокМебелиToolStripMenuItem.Text = "Список мебели"; списокМебелиToolStripMenuItem.Click += FurnituresToolStripMenuItem_Click; // // компонентыПоИзделиямToolStripMenuItem // компонентыПоИзделиямToolStripMenuItem.Name = "компонентыПоИзделиямToolStripMenuItem"; - компонентыПоИзделиямToolStripMenuItem.Size = new Size(218, 22); + компонентыПоИзделиямToolStripMenuItem.Size = new Size(437, 44); компонентыПоИзделиямToolStripMenuItem.Text = "Компоненты по изделиям"; компонентыПоИзделиямToolStripMenuItem.Click += FurnituresComponentsToolStripMenuItem_Click; // // списокЗаказовToolStripMenuItem // списокЗаказовToolStripMenuItem.Name = "списокЗаказовToolStripMenuItem"; - списокЗаказовToolStripMenuItem.Size = new Size(218, 22); + списокЗаказовToolStripMenuItem.Size = new Size(437, 44); списокЗаказовToolStripMenuItem.Text = "Список заказов"; списокЗаказовToolStripMenuItem.Click += OrdersToolStripMenuItem_Click; // // запускРаботToolStripMenuItem // запускРаботToolStripMenuItem.Name = "запускРаботToolStripMenuItem"; - запускРаботToolStripMenuItem.Size = new Size(92, 22); + запускРаботToolStripMenuItem.Size = new Size(179, 38); запускРаботToolStripMenuItem.Text = "Запуск работ"; запускРаботToolStripMenuItem.Click += doWorkToolStripMenuItem_Click; // @@ -135,23 +142,23 @@ dataGridView.Anchor = AnchorStyles.Top | AnchorStyles.Bottom | AnchorStyles.Left | AnchorStyles.Right; dataGridView.AutoSizeColumnsMode = DataGridViewAutoSizeColumnsMode.Fill; dataGridView.ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.AutoSize; - dataGridView.Location = new Point(0, 30); - dataGridView.Margin = new Padding(2, 1, 2, 1); + dataGridView.Location = new Point(0, 64); + dataGridView.Margin = new Padding(4, 2, 4, 2); dataGridView.Name = "dataGridView"; dataGridView.RowHeadersVisible = false; dataGridView.RowHeadersWidth = 82; dataGridView.RowTemplate.Height = 41; dataGridView.SelectionMode = DataGridViewSelectionMode.FullRowSelect; - dataGridView.Size = new Size(666, 248); + dataGridView.Size = new Size(1237, 529); dataGridView.TabIndex = 1; // // ButtonCreateOrder // ButtonCreateOrder.Anchor = AnchorStyles.Top | AnchorStyles.Right; - ButtonCreateOrder.Location = new Point(682, 30); - ButtonCreateOrder.Margin = new Padding(2, 1, 2, 1); + ButtonCreateOrder.Location = new Point(1267, 64); + ButtonCreateOrder.Margin = new Padding(4, 2, 4, 2); ButtonCreateOrder.Name = "ButtonCreateOrder"; - ButtonCreateOrder.Size = new Size(180, 22); + ButtonCreateOrder.Size = new Size(334, 47); ButtonCreateOrder.TabIndex = 2; ButtonCreateOrder.Text = "Создать заказ"; ButtonCreateOrder.UseVisualStyleBackColor = true; @@ -160,10 +167,10 @@ // ButtonIssuedOrder // ButtonIssuedOrder.Anchor = AnchorStyles.Top | AnchorStyles.Right; - ButtonIssuedOrder.Location = new Point(682, 67); - ButtonIssuedOrder.Margin = new Padding(2, 1, 2, 1); + ButtonIssuedOrder.Location = new Point(1267, 143); + ButtonIssuedOrder.Margin = new Padding(4, 2, 4, 2); ButtonIssuedOrder.Name = "ButtonIssuedOrder"; - ButtonIssuedOrder.Size = new Size(180, 22); + ButtonIssuedOrder.Size = new Size(334, 47); ButtonIssuedOrder.TabIndex = 5; ButtonIssuedOrder.Text = "Заказ выдан"; ButtonIssuedOrder.UseVisualStyleBackColor = true; @@ -172,10 +179,10 @@ // ButtonRef // ButtonRef.Anchor = AnchorStyles.Top | AnchorStyles.Right; - ButtonRef.Location = new Point(682, 107); - ButtonRef.Margin = new Padding(2, 1, 2, 1); + ButtonRef.Location = new Point(1267, 228); + ButtonRef.Margin = new Padding(4, 2, 4, 2); ButtonRef.Name = "ButtonRef"; - ButtonRef.Size = new Size(180, 22); + ButtonRef.Size = new Size(334, 47); ButtonRef.TabIndex = 6; ButtonRef.Text = "Обновить список"; ButtonRef.UseVisualStyleBackColor = true; @@ -183,16 +190,16 @@ // // FormMain // - AutoScaleDimensions = new SizeF(7F, 15F); + AutoScaleDimensions = new SizeF(13F, 32F); AutoScaleMode = AutoScaleMode.Font; - ClientSize = new Size(878, 278); + ClientSize = new Size(1631, 593); Controls.Add(ButtonRef); Controls.Add(ButtonIssuedOrder); Controls.Add(ButtonCreateOrder); Controls.Add(dataGridView); Controls.Add(menuStrip1); MainMenuStrip = menuStrip1; - Margin = new Padding(2, 1, 2, 1); + Margin = new Padding(4, 2, 4, 2); Name = "FormMain"; Text = "Сборка мебели"; Load += MainForm_Load; @@ -220,5 +227,6 @@ private ToolStripMenuItem клиентыToolStripMenuItem; private ToolStripMenuItem исполнителиToolStripMenuItem; private ToolStripMenuItem запускРаботToolStripMenuItem; + private ToolStripMenuItem письмаToolStripMenuItem; } } \ No newline at end of file diff --git a/FurnitureAssembly/FurnitureAssembly/FormMain.cs b/FurnitureAssembly/FurnitureAssembly/FormMain.cs index 2c6203d..0387773 100644 --- a/FurnitureAssembly/FurnitureAssembly/FormMain.cs +++ b/FurnitureAssembly/FurnitureAssembly/FormMain.cs @@ -257,5 +257,14 @@ namespace FurnitureAssemblyView Program.ServiceProvider?.GetService(typeof(IImplementerLogic)) as IImplementerLogic)!, _orderLogic); } + private void MailsToolStripMenuItem_Click(object sender, EventArgs e) + { + var service = Program.ServiceProvider?.GetService(typeof(FormMails)); + + if (service is FormMails form) + { + form.ShowDialog(); + } + } } } diff --git a/FurnitureAssembly/FurnitureAssembly/FormMain.resx b/FurnitureAssembly/FurnitureAssembly/FormMain.resx index 5203d24..a0623c8 100644 --- a/FurnitureAssembly/FurnitureAssembly/FormMain.resx +++ b/FurnitureAssembly/FurnitureAssembly/FormMain.resx @@ -18,7 +18,7 @@ System.Resources.ResXResourceReader, System.Windows.Forms, ... System.Resources.ResXResourceWriter, System.Windows.Forms, ... this is my long stringthis is a comment - Blue + Blue [base64 mime encoded serialized .NET Framework object] diff --git a/FurnitureAssembly/FurnitureAssemblyBusinessLogic/BusinessLogic/OrderLogic.cs b/FurnitureAssembly/FurnitureAssemblyBusinessLogic/BusinessLogic/OrderLogic.cs index 3dbee2b..a577108 100644 --- a/FurnitureAssembly/FurnitureAssemblyBusinessLogic/BusinessLogic/OrderLogic.cs +++ b/FurnitureAssembly/FurnitureAssemblyBusinessLogic/BusinessLogic/OrderLogic.cs @@ -1,4 +1,5 @@ -using FurnitureAssemblyContracts.BindingModels; +using FurnitureAssemblyBusinessLogic.MailWorker; +using FurnitureAssemblyContracts.BindingModels; using FurnitureAssemblyContracts.BusinessLogicsContracts; using FurnitureAssemblyContracts.SearchModels; using FurnitureAssemblyContracts.StoragesContracts; @@ -17,22 +18,39 @@ namespace FurnitureAssemblyBusinessLogic.BusinessLogic { private readonly ILogger _logger; private readonly IOrderStorage _orderStorage; - public OrderLogic(ILogger logger, IOrderStorage orderStorage) + private readonly AbstractMailWorker _mailWorker; + private readonly IClientLogic _clientLogic; + private readonly object locker = new object(); + public OrderLogic(ILogger logger, IOrderStorage orderStorage, AbstractMailWorker mailWorker, IClientLogic clientLogic) { _logger = logger; _orderStorage = orderStorage; + _mailWorker = mailWorker; + _clientLogic = clientLogic; } public bool CreateOrder(OrderBindingModel model) { CheckModel(model); - if (model.Status != OrderStatus.Неизвестен) return false; - model.Status = OrderStatus.Принят; - if (_orderStorage.Insert(model) == null) + + if (model.Status != OrderStatus.Неизвестен) { + _logger.LogWarning("Insert operation failed, incorrect order status"); + return false; + } + + model.Status = OrderStatus.Принят; + + var result = _orderStorage.Insert(model); + + if (result == null) + { + model.Status = OrderStatus.Неизвестен; _logger.LogWarning("Insert operation failed"); return false; } + + SendOrderMessage(result.ClientId, $"Сборка мебели, Заказ №{result.Id}", $"Заказ №{result.Id} от {result.DateCreate} на сумму {result.Sum:0.00} принят"); return true; } @@ -50,28 +68,43 @@ namespace FurnitureAssemblyBusinessLogic.BusinessLogic } if (viewModel.Status + 1 != newStatus) { - _logger.LogWarning("Change status operation failed"); + _logger.LogWarning("Status update operation failed. New status " + newStatus.ToString() + "incorrect"); return false; } + model.Status = newStatus; model.FurnitureId = viewModel.FurnitureId; model.Count = viewModel.Count; model.Sum = viewModel.Sum; model.DateCreate = viewModel.DateCreate; - if (model.Status == OrderStatus.Готов) + if (viewModel.ImplementerId.HasValue) { - model.DateImplement = DateTime.Now.ToUniversalTime(); + model.ImplementerId = viewModel.ImplementerId; + } + + if (model.Status == OrderStatus.Выдан) + { + model.DateImplement = DateTime.Now; } else { model.DateImplement = viewModel.DateImplement; } - CheckModel(model); - if (_orderStorage.Update(model) == null) + + CheckModel(model, false); + var result = _orderStorage.Update(model); + + if (result == null) { - _logger.LogWarning("Change status operation failed"); + model.Status--; + + _logger.LogWarning("Update operation failed"); + return false; } + + SendOrderMessage(result.ClientId, $"Сборка мебели, Заказ №{result.Id}", $"Заказ №{model.Id} изменен статус на {result.Status}"); + return true; } @@ -143,5 +176,23 @@ namespace FurnitureAssemblyBusinessLogic.BusinessLogic _logger.LogInformation("ReadElement find. Id:{Id}", element.Id); return element; } + private bool SendOrderMessage(int clientId, string subject, string text) + { + var client = _clientLogic.ReadElement(new() { Id = clientId }); + + if (client == null) + { + return false; + } + + _mailWorker.MailSendAsync(new() + { + MailAddress = client.Email, + Subject = subject, + Text = text + }); + + return true; + } } } diff --git a/FurnitureAssembly/FurnitureAssemblyClientApp/Views/Home/Mails.cshtml b/FurnitureAssembly/FurnitureAssemblyClientApp/Views/Home/Mails.cshtml index da24305..588abf9 100644 --- a/FurnitureAssembly/FurnitureAssemblyClientApp/Views/Home/Mails.cshtml +++ b/FurnitureAssembly/FurnitureAssemblyClientApp/Views/Home/Mails.cshtml @@ -7,7 +7,7 @@ }
-

Заказы

+

Письма

@{ diff --git a/FurnitureAssembly/FurnitureAssemblyDatabaseImplement/FurnitureAssemblyDatabase.cs b/FurnitureAssembly/FurnitureAssemblyDatabaseImplement/FurnitureAssemblyDatabase.cs index 9cb9ac0..88f9432 100644 --- a/FurnitureAssembly/FurnitureAssemblyDatabaseImplement/FurnitureAssemblyDatabase.cs +++ b/FurnitureAssembly/FurnitureAssemblyDatabaseImplement/FurnitureAssemblyDatabase.cs @@ -16,6 +16,8 @@ namespace FurnitureAssemblyDatabaseImplement if (optionsBuilder.IsConfigured == false) { optionsBuilder.UseNpgsql("Host=localhost;Database=FurnitureAssemblyDatabaseFull;Username=postgres;Password=postgres"); + AppContext.SetSwitch("Npgsql.EnableLegacyTimestampBehavior", true); + AppContext.SetSwitch("Npgsql.DisableDateTimeInfinityConversions", true); } base.OnConfiguring(optionsBuilder); diff --git a/FurnitureAssembly/FurnitureAssemblyDatabaseImplement/Implements/ClientStorage.cs b/FurnitureAssembly/FurnitureAssemblyDatabaseImplement/Implements/ClientStorage.cs index 520c7a0..0de7a1f 100644 --- a/FurnitureAssembly/FurnitureAssemblyDatabaseImplement/Implements/ClientStorage.cs +++ b/FurnitureAssembly/FurnitureAssemblyDatabaseImplement/Implements/ClientStorage.cs @@ -29,38 +29,49 @@ namespace FurnitureAssemblyDatabaseImplement.Implements public ClientViewModel? GetElement(ClientSearchModel model) { - if (string.IsNullOrEmpty(model.Email) && !model.Id.HasValue) - { - return null; - } using var context = new FurnitureAssemblyDatabase(); - return context.Clients.FirstOrDefault(x => - (!string.IsNullOrEmpty(model.Email) && x.Email == model.Email) || - (model.Id.HasValue && x.Id == model.Id)) - ?.GetViewModel; - } + if (model.Id.HasValue) + { + return context.Clients + .Include(x => x.Orders) + .FirstOrDefault(x => x.Id == model.Id) + ?.GetViewModel; + } + + if (!string.IsNullOrEmpty(model.Email) && !string.IsNullOrEmpty(model.Password)) + { + return context.Clients + .Include(x => x.Orders) + .FirstOrDefault(x => (x.Email == model.Email && x.Password == model.Password)) + ?.GetViewModel; + } + + if (!string.IsNullOrEmpty(model.Email)) + return context.Clients + .FirstOrDefault(x => x.Email == model.Email) + ?.GetViewModel; + + return null; + } public List GetFilteredList(ClientSearchModel model) { - if (string.IsNullOrEmpty(model.Email) || string.IsNullOrEmpty(model.Password)) + if (string.IsNullOrEmpty(model.Email)) { return new(); } - using var context = new FurnitureAssemblyDatabase(); - return context.Clients - .Where(x => x.Email.Equals(model.Email) && x.Password.Equals(model.Password)) - .Select(x => x.GetViewModel) - .ToList(); - } + using var context = new FurnitureAssemblyDatabase(); + + return context.Clients + .Where(x => x.Email.Contains(model.Email)) + .Select(x => x.GetViewModel).ToList(); + } public List GetFullList() { using var context = new FurnitureAssemblyDatabase(); - return context.Clients - .Select(x => x.GetViewModel) - .ToList(); + return context.Clients.Select(x => x.GetViewModel).ToList(); } - public ClientViewModel? Insert(ClientBindingModel model) { var newClient = Client.Create(model); @@ -73,7 +84,6 @@ namespace FurnitureAssemblyDatabaseImplement.Implements context.SaveChanges(); return newClient.GetViewModel; } - public ClientViewModel? Update(ClientBindingModel model) { using var context = new FurnitureAssemblyDatabase(); diff --git a/FurnitureAssembly/FurnitureAssemblyDatabaseImplement/Migrations/20240516134544_lab07.Designer.cs b/FurnitureAssembly/FurnitureAssemblyDatabaseImplement/Migrations/20240516134544_lab07.Designer.cs new file mode 100644 index 0000000..8742fda --- /dev/null +++ b/FurnitureAssembly/FurnitureAssemblyDatabaseImplement/Migrations/20240516134544_lab07.Designer.cs @@ -0,0 +1,298 @@ +// +using System; +using FurnitureAssemblyDatabaseImplement; +using Microsoft.EntityFrameworkCore; +using Microsoft.EntityFrameworkCore.Infrastructure; +using Microsoft.EntityFrameworkCore.Migrations; +using Microsoft.EntityFrameworkCore.Storage.ValueConversion; +using Npgsql.EntityFrameworkCore.PostgreSQL.Metadata; + +#nullable disable + +namespace FurnitureAssemblyDatabaseImplement.Migrations +{ + [DbContext(typeof(FurnitureAssemblyDatabase))] + [Migration("20240516134544_lab07")] + partial class lab07 + { + /// + protected override void BuildTargetModel(ModelBuilder modelBuilder) + { +#pragma warning disable 612, 618 + modelBuilder + .HasAnnotation("ProductVersion", "7.0.3") + .HasAnnotation("Relational:MaxIdentifierLength", 63); + + NpgsqlModelBuilderExtensions.UseIdentityByDefaultColumns(modelBuilder); + + modelBuilder.Entity("FurnitureAssemblyDatabaseImplement.Models.Client", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("integer"); + + NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property("Id")); + + b.Property("ClientFIO") + .IsRequired() + .HasColumnType("text"); + + b.Property("Email") + .IsRequired() + .HasColumnType("text"); + + b.Property("Password") + .IsRequired() + .HasColumnType("text"); + + b.HasKey("Id"); + + b.ToTable("Clients"); + }); + + modelBuilder.Entity("FurnitureAssemblyDatabaseImplement.Models.Furniture", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("integer"); + + NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property("Id")); + + b.Property("FurnitureName") + .IsRequired() + .HasColumnType("text"); + + b.Property("Price") + .HasColumnType("double precision"); + + b.HasKey("Id"); + + b.ToTable("Furnitures"); + }); + + modelBuilder.Entity("FurnitureAssemblyDatabaseImplement.Models.FurnitureWorkpiece", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("integer"); + + NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property("Id")); + + b.Property("Count") + .HasColumnType("integer"); + + b.Property("FurnitureId") + .HasColumnType("integer"); + + b.Property("WorkpieceId") + .HasColumnType("integer"); + + b.HasKey("Id"); + + b.HasIndex("FurnitureId"); + + b.HasIndex("WorkpieceId"); + + b.ToTable("FurnitureWorkpieces"); + }); + + modelBuilder.Entity("FurnitureAssemblyDatabaseImplement.Models.Implementer", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("integer"); + + NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property("Id")); + + b.Property("ImplementerFIO") + .IsRequired() + .HasColumnType("text"); + + b.Property("Password") + .IsRequired() + .HasColumnType("text"); + + b.Property("Qualification") + .HasColumnType("integer"); + + b.Property("WorkExperience") + .HasColumnType("integer"); + + b.HasKey("Id"); + + b.ToTable("Implementers"); + }); + + modelBuilder.Entity("FurnitureAssemblyDatabaseImplement.Models.MessageInfo", b => + { + b.Property("MessageId") + .HasColumnType("text"); + + b.Property("Body") + .IsRequired() + .HasColumnType("text"); + + b.Property("ClientId") + .HasColumnType("integer"); + + b.Property("DateDelivery") + .HasColumnType("timestamp without time zone"); + + b.Property("SenderName") + .IsRequired() + .HasColumnType("text"); + + b.Property("Subject") + .IsRequired() + .HasColumnType("text"); + + b.HasKey("MessageId"); + + b.HasIndex("ClientId"); + + b.ToTable("Messages"); + }); + + modelBuilder.Entity("FurnitureAssemblyDatabaseImplement.Models.Order", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("integer"); + + NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property("Id")); + + b.Property("ClientId") + .HasColumnType("integer"); + + b.Property("Count") + .HasColumnType("integer"); + + b.Property("DateCreate") + .HasColumnType("timestamp without time zone"); + + b.Property("DateImplement") + .HasColumnType("timestamp without time zone"); + + b.Property("FurnitureId") + .HasColumnType("integer"); + + b.Property("ImplementerId") + .HasColumnType("integer"); + + b.Property("Status") + .HasColumnType("integer"); + + b.Property("Sum") + .HasColumnType("double precision"); + + b.HasKey("Id"); + + b.HasIndex("ClientId"); + + b.HasIndex("FurnitureId"); + + b.HasIndex("ImplementerId"); + + b.ToTable("Orders"); + }); + + modelBuilder.Entity("FurnitureAssemblyDatabaseImplement.Models.Workpiece", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("integer"); + + NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property("Id")); + + b.Property("Cost") + .HasColumnType("double precision"); + + b.Property("WorkpieceName") + .IsRequired() + .HasColumnType("text"); + + b.HasKey("Id"); + + b.ToTable("Workpieces"); + }); + + modelBuilder.Entity("FurnitureAssemblyDatabaseImplement.Models.FurnitureWorkpiece", b => + { + b.HasOne("FurnitureAssemblyDatabaseImplement.Models.Furniture", "Furniture") + .WithMany("Workpieces") + .HasForeignKey("FurnitureId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.HasOne("FurnitureAssemblyDatabaseImplement.Models.Workpiece", "Workpiece") + .WithMany("FurnitureWorkpieces") + .HasForeignKey("WorkpieceId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.Navigation("Furniture"); + + b.Navigation("Workpiece"); + }); + + modelBuilder.Entity("FurnitureAssemblyDatabaseImplement.Models.MessageInfo", b => + { + b.HasOne("FurnitureAssemblyDatabaseImplement.Models.Client", "Client") + .WithMany("Messages") + .HasForeignKey("ClientId"); + + b.Navigation("Client"); + }); + + modelBuilder.Entity("FurnitureAssemblyDatabaseImplement.Models.Order", b => + { + b.HasOne("FurnitureAssemblyDatabaseImplement.Models.Client", "Client") + .WithMany("Orders") + .HasForeignKey("ClientId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.HasOne("FurnitureAssemblyDatabaseImplement.Models.Furniture", "Furniture") + .WithMany("Orders") + .HasForeignKey("FurnitureId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.HasOne("FurnitureAssemblyDatabaseImplement.Models.Implementer", "Implementer") + .WithMany("Orders") + .HasForeignKey("ImplementerId"); + + b.Navigation("Client"); + + b.Navigation("Furniture"); + + b.Navigation("Implementer"); + }); + + modelBuilder.Entity("FurnitureAssemblyDatabaseImplement.Models.Client", b => + { + b.Navigation("Messages"); + + b.Navigation("Orders"); + }); + + modelBuilder.Entity("FurnitureAssemblyDatabaseImplement.Models.Furniture", b => + { + b.Navigation("Orders"); + + b.Navigation("Workpieces"); + }); + + modelBuilder.Entity("FurnitureAssemblyDatabaseImplement.Models.Implementer", b => + { + b.Navigation("Orders"); + }); + + modelBuilder.Entity("FurnitureAssemblyDatabaseImplement.Models.Workpiece", b => + { + b.Navigation("FurnitureWorkpieces"); + }); +#pragma warning restore 612, 618 + } + } +} diff --git a/FurnitureAssembly/FurnitureAssemblyDatabaseImplement/Migrations/20240516134544_lab07.cs b/FurnitureAssembly/FurnitureAssemblyDatabaseImplement/Migrations/20240516134544_lab07.cs new file mode 100644 index 0000000..b864723 --- /dev/null +++ b/FurnitureAssembly/FurnitureAssemblyDatabaseImplement/Migrations/20240516134544_lab07.cs @@ -0,0 +1,69 @@ +using System; +using Microsoft.EntityFrameworkCore.Migrations; + +#nullable disable + +namespace FurnitureAssemblyDatabaseImplement.Migrations +{ + /// + public partial class lab07 : Migration + { + /// + protected override void Up(MigrationBuilder migrationBuilder) + { + migrationBuilder.AlterColumn( + name: "DateImplement", + table: "Orders", + type: "timestamp without time zone", + nullable: true, + oldClrType: typeof(DateTime), + oldType: "timestamp with time zone", + oldNullable: true); + + migrationBuilder.AlterColumn( + name: "DateCreate", + table: "Orders", + type: "timestamp without time zone", + nullable: false, + oldClrType: typeof(DateTime), + oldType: "timestamp with time zone"); + + migrationBuilder.AlterColumn( + name: "DateDelivery", + table: "Messages", + type: "timestamp without time zone", + nullable: false, + oldClrType: typeof(DateTime), + oldType: "timestamp with time zone"); + } + + /// + protected override void Down(MigrationBuilder migrationBuilder) + { + migrationBuilder.AlterColumn( + name: "DateImplement", + table: "Orders", + type: "timestamp with time zone", + nullable: true, + oldClrType: typeof(DateTime), + oldType: "timestamp without time zone", + oldNullable: true); + + migrationBuilder.AlterColumn( + name: "DateCreate", + table: "Orders", + type: "timestamp with time zone", + nullable: false, + oldClrType: typeof(DateTime), + oldType: "timestamp without time zone"); + + migrationBuilder.AlterColumn( + name: "DateDelivery", + table: "Messages", + type: "timestamp with time zone", + nullable: false, + oldClrType: typeof(DateTime), + oldType: "timestamp without time zone"); + } + } +} diff --git a/FurnitureAssembly/FurnitureAssemblyDatabaseImplement/Migrations/FurnitureAssemblyDatabaseModelSnapshot.cs b/FurnitureAssembly/FurnitureAssemblyDatabaseImplement/Migrations/FurnitureAssemblyDatabaseModelSnapshot.cs index 5a2d1e1..7fbd3fd 100644 --- a/FurnitureAssembly/FurnitureAssemblyDatabaseImplement/Migrations/FurnitureAssemblyDatabaseModelSnapshot.cs +++ b/FurnitureAssembly/FurnitureAssemblyDatabaseImplement/Migrations/FurnitureAssemblyDatabaseModelSnapshot.cs @@ -133,7 +133,7 @@ namespace FurnitureAssemblyDatabaseImplement.Migrations .HasColumnType("integer"); b.Property("DateDelivery") - .HasColumnType("timestamp with time zone"); + .HasColumnType("timestamp without time zone"); b.Property("SenderName") .IsRequired() @@ -165,10 +165,10 @@ namespace FurnitureAssemblyDatabaseImplement.Migrations .HasColumnType("integer"); b.Property("DateCreate") - .HasColumnType("timestamp with time zone"); + .HasColumnType("timestamp without time zone"); b.Property("DateImplement") - .HasColumnType("timestamp with time zone"); + .HasColumnType("timestamp without time zone"); b.Property("FurnitureId") .HasColumnType("integer"); @@ -235,7 +235,7 @@ namespace FurnitureAssemblyDatabaseImplement.Migrations modelBuilder.Entity("FurnitureAssemblyDatabaseImplement.Models.MessageInfo", b => { b.HasOne("FurnitureAssemblyDatabaseImplement.Models.Client", "Client") - .WithMany() + .WithMany("Messages") .HasForeignKey("ClientId"); b.Navigation("Client"); @@ -244,7 +244,7 @@ namespace FurnitureAssemblyDatabaseImplement.Migrations modelBuilder.Entity("FurnitureAssemblyDatabaseImplement.Models.Order", b => { b.HasOne("FurnitureAssemblyDatabaseImplement.Models.Client", "Client") - .WithMany() + .WithMany("Orders") .HasForeignKey("ClientId") .OnDelete(DeleteBehavior.Cascade) .IsRequired(); @@ -266,6 +266,13 @@ namespace FurnitureAssemblyDatabaseImplement.Migrations b.Navigation("Implementer"); }); + modelBuilder.Entity("FurnitureAssemblyDatabaseImplement.Models.Client", b => + { + b.Navigation("Messages"); + + b.Navigation("Orders"); + }); + modelBuilder.Entity("FurnitureAssemblyDatabaseImplement.Models.Furniture", b => { b.Navigation("Orders"); diff --git a/FurnitureAssembly/FurnitureAssemblyDatabaseImplement/Models/Client.cs b/FurnitureAssembly/FurnitureAssemblyDatabaseImplement/Models/Client.cs index c7a5157..2f8a9ec 100644 --- a/FurnitureAssembly/FurnitureAssemblyDatabaseImplement/Models/Client.cs +++ b/FurnitureAssembly/FurnitureAssemblyDatabaseImplement/Models/Client.cs @@ -4,6 +4,7 @@ using FurnitureAssemblyDataModels.Models; using System; using System.Collections.Generic; using System.ComponentModel.DataAnnotations; +using System.ComponentModel.DataAnnotations.Schema; using System.Linq; using System.Text; using System.Threading.Tasks; @@ -19,6 +20,10 @@ namespace FurnitureAssemblyDatabaseImplement.Models public string Email { get; private set; } = string.Empty; [Required] public string Password { get; private set; } = string.Empty; + [ForeignKey("ClientId")] + public virtual List Orders { get; set; } = new(); + [ForeignKey("ClientId")] + public virtual List Messages { get; set; } = new(); public static Client? Create(ClientBindingModel model) { @@ -26,6 +31,7 @@ namespace FurnitureAssemblyDatabaseImplement.Models { return null; } + return new Client() { Id = model.Id, @@ -34,16 +40,6 @@ namespace FurnitureAssemblyDatabaseImplement.Models Password = model.Password }; } - public static Client Create(ClientViewModel model) - { - return new Client - { - Id = model.Id, - ClientFIO = model.ClientFIO, - Email = model.Email, - Password = model.Password - }; - } public void Update(ClientBindingModel model) { if (model == null) diff --git a/FurnitureAssembly/FurnitureAssemblyRestApi/appsettings.json b/FurnitureAssembly/FurnitureAssemblyRestApi/appsettings.json index 7013aed..023ce10 100644 --- a/FurnitureAssembly/FurnitureAssemblyRestApi/appsettings.json +++ b/FurnitureAssembly/FurnitureAssemblyRestApi/appsettings.json @@ -7,10 +7,10 @@ }, "AllowedHosts": "*", - "SmtpClientHost": "smtp.beget.com", - "SmtpClientPort": "465", - "PopHost": "pop.beget.com", + "SmtpClientHost": "smtp.gmail.com", + "SmtpClientPort": "587", + "PopHost": "pop.gmail.com", "PopPort": "995", - "MailLogin": "", - "MailPassword": "Fa0d*HzV" + "MailLogin": "@gmail.com", + "MailPassword": "gsmp yceu sztw iqid" }