Сдано

This commit is contained in:
Yunusov_Niyaz 2024-04-18 11:16:56 +04:00
parent 2662170f28
commit 3d1fb5c067
17 changed files with 281 additions and 144 deletions

View File

@ -34,8 +34,12 @@
labelSushi = new Label();
labelClient = new Label();
labelEmployee = new Label();
labelSum = new Label();
textBoxCount = new TextBox();
textBoxSum = new TextBox();
buttonSave = new Button();
buttonCancel = new Button();
labelCount = new Label();
SuspendLayout();
//
// comboBoxSushi
@ -46,6 +50,8 @@
comboBoxSushi.Name = "comboBoxSushi";
comboBoxSushi.Size = new Size(353, 28);
comboBoxSushi.TabIndex = 0;
comboBoxSushi.SelectedIndexChanged += ComboBoxRepair_SelectedIndexChanged;
comboBoxSushi.Click += ComboBoxRepair_SelectedIndexChanged;
//
// comboBoxClient
//
@ -59,7 +65,7 @@
// comboBoxEmployee
//
comboBoxEmployee.DropDownStyle = ComboBoxStyle.DropDownList;
comboBoxEmployee.Location = new Point(130, 87);
comboBoxEmployee.Location = new Point(130, 123);
comboBoxEmployee.Name = "comboBoxEmployee";
comboBoxEmployee.Size = new Size(353, 28);
comboBoxEmployee.TabIndex = 8;
@ -69,9 +75,9 @@
labelSushi.AutoSize = true;
labelSushi.Location = new Point(21, 22);
labelSushi.Name = "labelSushi";
labelSushi.Size = new Size(54, 20);
labelSushi.Size = new Size(46, 20);
labelSushi.TabIndex = 3;
labelSushi.Text = "Услуга";
labelSushi.Text = "Суши";
//
// labelClient
//
@ -85,11 +91,38 @@
// labelEmployee
//
labelEmployee.AutoSize = true;
labelEmployee.Location = new Point(21, 90);
labelEmployee.Location = new Point(21, 123);
labelEmployee.Name = "labelEmployee";
labelEmployee.Size = new Size(60, 20);
labelEmployee.Size = new Size(80, 20);
labelEmployee.TabIndex = 3;
labelEmployee.Text = "Мастер";
labelEmployee.Text = "Официант";
//
// labelSum
//
labelSum.AutoSize = true;
labelSum.Location = new Point(306, 93);
labelSum.Name = "labelSum";
labelSum.Size = new Size(58, 20);
labelSum.TabIndex = 3;
labelSum.Text = "Сумма:";
//
// textBoxCount
//
textBoxCount.Location = new Point(130, 87);
textBoxCount.Name = "textBoxCount";
textBoxCount.Size = new Size(170, 27);
textBoxCount.TabIndex = 4;
textBoxCount.Click += TextBoxCount_TextChanged;
textBoxCount.TextChanged += TextBoxCount_TextChanged;
//
// textBoxSum
//
textBoxSum.Location = new Point(370, 90);
textBoxSum.Name = "textBoxSum";
textBoxSum.ReadOnly = true;
textBoxSum.Size = new Size(113, 27);
textBoxSum.TabIndex = 5;
textBoxSum.TextChanged += TextBoxSum_TextChanged;
//
// buttonSave
//
@ -111,15 +144,28 @@
buttonCancel.UseVisualStyleBackColor = true;
buttonCancel.Click += ButtonCancel_Click;
//
// FormCreateAppointment
// labelCount
//
labelCount.AutoSize = true;
labelCount.Location = new Point(21, 90);
labelCount.Name = "labelCount";
labelCount.Size = new Size(90, 20);
labelCount.TabIndex = 10;
labelCount.Text = "Количество";
//
// FormCreateOrder
//
AutoScaleDimensions = new SizeF(8F, 20F);
AutoScaleMode = AutoScaleMode.Font;
ClientSize = new Size(515, 202);
Controls.Add(labelCount);
Controls.Add(buttonCancel);
Controls.Add(buttonSave);
Controls.Add(labelSushi);
Controls.Add(comboBoxSushi);
Controls.Add(textBoxCount);
Controls.Add(textBoxSum);
Controls.Add(labelSum);
Controls.Add(labelEmployee);
Controls.Add(comboBoxEmployee);
Controls.Add(labelClient);
@ -139,7 +185,11 @@
private Label labelSushi;
private Label labelClient;
private Label labelEmployee;
private Label labelSum;
private TextBox textBoxCount;
private TextBox textBoxSum;
private Button buttonSave;
private Button buttonCancel;
private Label labelCount;
}
}

View File

@ -62,59 +62,59 @@ namespace Sushi
MessageBoxIcon.Error);
}
}
//private void CalcSum()
//{
// if (comboBoxRepair.SelectedValue != null &&
// !string.IsNullOrEmpty(textBoxCount.Text))
// {
// try
// {
// int id = Convert.ToInt32(comboBoxRepair.SelectedValue);
// var repair = _logicS.ReadElement(new SushiSearchModel
// {
// Id
// = id
// });
// int count = Convert.ToInt32(textBoxCount.Text);
// textBoxSum.Text = Math.Round(count * (repair?.Price ?? 0),
// 2).ToString();
// _logger.LogInformation("Расчет суммы заказа");
// }
// catch (Exception ex)
// {
// _logger.LogError(ex, "Ошибка расчета суммы заказа");
// MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK,
// MessageBoxIcon.Error);
// }
// }
//}
//private void TextBoxCount_TextChanged(object sender, EventArgs e)
//{
// CalcSum();
//}
//private void TextBoxSum_TextChanged(object sender, EventArgs e)
//{
// CalcSum();
//}
//private void ComboBoxRepair_SelectedIndexChanged(object sender, EventArgs e)
//{
// CalcSum();
//}
private void CalcSum()
{
if (comboBoxSushi.SelectedValue != null &&
!string.IsNullOrEmpty(textBoxCount.Text))
{
try
{
int id = Convert.ToInt32(comboBoxSushi.SelectedValue);
var repair = _logicS.ReadElement(new SushiSearchModel
{
Id = id
});
int count = Convert.ToInt32(textBoxCount.Text);
textBoxSum.Text = Math.Round(count * (repair?.Price ?? 0), 2).ToString();
_logger.LogInformation("Расчет суммы заказа");
}
catch (Exception ex)
{
_logger.LogError(ex, "Ошибка расчета суммы заказа");
MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK,
MessageBoxIcon.Error);
}
}
}
private void TextBoxCount_TextChanged(object sender, EventArgs e)
{
CalcSum();
}
private void TextBoxSum_TextChanged(object sender, EventArgs e)
{
CalcSum();
}
private void ComboBoxRepair_SelectedIndexChanged(object sender, EventArgs e)
{
CalcSum();
}
private void ButtonSave_Click(object sender, EventArgs e)
{
if (comboBoxSushi.SelectedValue == null || comboBoxClient.SelectedValue == null || comboBoxEmployee.SelectedValue == null)
{
MessageBox.Show("Выберите компьютер", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
MessageBox.Show("Выберите блюдо", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
return;
}
_logger.LogInformation("Создание заказа");
try
{
var operationResult = _logicO.Create(new OrderBindingModel
var operationResult = _logicO.CreateOrder(new OrderBindingModel
{
SushiId = Convert.ToInt32(comboBoxSushi.SelectedValue),
ClientId = Convert.ToInt32(comboBoxClient.SelectedValue),
EmployeeId = Convert.ToInt32(comboBoxEmployee.SelectedValue),
Count = Convert.ToInt32(textBoxCount.Text),
Sum = Convert.ToDouble(textBoxSum.Text),
Time = DateTime.UtcNow
});
if (!operationResult)

View File

@ -49,7 +49,7 @@
menuStrip.Items.AddRange(new ToolStripItem[] { справочникиToolStripMenuItem });
menuStrip.Location = new Point(0, 0);
menuStrip.Name = "menuStrip";
menuStrip.Size = new Size(1209, 28);
menuStrip.Size = new Size(1547, 28);
menuStrip.TabIndex = 0;
menuStrip.Text = "Меню справочников";
//
@ -85,7 +85,7 @@
//
мастераToolStripMenuItem.Name = астераToolStripMenuItem";
мастераToolStripMenuItem.Size = new Size(224, 26);
мастераToolStripMenuItem.Text = "Мастера";
мастераToolStripMenuItem.Text = "Официант";
мастераToolStripMenuItem.Click += EmployeesStripMenuItem_Click;
//
// dataGridView
@ -95,12 +95,12 @@
dataGridView.Name = "dataGridView";
dataGridView.RowHeadersWidth = 51;
dataGridView.RowTemplate.Height = 29;
dataGridView.Size = new Size(970, 419);
dataGridView.Size = new Size(1235, 419);
dataGridView.TabIndex = 1;
//
// buttonCreate
//
buttonCreate.Location = new Point(999, 46);
buttonCreate.Location = new Point(1309, 55);
buttonCreate.Name = "buttonCreate";
buttonCreate.Size = new Size(187, 37);
buttonCreate.TabIndex = 2;
@ -110,27 +110,25 @@
//
// buttonUpdate
//
buttonUpdate.Location = new Point(999, 123);
buttonUpdate.Location = new Point(1309, 136);
buttonUpdate.Name = "buttonUpdate";
buttonUpdate.Size = new Size(187, 37);
buttonUpdate.TabIndex = 3;
buttonUpdate.Text = "Отдать на выполнение";
buttonUpdate.UseVisualStyleBackColor = true;
buttonUpdate.Click += ButtonUpd_Click;
//
// buttonDelete
//
buttonDelete.Location = new Point(999, 196);
buttonDelete.Location = new Point(1309, 216);
buttonDelete.Name = "buttonDelete";
buttonDelete.Size = new Size(187, 37);
buttonDelete.TabIndex = 4;
buttonDelete.Text = "Заказ готов";
buttonDelete.UseVisualStyleBackColor = true;
buttonDelete.Click += ButtonDelete_Click;
//
// buttonRefresh
//
buttonRefresh.Location = new Point(999, 272);
buttonRefresh.Location = new Point(1309, 303);
buttonRefresh.Name = "buttonRefresh";
buttonRefresh.Size = new Size(187, 37);
buttonRefresh.TabIndex = 6;
@ -142,7 +140,7 @@
//
AutoScaleDimensions = new SizeF(8F, 20F);
AutoScaleMode = AutoScaleMode.Font;
ClientSize = new Size(1209, 450);
ClientSize = new Size(1547, 450);
Controls.Add(buttonRefresh);
Controls.Add(buttonDelete);
Controls.Add(buttonUpdate);

View File

@ -2,6 +2,8 @@
using Microsoft.Extensions.Logging;
using SushiContracts.BindingModels;
using SushiContracts.BusinessLogicsContracts;
using SushiBusinessLogic;
using SushiDataModels.Enums;
namespace Sushi
{
@ -57,10 +59,12 @@ namespace Sushi
if (list != null)
{
dataGridView.DataSource = list;
dataGridView.Columns["ServiceId"].Visible = false;
dataGridView.Columns["SushiId"].Visible = false;
dataGridView.Columns["ClientId"].Visible = false;
dataGridView.Columns["EmployeeId"].Visible = false;
dataGridView.Columns["ServiceName"].AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill;
dataGridView.Columns["ClientName"].AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill;
dataGridView.Columns["EmployeeName"].AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill;
dataGridView.Columns["SushiName"].AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill;
}
_logger.LogInformation("Загрузка заказов");
}
@ -90,50 +94,94 @@ namespace Sushi
}
}
private void ButtonUpd_Click(object sender, EventArgs e)
private OrderBindingModel CreateBindingModel(int id, bool isDone = false)
{
return new OrderBindingModel
{
Id = id,
SushiId = Convert.ToInt32(dataGridView.SelectedRows[0].Cells["SushiId"].Value),
Status = Enum.Parse<OrderStatus>(dataGridView.SelectedRows[0].Cells["Status"].Value.ToString()),
Count = Convert.ToInt32(dataGridView.SelectedRows[0].Cells["Count"].Value),
Sum = double.Parse(dataGridView.SelectedRows[0].Cells["Sum"].Value.ToString()),
//ClientId = Convert.ToInt32(dataGridView.SelectedRows[0].Cells["ClientId"].Value),
//EmployeeId = Convert.ToInt32(dataGridView.SelectedRows[0].Cells["EmployeeId"].Value),
DateCreate = DateTime.Parse(dataGridView.SelectedRows[0].Cells["DateCreate"].Value.ToString()),
};
}
private void ButtonTakeOrderInWork_Click(object sender, EventArgs e)
{
if (dataGridView.SelectedRows.Count == 1)
{
var service = Program.ServiceProvider?.GetService(typeof(FormCreateOrder));
if (service is FormCreateOrder form)
int id =
Convert.ToInt32(dataGridView.SelectedRows[0].Cells["Id"].Value);
_logger.LogInformation("Заказ №{id}. Меняется статус на 'В работе'", id);
try
{
form.Id = Convert.ToInt32(dataGridView.SelectedRows[0].Cells["Id"].Value);
if (form.ShowDialog() == DialogResult.OK)
LoadData();
var operationResult = _OrderLogic.TakeOrderInWork(CreateBindingModel(id));
if (!operationResult)
{
throw new Exception("Ошибка при сохранении. Дополнительная информация в логах.");
}
LoadData();
}
catch (Exception ex)
{
_logger.LogError(ex, "Ошибка передачи заказа в работу");
MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK,
MessageBoxIcon.Error);
}
}
}
private void ButtonDelete_Click(object sender, EventArgs e)
private void ButtonOrderReady_Click(object sender, EventArgs e)
{
if (dataGridView.SelectedRows.Count == 1)
{
if (MessageBox.Show("Удалить запись?", "Вопрос",
MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
int id =
Convert.ToInt32(dataGridView.SelectedRows[0].Cells["Id"].Value);
_logger.LogInformation("Заказ №{id}. Меняется статус на 'Готов'",
id);
try
{
int id =
Convert.ToInt32(dataGridView.SelectedRows[0].Cells["Id"].Value);
_logger.LogInformation("Удаление компонента");
try
var operationResult = _OrderLogic.FinishOrder(CreateBindingModel(id));
if (!operationResult)
{
if (!_OrderLogic.Delete(new OrderBindingModel
{
Id = id
}))
{
throw new Exception("Ошибка при удалении. Дополнительная информация в логах.");
}
LoadData();
}
catch (Exception ex)
{
_logger.LogError(ex, "Ошибка удаления компонента");
MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
throw new Exception("Ошибка при сохранении. Дополнительная информация в логах.");
}
LoadData();
}
catch (Exception ex)
{
_logger.LogError(ex, "Ошибка отметки о готовности заказа");
MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}
}
private void ButtonIssuedOrder_Click(object sender, EventArgs e)
{
if (dataGridView.SelectedRows.Count == 1)
{
int id =
Convert.ToInt32(dataGridView.SelectedRows[0].Cells["Id"].Value);
_logger.LogInformation("Заказ №{id}. Меняется статус на 'Выдан'",
id);
try
{
var operationResult = _OrderLogic.DeliveryOrder(CreateBindingModel(id));
if (!operationResult)
{
throw new Exception("Ошибка при сохранении. Дополнительная информация в логах.");
}
_logger.LogInformation("Заказ №{id} выдан", id);
LoadData();
}
catch (Exception ex)
{
_logger.LogError(ex, "Ошибка отметки о выдачи заказа");
MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK,
MessageBoxIcon.Error);
}
}
}
private void RefreshButton_Click(object sender, EventArgs e)
{
LoadData();

View File

@ -71,8 +71,7 @@ namespace Sushi
}
private void ButtonAdd_Click(object sender, EventArgs e)
{
var service =
Program.ServiceProvider?.GetService(typeof(FormSushiComponent));
var service = Program.ServiceProvider?.GetService(typeof(FormSushiComponent));
if (service is FormSushiComponent form)
{
if (form.ShowDialog() == DialogResult.OK)

View File

@ -1,5 +1,4 @@

using SushiContracts.BusinessLogicContracts;
using SushiContracts.BusinessLogicContracts;
using SushiContracts.ViewModels;
using SushiDataModels;

View File

@ -56,6 +56,7 @@ namespace Sushi
services.AddTransient<FormEmployees>();
services.AddTransient<FormCreateOrder>();
services.AddTransient<FormSushies>();
services.AddTransient<FormSushi>();
services.AddTransient<FormMain>();
services.AddTransient<FormSushiComponent>();
}

View File

@ -22,7 +22,8 @@ namespace SushiBusinessLogic
public List<OrderViewModel>? ReadList(OrderSearchModel? model)
{
_logger.LogInformation("ReadList. Id:{ Id}", model?.Id);
var list = model == null ? _orderStorage.GetFullList() : _orderStorage.GetFilteredList(model);
var list = model == null ? _orderStorage.GetFullList() :
_orderStorage.GetFilteredList(model);
if (list == null)
{
_logger.LogWarning("ReadList return null list");
@ -32,26 +33,11 @@ namespace SushiBusinessLogic
return list;
}
public OrderViewModel? ReadElement(OrderSearchModel model)
{
if (model == null)
{
throw new ArgumentNullException(nameof(model));
}
_logger.LogInformation("ReadElement. Id:{ Id}", model.Id);
var element = _orderStorage.GetElement(model);
if (element == null)
{
_logger.LogWarning("ReadElement element not found");
return null;
}
_logger.LogInformation("ReadElement find. Id:{Id}", element.Id);
return element;
}
public bool Create(OrderBindingModel model)
public bool CreateOrder(OrderBindingModel model)
{
CheckModel(model);
if (model.Status != OrderStatus.Неизвестен) return false;
model.Status = OrderStatus.Принят;
if (_orderStorage.Insert(model) == null)
{
_logger.LogWarning("Insert operation failed");
@ -60,27 +46,39 @@ namespace SushiBusinessLogic
return true;
}
public bool Delete(OrderBindingModel model)
public bool ChangeStatus(OrderBindingModel model, OrderStatus status)
{
CheckModel(model, false);
_logger.LogInformation("Delete. Id:{Id}", model.Id);
if (_orderStorage.Delete(model) == null)
CheckModel(model);
var element = _orderStorage.GetElement(new OrderSearchModel { Id = model.Id });
if (element == null)
{
_logger.LogWarning("Delete operation failed");
_logger.LogWarning("Read operation failed");
return false;
}
if (element.Status != status - 1)
{
_logger.LogWarning("Status change operation failed");
throw new InvalidOperationException("Текущий статус заказа не может быть переведен в выбранный");
}
model.Status = status;
if (model.Status == OrderStatus.Выдан) model.DateImplement = DateTime.Now;
_orderStorage.Update(model);
return true;
}
public bool Update(OrderBindingModel model)
public bool TakeOrderInWork(OrderBindingModel model)
{
CheckModel(model);
if (_orderStorage.Update(model) == null)
{
_logger.LogWarning("Update operation failed");
return false;
}
return true;
return ChangeStatus(model, OrderStatus.Выполняется);
}
public bool FinishOrder(OrderBindingModel model)
{
return ChangeStatus(model, OrderStatus.Готов);
}
public bool DeliveryOrder(OrderBindingModel model)
{
return ChangeStatus(model, OrderStatus.Выдан);
}
private void CheckModel(OrderBindingModel model, bool withParams = true)

View File

@ -97,7 +97,7 @@ namespace SushiBusinessLogic
}
if (model.Price <= 0)
{
throw new ArgumentNullException("Цена блюдо должна быть больше 0", nameof(model.Price));
throw new ArgumentNullException("Цена блюдa должна быть больше 0", nameof(model.Price));
}
_logger.LogInformation("Dish. Dish:{Dish}. Price:{ Price }. Id: { Id}", model.SushiName, model.Price, model.Id);
var element = _DishStorage.GetElement(new SushiSearchModel

View File

@ -7,10 +7,10 @@ namespace SushiContracts.BusinessLogicsContracts
public interface IOrderLogic
{
List<OrderViewModel>? ReadList(OrderSearchModel? model);
OrderViewModel? ReadElement(OrderSearchModel model);
bool Create(OrderBindingModel model);
bool Update(OrderBindingModel model);
bool Delete(OrderBindingModel model);
bool CreateOrder(OrderBindingModel model);
bool TakeOrderInWork(OrderBindingModel model);
bool FinishOrder(OrderBindingModel model);
bool DeliveryOrder(OrderBindingModel model);
}
}

View File

@ -8,6 +8,12 @@ namespace SushiContracts.ViewModels
{
[DisplayName("Номер")]
public int Id { get; set; }
public int ClientId { get; set; }
[DisplayName("Имя клиента")]
public string ClientName { get; set; } = string.Empty;
public int EmployeeId { get; set; }
[DisplayName("Имя сотрудника")]
public string EmployeeName { get; set; } = string.Empty;
public int SushiId { get; set; }
[DisplayName("Блюдо")]
public string SushiName { get; set; } = string.Empty;

View File

@ -5,6 +5,8 @@ namespace SushiDataModels
public interface IOrderModel
{
int SushiId { get; }
int ClientId { get; }
int EmployeeId { get; }
int Count { get; }
double Sum { get; }
OrderStatus Status { get; }

View File

@ -81,11 +81,27 @@ namespace SushiShopDatabaseImplement.Implements
if (model == null)
return null;
using var context = new SushiDatabase();
foreach (var Sushis in context.Sushies)
foreach (var Sushies in context.Sushies)
{
if (Sushis.Id == model.SushiId)
if (Sushies.Id == model.SushiId)
{
model.SushiName = Sushis.SushiName;
model.SushiName = Sushies.SushiName;
break;
}
}
foreach (var Clients in context.Clients)
{
if (Clients.Id == model.ClientId)
{
model.ClientName = Clients.ClientName;
break;
}
}
foreach (var Employees in context.Employees)
{
if (Employees.Id == model.EmployeeId)
{
model.EmployeeName = Employees.EmployeeName;
break;
}
}

View File

@ -12,7 +12,7 @@ using SushiDatabaseImplement;
namespace SushiDatabaseImplement.Migrations
{
[DbContext(typeof(SushiDatabase))]
[Migration("20240403234311_InitialCreate")]
[Migration("20240404102840_InitialCreate")]
partial class InitialCreate
{
/// <inheritdoc />
@ -114,7 +114,7 @@ namespace SushiDatabaseImplement.Migrations
SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property<int>("Id"));
b.Property<int?>("ClientId")
b.Property<int>("ClientId")
.HasColumnType("int");
b.Property<int>("Count")
@ -126,7 +126,7 @@ namespace SushiDatabaseImplement.Migrations
b.Property<DateTime?>("DateImplement")
.HasColumnType("datetime2");
b.Property<int?>("EmployeeId")
b.Property<int>("EmployeeId")
.HasColumnType("int");
b.Property<int>("Status")
@ -179,11 +179,15 @@ namespace SushiDatabaseImplement.Migrations
{
b.HasOne("SushiDatabaseImplement.Models.Client", null)
.WithMany("Order")
.HasForeignKey("ClientId");
.HasForeignKey("ClientId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.HasOne("SushiDatabaseImplement.Models.Employee", null)
.WithMany("Order")
.HasForeignKey("EmployeeId");
.HasForeignKey("EmployeeId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.HasOne("SushiDatabaseImplement.Models.Sushi", null)
.WithMany("Order")

View File

@ -79,8 +79,8 @@ namespace SushiDatabaseImplement.Migrations
DateCreate = table.Column<DateTime>(type: "datetime2", nullable: false),
DateImplement = table.Column<DateTime>(type: "datetime2", nullable: true),
SushiId = table.Column<int>(type: "int", nullable: false),
ClientId = table.Column<int>(type: "int", nullable: true),
EmployeeId = table.Column<int>(type: "int", nullable: true)
ClientId = table.Column<int>(type: "int", nullable: false),
EmployeeId = table.Column<int>(type: "int", nullable: false)
},
constraints: table =>
{
@ -89,12 +89,14 @@ namespace SushiDatabaseImplement.Migrations
name: "FK_Orders_Clients_ClientId",
column: x => x.ClientId,
principalTable: "Clients",
principalColumn: "Id");
principalColumn: "Id",
onDelete: ReferentialAction.Cascade);
table.ForeignKey(
name: "FK_Orders_Employees_EmployeeId",
column: x => x.EmployeeId,
principalTable: "Employees",
principalColumn: "Id");
principalColumn: "Id",
onDelete: ReferentialAction.Cascade);
table.ForeignKey(
name: "FK_Orders_Sushies_SushiId",
column: x => x.SushiId,

View File

@ -111,7 +111,7 @@ namespace SushiDatabaseImplement.Migrations
SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property<int>("Id"));
b.Property<int?>("ClientId")
b.Property<int>("ClientId")
.HasColumnType("int");
b.Property<int>("Count")
@ -123,7 +123,7 @@ namespace SushiDatabaseImplement.Migrations
b.Property<DateTime?>("DateImplement")
.HasColumnType("datetime2");
b.Property<int?>("EmployeeId")
b.Property<int>("EmployeeId")
.HasColumnType("int");
b.Property<int>("Status")
@ -176,11 +176,15 @@ namespace SushiDatabaseImplement.Migrations
{
b.HasOne("SushiDatabaseImplement.Models.Client", null)
.WithMany("Order")
.HasForeignKey("ClientId");
.HasForeignKey("ClientId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.HasOne("SushiDatabaseImplement.Models.Employee", null)
.WithMany("Order")
.HasForeignKey("EmployeeId");
.HasForeignKey("EmployeeId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.HasOne("SushiDatabaseImplement.Models.Sushi", null)
.WithMany("Order")

View File

@ -19,6 +19,10 @@ namespace SushiShopDatabaseImplement.Models
public DateTime? DateImplement { get; private set; }
[Required]
public int SushiId { get; private set; }
[Required]
public int ClientId { get; private set; }
[Required]
public int EmployeeId { get; private set; }
public static Order? Create(OrderBindingModel model)
{
@ -31,6 +35,8 @@ namespace SushiShopDatabaseImplement.Models
Id = model.Id,
Count = model.Count,
Sum = model.Sum,
ClientId = model.ClientId,
EmployeeId = model.EmployeeId,
Status = model.Status,
DateCreate = model.DateCreate,
DateImplement = model.DateImplement,
@ -44,6 +50,8 @@ namespace SushiShopDatabaseImplement.Models
{
return;
}
ClientId = model.ClientId;
EmployeeId = model.EmployeeId;
Status = model.Status;
DateImplement = model.DateImplement;
}
@ -51,6 +59,8 @@ namespace SushiShopDatabaseImplement.Models
public OrderViewModel GetViewModel => new()
{
SushiId = SushiId,
ClientId = ClientId,
EmployeeId = EmployeeId,
Count = Count,
Sum = Sum,
Status = Status,