ISEbd-21 Zinovev V.V. LabWork07_Base #8

Closed
vladimir_zinovev wants to merge 2 commits from lab07 into lab06
16 changed files with 637 additions and 118 deletions
Showing only changes of commit f78fa6e18c - Show all commits

View File

@ -1,11 +1,11 @@
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<appSettings>
<add key="SmtpClientHost" value="smtp.beget.com" />
<add key="SmtpClientPort" value="465" />
<add key="PopHost" value="pop3.beget.com" />
<add key="SmtpClientHost" value="smtp.gmail.com" />
<add key="SmtpClientPort" value="587" />
<add key="PopHost" value="pop.gmail.com" />
<add key="PopPort" value="995" />
<add key="MailLogin" value="" />
<add key="MailPassword" value= "Fa0d*HzV" />
<add key="MailLogin" value="@gmail.com" />
<add key="MailPassword" value= "gsmp yceu sztw iqid" />
</appSettings>
</configuration>

View File

@ -28,12 +28,42 @@
/// </summary>
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";
Review

Заголовок формы оформлен неверно

Заголовок формы оформлен неверно
Load += FormMails_Load;
((System.ComponentModel.ISupportInitialize)dataGridView).EndInit();
ResumeLayout(false);
}
#endregion
private DataGridView dataGridView;
}
}

View File

@ -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<FormMails> 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);
}
}
}
}

View File

@ -1,17 +1,17 @@
<?xml version="1.0" encoding="utf-8"?>
<root>
<!--
<!--
Microsoft ResX Schema
Version 2.0
The primary goals of this format is to allow a simple XML format
that is mostly human readable. The generation and parsing of the
various data types are done through the TypeConverter classes
The primary goals of this format is to allow a simple XML format
that is mostly human readable. The generation and parsing of the
various data types are done through the TypeConverter classes
associated with the data types.
Example:
... ado.net/XML headers & schema ...
<resheader name="resmimetype">text/microsoft-resx</resheader>
<resheader name="version">2.0</resheader>
@ -26,36 +26,36 @@
<value>[base64 mime encoded string representing a byte array form of the .NET Framework object]</value>
<comment>This is a comment</comment>
</data>
There are any number of "resheader" rows that contain simple
There are any number of "resheader" rows that contain simple
name/value pairs.
Each data row contains a name, and value. The row also contains a
type or mimetype. Type corresponds to a .NET class that support
text/value conversion through the TypeConverter architecture.
Classes that don't support this are serialized and stored with the
Each data row contains a name, and value. The row also contains a
type or mimetype. Type corresponds to a .NET class that support
text/value conversion through the TypeConverter architecture.
Classes that don't support this are serialized and stored with the
mimetype set.
The mimetype is used for serialized objects, and tells the
ResXResourceReader how to depersist the object. This is currently not
The mimetype is used for serialized objects, and tells the
ResXResourceReader how to depersist the object. This is currently not
extensible. For a given mimetype the value must be set accordingly:
Note - application/x-microsoft.net.object.binary.base64 is the format
that the ResXResourceWriter will generate, however the reader can
Note - application/x-microsoft.net.object.binary.base64 is the format
that the ResXResourceWriter will generate, however the reader can
read any of the formats listed below.
mimetype: application/x-microsoft.net.object.binary.base64
value : The object must be serialized with
value : The object must be serialized with
: System.Runtime.Serialization.Formatters.Binary.BinaryFormatter
: and then encoded with base64 encoding.
mimetype: application/x-microsoft.net.object.soap.base64
value : The object must be serialized with
value : The object must be serialized with
: System.Runtime.Serialization.Formatters.Soap.SoapFormatter
: and then encoded with base64 encoding.
mimetype: application/x-microsoft.net.object.bytearray.base64
value : The object must be serialized into a byte array
value : The object must be serialized into a byte array
: using a System.ComponentModel.TypeConverter
: and then encoded with base64 encoding.
-->

View File

@ -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;
}
}

View File

@ -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();
}
}
}
}

View File

@ -18,7 +18,7 @@
<resheader name="reader">System.Resources.ResXResourceReader, System.Windows.Forms, ...</resheader>
<resheader name="writer">System.Resources.ResXResourceWriter, System.Windows.Forms, ...</resheader>
<data name="Name1"><value>this is my long string</value><comment>this is a comment</comment></data>
<data name="Color1" type="System.Drawing.Color, System.Drawing"">Blue</data>
<data name="Color1" type="System.Drawing.Color, System.Drawing">Blue</data>
<data name="Bitmap1" mimetype="application/x-microsoft.net.object.binary.base64">
<value>[base64 mime encoded serialized .NET Framework object]</value>
</data>

View File

@ -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<OrderLogic> logger, IOrderStorage orderStorage)
private readonly AbstractMailWorker _mailWorker;
private readonly IClientLogic _clientLogic;
private readonly object locker = new object();
public OrderLogic(ILogger<OrderLogic> 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;
}
}
}

View File

@ -7,7 +7,7 @@
}
<div class="text-center">
<h1 class="display-4">Заказы</h1>
<h1 class="display-4">Письма</h1>
</div>
<div class="text-center">
@{

View File

@ -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);

View File

@ -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<ClientViewModel> 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<ClientViewModel> 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();

View File

@ -0,0 +1,298 @@
// <auto-generated />
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
{
/// <inheritdoc />
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<int>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("integer");
NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property<int>("Id"));
b.Property<string>("ClientFIO")
.IsRequired()
.HasColumnType("text");
b.Property<string>("Email")
.IsRequired()
.HasColumnType("text");
b.Property<string>("Password")
.IsRequired()
.HasColumnType("text");
b.HasKey("Id");
b.ToTable("Clients");
});
modelBuilder.Entity("FurnitureAssemblyDatabaseImplement.Models.Furniture", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("integer");
NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property<int>("Id"));
b.Property<string>("FurnitureName")
.IsRequired()
.HasColumnType("text");
b.Property<double>("Price")
.HasColumnType("double precision");
b.HasKey("Id");
b.ToTable("Furnitures");
});
modelBuilder.Entity("FurnitureAssemblyDatabaseImplement.Models.FurnitureWorkpiece", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("integer");
NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property<int>("Id"));
b.Property<int>("Count")
.HasColumnType("integer");
b.Property<int>("FurnitureId")
.HasColumnType("integer");
b.Property<int>("WorkpieceId")
.HasColumnType("integer");
b.HasKey("Id");
b.HasIndex("FurnitureId");
b.HasIndex("WorkpieceId");
b.ToTable("FurnitureWorkpieces");
});
modelBuilder.Entity("FurnitureAssemblyDatabaseImplement.Models.Implementer", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("integer");
NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property<int>("Id"));
b.Property<string>("ImplementerFIO")
.IsRequired()
.HasColumnType("text");
b.Property<string>("Password")
.IsRequired()
.HasColumnType("text");
b.Property<int>("Qualification")
.HasColumnType("integer");
b.Property<int>("WorkExperience")
.HasColumnType("integer");
b.HasKey("Id");
b.ToTable("Implementers");
});
modelBuilder.Entity("FurnitureAssemblyDatabaseImplement.Models.MessageInfo", b =>
{
b.Property<string>("MessageId")
.HasColumnType("text");
b.Property<string>("Body")
.IsRequired()
.HasColumnType("text");
b.Property<int?>("ClientId")
.HasColumnType("integer");
b.Property<DateTime>("DateDelivery")
.HasColumnType("timestamp without time zone");
b.Property<string>("SenderName")
.IsRequired()
.HasColumnType("text");
b.Property<string>("Subject")
.IsRequired()
.HasColumnType("text");
b.HasKey("MessageId");
b.HasIndex("ClientId");
b.ToTable("Messages");
});
modelBuilder.Entity("FurnitureAssemblyDatabaseImplement.Models.Order", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("integer");
NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property<int>("Id"));
b.Property<int>("ClientId")
.HasColumnType("integer");
b.Property<int>("Count")
.HasColumnType("integer");
b.Property<DateTime>("DateCreate")
.HasColumnType("timestamp without time zone");
b.Property<DateTime?>("DateImplement")
.HasColumnType("timestamp without time zone");
b.Property<int>("FurnitureId")
.HasColumnType("integer");
b.Property<int?>("ImplementerId")
.HasColumnType("integer");
b.Property<int>("Status")
.HasColumnType("integer");
b.Property<double>("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<int>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("integer");
NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property<int>("Id"));
b.Property<double>("Cost")
.HasColumnType("double precision");
b.Property<string>("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
}
}
}

View File

@ -0,0 +1,69 @@
using System;
using Microsoft.EntityFrameworkCore.Migrations;
#nullable disable
namespace FurnitureAssemblyDatabaseImplement.Migrations
{
/// <inheritdoc />
public partial class lab07 : Migration
{
/// <inheritdoc />
protected override void Up(MigrationBuilder migrationBuilder)
{
migrationBuilder.AlterColumn<DateTime>(
name: "DateImplement",
table: "Orders",
type: "timestamp without time zone",
nullable: true,
oldClrType: typeof(DateTime),
oldType: "timestamp with time zone",
oldNullable: true);
migrationBuilder.AlterColumn<DateTime>(
name: "DateCreate",
table: "Orders",
type: "timestamp without time zone",
nullable: false,
oldClrType: typeof(DateTime),
oldType: "timestamp with time zone");
migrationBuilder.AlterColumn<DateTime>(
name: "DateDelivery",
table: "Messages",
type: "timestamp without time zone",
nullable: false,
oldClrType: typeof(DateTime),
oldType: "timestamp with time zone");
}
/// <inheritdoc />
protected override void Down(MigrationBuilder migrationBuilder)
{
migrationBuilder.AlterColumn<DateTime>(
name: "DateImplement",
table: "Orders",
type: "timestamp with time zone",
nullable: true,
oldClrType: typeof(DateTime),
oldType: "timestamp without time zone",
oldNullable: true);
migrationBuilder.AlterColumn<DateTime>(
name: "DateCreate",
table: "Orders",
type: "timestamp with time zone",
nullable: false,
oldClrType: typeof(DateTime),
oldType: "timestamp without time zone");
migrationBuilder.AlterColumn<DateTime>(
name: "DateDelivery",
table: "Messages",
type: "timestamp with time zone",
nullable: false,
oldClrType: typeof(DateTime),
oldType: "timestamp without time zone");
}
}
}

View File

@ -133,7 +133,7 @@ namespace FurnitureAssemblyDatabaseImplement.Migrations
.HasColumnType("integer");
b.Property<DateTime>("DateDelivery")
.HasColumnType("timestamp with time zone");
.HasColumnType("timestamp without time zone");
b.Property<string>("SenderName")
.IsRequired()
@ -165,10 +165,10 @@ namespace FurnitureAssemblyDatabaseImplement.Migrations
.HasColumnType("integer");
b.Property<DateTime>("DateCreate")
.HasColumnType("timestamp with time zone");
.HasColumnType("timestamp without time zone");
b.Property<DateTime?>("DateImplement")
.HasColumnType("timestamp with time zone");
.HasColumnType("timestamp without time zone");
b.Property<int>("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");

View File

@ -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<Order> Orders { get; set; } = new();
[ForeignKey("ClientId")]
public virtual List<MessageInfo> 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)

View File

@ -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"
}