реализации
This commit is contained in:
parent
f6ff5668f3
commit
2767e576c9
@ -1,35 +1,115 @@
|
||||
using IceCreamShopContracts.BindingModels;
|
||||
using IceCreamShopContracts.BusinessLogicsContracts;
|
||||
using IceCreamShopContracts.SearchModels;
|
||||
using IceCreamShopContracts.StoragesContracts;
|
||||
using IceCreamShopContracts.ViewModels;
|
||||
using Microsoft.Extensions.Logging;
|
||||
|
||||
namespace IceCreamBusinessLogic.BusinessLogics
|
||||
{
|
||||
public class ClientLogic : IClientLogic
|
||||
{
|
||||
private readonly ILogger _logger;
|
||||
private readonly IClientStorage _clientStorage;
|
||||
public ClientLogic(ILogger<ClientLogic> logger, IClientStorage clientStorage)
|
||||
{
|
||||
_logger = logger;
|
||||
_clientStorage = clientStorage;
|
||||
}
|
||||
|
||||
public bool Create(ClientBindingModel model)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
CheckModel(model);
|
||||
if (_clientStorage.Insert(model) == null)
|
||||
{
|
||||
_logger.LogWarning("Insert operation failed");
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
public bool Delete(ClientBindingModel model)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
CheckModel(model, false);
|
||||
_logger.LogInformation("Delete. Id:{Id}", model.Id);
|
||||
if (_clientStorage.Delete(model) == null)
|
||||
{
|
||||
_logger.LogWarning("Delete operation failed");
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
public ClientViewModel? ReadElement(ClientSearchModel model)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
if (model == null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(model));
|
||||
}
|
||||
_logger.LogInformation("ReadElement. Email:{Email}.Id:{ Id}",
|
||||
model.Email, model.Id);
|
||||
var element = _clientStorage.GetElement(model);
|
||||
if (element == null)
|
||||
{
|
||||
_logger.LogWarning("ReadElement element not found");
|
||||
return null;
|
||||
}
|
||||
_logger.LogInformation("ReadElement find. Id:{Id}", element.Id);
|
||||
return element;
|
||||
}
|
||||
|
||||
public List<ClientViewModel>? ReadList(ClientSearchModel? model)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
_logger.LogInformation("ReadList. Email:{Email}.Id:{ Id} ", model?.Email, model?.Id);
|
||||
var list = (model == null) ? _clientStorage.GetFullList() :
|
||||
_clientStorage.GetFilteredList(model);
|
||||
if (list == null)
|
||||
{
|
||||
_logger.LogWarning("ReadList return null list");
|
||||
return null;
|
||||
}
|
||||
_logger.LogInformation("ReadList. Count:{Count}", list.Count);
|
||||
return list;
|
||||
}
|
||||
|
||||
public bool Update(ClientBindingModel model)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
CheckModel(model);
|
||||
if (_clientStorage.Update(model) == null)
|
||||
{
|
||||
_logger.LogWarning("Update operation failed");
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
private void CheckModel(ClientBindingModel model, bool withParams = true)
|
||||
{
|
||||
if (model == null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(model));
|
||||
}
|
||||
if (!withParams)
|
||||
{
|
||||
return;
|
||||
}
|
||||
if (string.IsNullOrEmpty(model.ClientFIO))
|
||||
{
|
||||
throw new ArgumentNullException("Нет фио клиента", nameof(model.ClientFIO));
|
||||
}
|
||||
if (string.IsNullOrEmpty(model.Email))
|
||||
{
|
||||
throw new ArgumentNullException("Нет логина клиента", nameof(model.Email));
|
||||
}
|
||||
_logger.LogInformation("Client. Id: {Id}, FIO: {fio}, email: {email}", model.Id, model.ClientFIO, model.Email);
|
||||
var element = _clientStorage.GetElement(new ClientSearchModel
|
||||
{
|
||||
Email = model.Email,
|
||||
});
|
||||
if (element != null && element.Id != model.Id)
|
||||
{
|
||||
throw new InvalidOperationException("Клиент с таким логином уже есть");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@ -112,7 +112,6 @@ namespace IceCreamBusinessLogic.BusinessLogics
|
||||
{
|
||||
Id = viewModel.Id,
|
||||
IceCreamId = viewModel.IceCreamId,
|
||||
IceCreamName = viewModel.IceCreamName,
|
||||
Status = viewModel.Status,
|
||||
DateCreate = viewModel.DateCreate,
|
||||
DateImplement = viewModel.DateImplement,
|
||||
|
178
IceCreamShop/IceCreamShop/FormCreateOrder.Designer.cs
generated
178
IceCreamShop/IceCreamShop/FormCreateOrder.Designer.cs
generated
@ -28,111 +28,131 @@
|
||||
/// </summary>
|
||||
private void InitializeComponent()
|
||||
{
|
||||
this.buttonCancel = new System.Windows.Forms.Button();
|
||||
this.buttonSave = new System.Windows.Forms.Button();
|
||||
this.textBoxSum = new System.Windows.Forms.TextBox();
|
||||
this.textBoxCount = new System.Windows.Forms.TextBox();
|
||||
this.comboBoxIceCream = new System.Windows.Forms.ComboBox();
|
||||
this.labelSum = new System.Windows.Forms.Label();
|
||||
this.labelCount = new System.Windows.Forms.Label();
|
||||
this.labelName = new System.Windows.Forms.Label();
|
||||
this.SuspendLayout();
|
||||
buttonCancel = new Button();
|
||||
buttonSave = new Button();
|
||||
textBoxSum = new TextBox();
|
||||
textBoxCount = new TextBox();
|
||||
comboBoxIceCream = new ComboBox();
|
||||
labelSum = new Label();
|
||||
labelCount = new Label();
|
||||
labelName = new Label();
|
||||
comboBoxClient = new ComboBox();
|
||||
labelClient = new Label();
|
||||
SuspendLayout();
|
||||
//
|
||||
// buttonCancel
|
||||
//
|
||||
this.buttonCancel.Location = new System.Drawing.Point(283, 114);
|
||||
this.buttonCancel.Margin = new System.Windows.Forms.Padding(3, 2, 3, 2);
|
||||
this.buttonCancel.Name = "buttonCancel";
|
||||
this.buttonCancel.Size = new System.Drawing.Size(82, 22);
|
||||
this.buttonCancel.TabIndex = 15;
|
||||
this.buttonCancel.Text = "Отмена";
|
||||
this.buttonCancel.UseVisualStyleBackColor = true;
|
||||
this.buttonCancel.Click += new System.EventHandler(this.buttonCancel_Click);
|
||||
buttonCancel.Location = new Point(243, 152);
|
||||
buttonCancel.Margin = new Padding(3, 2, 3, 2);
|
||||
buttonCancel.Name = "buttonCancel";
|
||||
buttonCancel.Size = new Size(82, 22);
|
||||
buttonCancel.TabIndex = 15;
|
||||
buttonCancel.Text = "Отмена";
|
||||
buttonCancel.UseVisualStyleBackColor = true;
|
||||
buttonCancel.Click += buttonCancel_Click;
|
||||
//
|
||||
// buttonSave
|
||||
//
|
||||
this.buttonSave.Location = new System.Drawing.Point(195, 114);
|
||||
this.buttonSave.Margin = new System.Windows.Forms.Padding(3, 2, 3, 2);
|
||||
this.buttonSave.Name = "buttonSave";
|
||||
this.buttonSave.Size = new System.Drawing.Size(82, 22);
|
||||
this.buttonSave.TabIndex = 14;
|
||||
this.buttonSave.Text = "Сохранить";
|
||||
this.buttonSave.UseVisualStyleBackColor = true;
|
||||
this.buttonSave.Click += new System.EventHandler(this.buttonSave_Click);
|
||||
buttonSave.Location = new Point(155, 152);
|
||||
buttonSave.Margin = new Padding(3, 2, 3, 2);
|
||||
buttonSave.Name = "buttonSave";
|
||||
buttonSave.Size = new Size(82, 22);
|
||||
buttonSave.TabIndex = 14;
|
||||
buttonSave.Text = "Сохранить";
|
||||
buttonSave.UseVisualStyleBackColor = true;
|
||||
buttonSave.Click += buttonSave_Click;
|
||||
//
|
||||
// textBoxSum
|
||||
//
|
||||
this.textBoxSum.Location = new System.Drawing.Point(136, 75);
|
||||
this.textBoxSum.Margin = new System.Windows.Forms.Padding(3, 2, 3, 2);
|
||||
this.textBoxSum.Name = "textBoxSum";
|
||||
this.textBoxSum.Size = new System.Drawing.Size(230, 23);
|
||||
this.textBoxSum.TabIndex = 13;
|
||||
textBoxSum.Location = new Point(95, 72);
|
||||
textBoxSum.Margin = new Padding(3, 2, 3, 2);
|
||||
textBoxSum.Name = "textBoxSum";
|
||||
textBoxSum.Size = new Size(230, 23);
|
||||
textBoxSum.TabIndex = 13;
|
||||
//
|
||||
// textBoxCount
|
||||
//
|
||||
this.textBoxCount.Location = new System.Drawing.Point(136, 41);
|
||||
this.textBoxCount.Margin = new System.Windows.Forms.Padding(3, 2, 3, 2);
|
||||
this.textBoxCount.Name = "textBoxCount";
|
||||
this.textBoxCount.Size = new System.Drawing.Size(230, 23);
|
||||
this.textBoxCount.TabIndex = 12;
|
||||
this.textBoxCount.TextChanged += new System.EventHandler(this.textBoxCount_TextChanged);
|
||||
textBoxCount.Location = new Point(95, 38);
|
||||
textBoxCount.Margin = new Padding(3, 2, 3, 2);
|
||||
textBoxCount.Name = "textBoxCount";
|
||||
textBoxCount.Size = new Size(230, 23);
|
||||
textBoxCount.TabIndex = 12;
|
||||
textBoxCount.TextChanged += textBoxCount_TextChanged;
|
||||
//
|
||||
// comboBoxIceCream
|
||||
//
|
||||
this.comboBoxIceCream.FormattingEnabled = true;
|
||||
this.comboBoxIceCream.Location = new System.Drawing.Point(136, 6);
|
||||
this.comboBoxIceCream.Margin = new System.Windows.Forms.Padding(3, 2, 3, 2);
|
||||
this.comboBoxIceCream.Name = "comboBoxIceCream";
|
||||
this.comboBoxIceCream.Size = new System.Drawing.Size(230, 23);
|
||||
this.comboBoxIceCream.TabIndex = 11;
|
||||
this.comboBoxIceCream.SelectedIndexChanged += new System.EventHandler(this.comboBoxIceCream_SelectedIndexChanged);
|
||||
comboBoxIceCream.FormattingEnabled = true;
|
||||
comboBoxIceCream.Location = new Point(95, 3);
|
||||
comboBoxIceCream.Margin = new Padding(3, 2, 3, 2);
|
||||
comboBoxIceCream.Name = "comboBoxIceCream";
|
||||
comboBoxIceCream.Size = new Size(230, 23);
|
||||
comboBoxIceCream.TabIndex = 11;
|
||||
comboBoxIceCream.SelectedIndexChanged += comboBoxIceCream_SelectedIndexChanged;
|
||||
//
|
||||
// labelSum
|
||||
//
|
||||
this.labelSum.AutoSize = true;
|
||||
this.labelSum.Location = new System.Drawing.Point(12, 80);
|
||||
this.labelSum.Name = "labelSum";
|
||||
this.labelSum.Size = new System.Drawing.Size(48, 15);
|
||||
this.labelSum.TabIndex = 10;
|
||||
this.labelSum.Text = "Сумма:";
|
||||
labelSum.AutoSize = true;
|
||||
labelSum.Location = new Point(12, 80);
|
||||
labelSum.Name = "labelSum";
|
||||
labelSum.Size = new Size(48, 15);
|
||||
labelSum.TabIndex = 10;
|
||||
labelSum.Text = "Сумма:";
|
||||
//
|
||||
// labelCount
|
||||
//
|
||||
this.labelCount.AutoSize = true;
|
||||
this.labelCount.Location = new System.Drawing.Point(12, 43);
|
||||
this.labelCount.Name = "labelCount";
|
||||
this.labelCount.Size = new System.Drawing.Size(75, 15);
|
||||
this.labelCount.TabIndex = 9;
|
||||
this.labelCount.Text = "Количество:";
|
||||
labelCount.AutoSize = true;
|
||||
labelCount.Location = new Point(12, 43);
|
||||
labelCount.Name = "labelCount";
|
||||
labelCount.Size = new Size(75, 15);
|
||||
labelCount.TabIndex = 9;
|
||||
labelCount.Text = "Количество:";
|
||||
//
|
||||
// labelName
|
||||
//
|
||||
this.labelName.AutoSize = true;
|
||||
this.labelName.Location = new System.Drawing.Point(12, 6);
|
||||
this.labelName.Name = "labelName";
|
||||
this.labelName.Size = new System.Drawing.Size(77, 15);
|
||||
this.labelName.TabIndex = 8;
|
||||
this.labelName.Text = "Мороженое:";
|
||||
labelName.AutoSize = true;
|
||||
labelName.Location = new Point(12, 6);
|
||||
labelName.Name = "labelName";
|
||||
labelName.Size = new Size(77, 15);
|
||||
labelName.TabIndex = 8;
|
||||
labelName.Text = "Мороженое:";
|
||||
//
|
||||
// comboBoxClient
|
||||
//
|
||||
comboBoxClient.FormattingEnabled = true;
|
||||
comboBoxClient.Location = new Point(95, 111);
|
||||
comboBoxClient.Name = "comboBoxClient";
|
||||
comboBoxClient.Size = new Size(230, 23);
|
||||
comboBoxClient.TabIndex = 17;
|
||||
//
|
||||
// labelClient
|
||||
//
|
||||
labelClient.AutoSize = true;
|
||||
labelClient.Location = new Point(12, 114);
|
||||
labelClient.Name = "labelClient";
|
||||
labelClient.Size = new Size(49, 15);
|
||||
labelClient.TabIndex = 16;
|
||||
labelClient.Text = "Клиент:";
|
||||
//
|
||||
// FormCreateOrder
|
||||
//
|
||||
this.AutoScaleDimensions = new System.Drawing.SizeF(7F, 15F);
|
||||
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
|
||||
this.ClientSize = new System.Drawing.Size(376, 150);
|
||||
this.Controls.Add(this.buttonCancel);
|
||||
this.Controls.Add(this.buttonSave);
|
||||
this.Controls.Add(this.textBoxSum);
|
||||
this.Controls.Add(this.textBoxCount);
|
||||
this.Controls.Add(this.comboBoxIceCream);
|
||||
this.Controls.Add(this.labelSum);
|
||||
this.Controls.Add(this.labelCount);
|
||||
this.Controls.Add(this.labelName);
|
||||
this.Name = "FormCreateOrder";
|
||||
this.Text = "Заказ";
|
||||
this.Load += new System.EventHandler(this.FormCreateOrder_Load);
|
||||
this.ResumeLayout(false);
|
||||
this.PerformLayout();
|
||||
|
||||
AutoScaleDimensions = new SizeF(7F, 15F);
|
||||
AutoScaleMode = AutoScaleMode.Font;
|
||||
ClientSize = new Size(334, 184);
|
||||
Controls.Add(comboBoxClient);
|
||||
Controls.Add(labelClient);
|
||||
Controls.Add(buttonCancel);
|
||||
Controls.Add(buttonSave);
|
||||
Controls.Add(textBoxSum);
|
||||
Controls.Add(textBoxCount);
|
||||
Controls.Add(comboBoxIceCream);
|
||||
Controls.Add(labelSum);
|
||||
Controls.Add(labelCount);
|
||||
Controls.Add(labelName);
|
||||
Name = "FormCreateOrder";
|
||||
Text = "Заказ";
|
||||
Load += FormCreateOrder_Load;
|
||||
ResumeLayout(false);
|
||||
PerformLayout();
|
||||
}
|
||||
|
||||
#endregion
|
||||
@ -145,5 +165,7 @@
|
||||
private Label labelSum;
|
||||
private Label labelCount;
|
||||
private Label labelName;
|
||||
private ComboBox comboBoxClient;
|
||||
private Label labelClient;
|
||||
}
|
||||
}
|
@ -19,12 +19,14 @@ namespace IceCreamShopView
|
||||
private readonly ILogger _logger;
|
||||
private readonly IIceCreamLogic _logicI;
|
||||
private readonly IOrderLogic _logicO;
|
||||
public FormCreateOrder(ILogger<FormCreateOrder> logger, IIceCreamLogic logicI, IOrderLogic logicO)
|
||||
private readonly IClientLogic _logicC;
|
||||
public FormCreateOrder(ILogger<FormCreateOrder> logger, IIceCreamLogic logicI, IOrderLogic logicO, IClientLogic logicC)
|
||||
{
|
||||
InitializeComponent();
|
||||
_logger = logger;
|
||||
_logicI = logicI;
|
||||
_logicO = logicO;
|
||||
_logicC = logicC;
|
||||
}
|
||||
|
||||
private void FormCreateOrder_Load(object sender, EventArgs e)
|
||||
@ -47,6 +49,25 @@ namespace IceCreamShopView
|
||||
_logger.LogError(ex, "Ошибка загрузки списка мороженого");
|
||||
MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
||||
}
|
||||
|
||||
_logger.LogInformation("Загрузка клиентов для заказа");
|
||||
try
|
||||
{
|
||||
var list = _logicC.ReadList(null);
|
||||
if (list != null)
|
||||
{
|
||||
comboBoxClient.DisplayMember = "ClientFIO";
|
||||
comboBoxClient.ValueMember = "Id";
|
||||
comboBoxClient.DataSource = list;
|
||||
comboBoxClient.SelectedItem = null;
|
||||
}
|
||||
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_logger.LogError(ex, "Ошибка загрузки списка клиентов");
|
||||
MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
||||
}
|
||||
}
|
||||
|
||||
private void textBoxCount_TextChanged(object sender, EventArgs e)
|
||||
@ -95,13 +116,19 @@ namespace IceCreamShopView
|
||||
MessageBox.Show("Выберите мороженое", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
||||
return;
|
||||
}
|
||||
if (comboBoxClient.SelectedValue == null)
|
||||
{
|
||||
MessageBox.Show("Выберите клиента", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
||||
return;
|
||||
}
|
||||
|
||||
_logger.LogInformation("Создание заказа");
|
||||
try
|
||||
{
|
||||
var operationResult = _logicO.CreateOrder(new OrderBindingModel
|
||||
{
|
||||
IceCreamId = Convert.ToInt32(comboBoxIceCream.SelectedValue),
|
||||
IceCreamName = comboBoxIceCream.Text,
|
||||
ClientId = Convert.ToInt32(comboBoxClient.SelectedValue),
|
||||
Count = Convert.ToInt32(textBoxCount.Text),
|
||||
Sum = Convert.ToDouble(textBoxSum.Text)
|
||||
});
|
||||
|
@ -44,6 +44,7 @@ namespace IceCreamShopView
|
||||
{
|
||||
dataGridView.DataSource = list;
|
||||
dataGridView.Columns["IceCreamId"].Visible = false;
|
||||
dataGridView.Columns["ClientId"].Visible = false;
|
||||
}
|
||||
_logger.LogInformation("Загрузка заказов");
|
||||
}
|
||||
|
@ -7,6 +7,9 @@
|
||||
<link rel="stylesheet" href="~/lib/bootstrap/dist/css/bootstrap.min.css" />
|
||||
<link rel="stylesheet" href="~/css/site.css" asp-append-version="true" />
|
||||
<link rel="stylesheet" href="~/IceCreamShopClientApp.styles.css" asp-append-version="true" />
|
||||
<script src="~/lib/jquery/dist/jquery.min.js"></script>
|
||||
<script src="~/lib/bootstrap/dist/js/bootstrap.bundle.min.js"></script>
|
||||
<script src="~/js/site.js" asp-append-version="true"></script>
|
||||
</head>
|
||||
<body>
|
||||
<header>
|
||||
@ -47,9 +50,6 @@
|
||||
© 2023 - IceCreamShopClientApp - <a asp-area="" asp-controller="Home" asp-action="Privacy">Privacy</a>
|
||||
</div>
|
||||
</footer>
|
||||
<script src="~/lib/jquery/dist/jquery.min.js"></script>
|
||||
<script src="~/lib/bootstrap/dist/js/bootstrap.bundle.min.js"></script>
|
||||
<script src="~/js/site.js" asp-append-version="true"></script>
|
||||
@await RenderSectionAsync("Scripts", required: false)
|
||||
</body>
|
||||
</html>
|
||||
|
@ -12,7 +12,7 @@ namespace IceCreamShopContracts.BindingModels
|
||||
{
|
||||
public int Id { get; set; }
|
||||
public int IceCreamId { get; set; }
|
||||
public string IceCreamName { get; set; } = string.Empty;
|
||||
public int ClientId { get; set; }
|
||||
public int Count { get; set; }
|
||||
public double Sum { get; set; }
|
||||
public OrderStatus Status { get; set; } = OrderStatus.Неизвестен;
|
||||
|
@ -13,17 +13,29 @@ namespace IceCreamShopContracts.ViewModels
|
||||
{
|
||||
[DisplayName("Номер")]
|
||||
public int Id { get; set; }
|
||||
|
||||
public int IceCreamId { get; set; }
|
||||
|
||||
[DisplayName("Название")]
|
||||
public string IceCreamName { get; set; } = string.Empty;
|
||||
|
||||
public int ClientId { get; set; }
|
||||
|
||||
[DisplayName("ФИО клиента")]
|
||||
public string ClientFIO { get; set; } = string.Empty;
|
||||
|
||||
[DisplayName("Количество")]
|
||||
public int Count { get; set; }
|
||||
|
||||
[DisplayName("Сумма")]
|
||||
public double Sum { get; set; }
|
||||
|
||||
[DisplayName("Статус")]
|
||||
public OrderStatus Status { get; set; } = OrderStatus.Неизвестен;
|
||||
|
||||
[DisplayName("Дата создания")]
|
||||
public DateTime DateCreate { get; set; } = DateTime.Now;
|
||||
|
||||
[DisplayName("Дата выполнения")]
|
||||
public DateTime? DateImplement { get; set; }
|
||||
}
|
||||
|
@ -10,6 +10,7 @@ namespace AbstractIceCreamShopDataModels.Models
|
||||
public interface IOrderModel : IId
|
||||
{
|
||||
int IceCreamId { get; }
|
||||
int ClientId { get; }
|
||||
int Count { get; }
|
||||
double Sum { get; }
|
||||
OrderStatus Status { get; }
|
||||
|
@ -21,5 +21,6 @@ namespace IceCreamShopDatabaseImplement
|
||||
public virtual DbSet<IceCreamComponent> IceCreamComponents { set; get; }
|
||||
|
||||
public virtual DbSet<Order> Orders { set; get; }
|
||||
public virtual DbSet<Client> Clients { set; get; }
|
||||
}
|
||||
}
|
||||
|
@ -2,6 +2,7 @@
|
||||
using IceCreamShopContracts.SearchModels;
|
||||
using IceCreamShopContracts.StoragesContracts;
|
||||
using IceCreamShopContracts.ViewModels;
|
||||
using IceCreamShopDatabaseImplement.Models;
|
||||
|
||||
namespace IceCreamShopDatabaseImplement.Implements
|
||||
{
|
||||
@ -9,32 +10,78 @@ namespace IceCreamShopDatabaseImplement.Implements
|
||||
{
|
||||
public ClientViewModel? Delete(ClientBindingModel model)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
using var context = new IceCreamShopDatabase();
|
||||
var res = context.Clients.FirstOrDefault(x => x.Id == model.Id);
|
||||
if (res != null)
|
||||
{
|
||||
context.Clients.Remove(res);
|
||||
context.SaveChanges();
|
||||
}
|
||||
return res?.GetViewModel;
|
||||
}
|
||||
|
||||
public ClientViewModel? GetElement(ClientSearchModel model)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
using var context = new IceCreamShopDatabase();
|
||||
if (model.Id.HasValue)
|
||||
return context.Clients.FirstOrDefault(x => x.Id == model.Id)?.GetViewModel;
|
||||
if (model.Email != null && model.Password != null)
|
||||
return context.Clients
|
||||
.FirstOrDefault(x => x.Email.Equals(model.Email)
|
||||
&& x.Password.Equals(model.Password))
|
||||
?.GetViewModel;
|
||||
if (model.Email != null)
|
||||
return context.Clients.FirstOrDefault(x => x.Email.Equals(model.Email))?.GetViewModel;
|
||||
return null;
|
||||
}
|
||||
|
||||
public List<ClientViewModel> GetFilteredList(ClientSearchModel model)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
if (model == null)
|
||||
{
|
||||
return new();
|
||||
}
|
||||
if (model.Id.HasValue)
|
||||
{
|
||||
var res = GetElement(model);
|
||||
return res != null ? new() { res } : new();
|
||||
}
|
||||
if (model.Email != null)
|
||||
{
|
||||
using var context = new IceCreamShopDatabase();
|
||||
return context.Clients
|
||||
.Where(x => x.Email.Contains(model.Email))
|
||||
.Select(x => x.GetViewModel)
|
||||
.ToList();
|
||||
}
|
||||
return new();
|
||||
}
|
||||
|
||||
public List<ClientViewModel> GetFullList()
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
using var context = new IceCreamShopDatabase();
|
||||
return context.Clients.Select(x => x.GetViewModel).ToList();
|
||||
}
|
||||
|
||||
public ClientViewModel? Insert(ClientBindingModel model)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
using var context = new IceCreamShopDatabase();
|
||||
var res = Client.Create(model);
|
||||
if (res != null)
|
||||
{
|
||||
context.Clients.Add(res);
|
||||
context.SaveChanges();
|
||||
}
|
||||
return res?.GetViewModel;
|
||||
}
|
||||
|
||||
public ClientViewModel? Update(ClientBindingModel model)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
using var context = new IceCreamShopDatabase();
|
||||
var res = context.Clients.FirstOrDefault(x => x.Id == model.Id);
|
||||
res?.Update(model);
|
||||
context.SaveChanges();
|
||||
return res?.GetViewModel;
|
||||
}
|
||||
}
|
||||
}
|
@ -13,7 +13,7 @@ namespace IceCreamShopDatabaseImplement.Implements
|
||||
{
|
||||
using var context = new IceCreamShopDatabase();
|
||||
|
||||
var element = context.Orders.FirstOrDefault(rec => rec.Id == model.Id);
|
||||
var element = context.Orders.Include(x => x.Client).FirstOrDefault(x => x.Id == model.Id);
|
||||
|
||||
if (element != null)
|
||||
{
|
||||
@ -34,28 +34,46 @@ namespace IceCreamShopDatabaseImplement.Implements
|
||||
}
|
||||
|
||||
using var context = new IceCreamShopDatabase();
|
||||
return context.Orders.FirstOrDefault(x => (model.Id.HasValue && x.Id == model.Id))?.GetViewModel;
|
||||
return context.Orders
|
||||
.Include(x => x.Client)
|
||||
.FirstOrDefault(x => model.Id.HasValue && x.Id == model.Id)
|
||||
?.GetViewModel;
|
||||
}
|
||||
|
||||
public List<OrderViewModel> GetFilteredList(OrderSearchModel model)
|
||||
{
|
||||
if (model is null) return new();
|
||||
using var context = new IceCreamShopDatabase();
|
||||
|
||||
if (!model.Id.HasValue)
|
||||
if (model.Id.HasValue)
|
||||
{
|
||||
return context.Orders.Where(x => x.DateCreate >= model.DateFrom && x.DateCreate <= model.DateTo).
|
||||
Select(x => x.GetViewModel).ToList();
|
||||
var result = GetElement(model);
|
||||
return result != null ? new() { result } : new();
|
||||
}
|
||||
|
||||
return context.Orders.Where(x => x.Id == model.Id).Select(x => x.GetViewModel).ToList();
|
||||
using var context = new IceCreamShopDatabase();
|
||||
if (model.DateFrom.HasValue && model.DateTo.HasValue)
|
||||
{
|
||||
return context.Orders
|
||||
.Where(x => model.DateFrom <= x.DateCreate.Date && x.DateCreate <= model.DateTo)
|
||||
.Include(x => x.Client)
|
||||
.Select(x => x.GetViewModel)
|
||||
.ToList();
|
||||
}
|
||||
if (model.ClientId.HasValue)
|
||||
{
|
||||
return context.Orders
|
||||
.Where(x => x.Client.Id == model.ClientId)
|
||||
.Include(x => x.Client)
|
||||
.Select(x => x.GetViewModel)
|
||||
.ToList();
|
||||
}
|
||||
return new();
|
||||
}
|
||||
|
||||
public List<OrderViewModel> GetFullList()
|
||||
{
|
||||
using var context = new IceCreamShopDatabase();
|
||||
|
||||
return context.Orders.Select(x => x.GetViewModel).ToList();
|
||||
return context.Orders
|
||||
.Include(x => x.Client)
|
||||
.Select(x => x.GetViewModel)
|
||||
.ToList();
|
||||
}
|
||||
|
||||
public OrderViewModel? Insert(OrderBindingModel model)
|
||||
@ -72,14 +90,16 @@ namespace IceCreamShopDatabaseImplement.Implements
|
||||
context.Orders.Add(newOrder);
|
||||
context.SaveChanges();
|
||||
|
||||
return context.Orders.FirstOrDefault(x => x.Id == newOrder.Id)?.GetViewModel;
|
||||
return newOrder.GetViewModel;
|
||||
}
|
||||
|
||||
public OrderViewModel? Update(OrderBindingModel model)
|
||||
{
|
||||
using var context = new IceCreamShopDatabase();
|
||||
|
||||
var order = context.Orders.FirstOrDefault(x => x.Id == model.Id);
|
||||
var order = context.Orders
|
||||
.Include(x => x.Client)
|
||||
.FirstOrDefault(x => x.Id == model.Id);
|
||||
|
||||
if (order == null)
|
||||
{
|
||||
@ -89,7 +109,7 @@ namespace IceCreamShopDatabaseImplement.Implements
|
||||
order.Update(model);
|
||||
context.SaveChanges();
|
||||
|
||||
return context.Orders.FirstOrDefault(x => x.Id == model.Id)?.GetViewModel;
|
||||
return order.GetViewModel;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
59
IceCreamShop/IceCreamShopDatabaseImplement/Models/Client.cs
Normal file
59
IceCreamShop/IceCreamShopDatabaseImplement/Models/Client.cs
Normal file
@ -0,0 +1,59 @@
|
||||
using IceCreamShopContracts.BindingModels;
|
||||
using IceCreamShopContracts.ViewModels;
|
||||
using AbstractIceCreamShopDataModels.Models;
|
||||
using System.ComponentModel.DataAnnotations;
|
||||
using System.ComponentModel.DataAnnotations.Schema;
|
||||
|
||||
namespace IceCreamShopDatabaseImplement.Models
|
||||
{
|
||||
public class Client : IClientModel
|
||||
{
|
||||
[Required]
|
||||
public string ClientFIO { get; private set; } = string.Empty;
|
||||
|
||||
[Required]
|
||||
public string Email { get; private set; } = string.Empty;
|
||||
|
||||
[Required]
|
||||
public string Password { get; private set; } = string.Empty;
|
||||
|
||||
public int Id { get; private set; }
|
||||
|
||||
[ForeignKey("ClientId")]
|
||||
public virtual List<Order> Orders { get; set; } = new();
|
||||
|
||||
public static Client? Create(ClientBindingModel model)
|
||||
{
|
||||
if (model == null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
return new()
|
||||
{
|
||||
Id = model.Id,
|
||||
ClientFIO = model.ClientFIO,
|
||||
Email = model.Email,
|
||||
Password = model.Password
|
||||
};
|
||||
}
|
||||
|
||||
public void Update(ClientBindingModel model)
|
||||
{
|
||||
if (model == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
ClientFIO = model.ClientFIO;
|
||||
Email = model.Email;
|
||||
Password = model.Password;
|
||||
}
|
||||
|
||||
public ClientViewModel GetViewModel => new()
|
||||
{
|
||||
Id = Id,
|
||||
ClientFIO = ClientFIO,
|
||||
Email = Email,
|
||||
Password = Password,
|
||||
};
|
||||
}
|
||||
}
|
@ -3,6 +3,7 @@ using AbstractIceCreamShopDataModels.Models;
|
||||
using IceCreamShopContracts.BindingModels;
|
||||
using IceCreamShopContracts.ViewModels;
|
||||
using System.ComponentModel.DataAnnotations;
|
||||
using System.Reflection.Metadata;
|
||||
|
||||
namespace IceCreamShopDatabaseImplement.Models
|
||||
{
|
||||
@ -10,7 +11,8 @@ namespace IceCreamShopDatabaseImplement.Models
|
||||
{
|
||||
[Required]
|
||||
public int IceCreamId { get; set; }
|
||||
public string IceCreamName { get; private set; } = string.Empty;
|
||||
[Required]
|
||||
public int ClientId { get; private set; }
|
||||
[Required]
|
||||
public int Count { get; set; }
|
||||
[Required]
|
||||
@ -23,7 +25,8 @@ namespace IceCreamShopDatabaseImplement.Models
|
||||
public DateTime? DateImplement { get; set; }
|
||||
|
||||
public int Id { get; set; }
|
||||
|
||||
public virtual Document Document { get; set; }
|
||||
public virtual Client Client { get; set; }
|
||||
public static Order? Create(OrderBindingModel? model)
|
||||
{
|
||||
if (model == null)
|
||||
@ -33,7 +36,7 @@ namespace IceCreamShopDatabaseImplement.Models
|
||||
return new Order
|
||||
{
|
||||
IceCreamId = model.IceCreamId,
|
||||
IceCreamName = model.IceCreamName,
|
||||
ClientId = model.ClientId,
|
||||
Count = model.Count,
|
||||
Sum = model.Sum,
|
||||
Status = model.Status,
|
||||
@ -53,16 +56,25 @@ namespace IceCreamShopDatabaseImplement.Models
|
||||
DateImplement = model.DateImplement;
|
||||
}
|
||||
|
||||
public OrderViewModel GetViewModel => new()
|
||||
public OrderViewModel GetViewModel
|
||||
{
|
||||
IceCreamId = IceCreamId,
|
||||
IceCreamName = IceCreamName,
|
||||
Count = Count,
|
||||
Sum = Sum,
|
||||
Status = Status,
|
||||
DateCreate = DateCreate,
|
||||
DateImplement = DateImplement,
|
||||
Id = Id,
|
||||
};
|
||||
get
|
||||
{
|
||||
var context = new IceCreamShopDatabase();
|
||||
return new()
|
||||
{
|
||||
IceCreamId = IceCreamId,
|
||||
ClientId = ClientId,
|
||||
Count = Count,
|
||||
Sum = Sum,
|
||||
Status = Status,
|
||||
DateCreate = DateCreate,
|
||||
DateImplement = DateImplement,
|
||||
Id = Id,
|
||||
IceCreamName = context.IceCreams.FirstOrDefault(x => x.Id == IceCreamId)?.IceCreamName ?? string.Empty,
|
||||
ClientFIO = context.Clients.FirstOrDefault(x => x.Id == ClientId)?.ClientFIO ?? string.Empty
|
||||
};
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -14,9 +14,11 @@ namespace IceCreamShopFileImplement
|
||||
private readonly string ComponentFileName = "Component.xml";
|
||||
private readonly string OrderFileName = "Order.xml";
|
||||
private readonly string IceCreamFileName = "IceCream.xml";
|
||||
private readonly string ClientFileName = "Client.xml";
|
||||
public List<Component> Components { get; private set; }
|
||||
public List<Order> Orders { get; private set; }
|
||||
public List<IceCream> IceCreams { get; private set; }
|
||||
public List<Client> Clients { get; private set; }
|
||||
public static DataFileSingleton GetInstance()
|
||||
{
|
||||
if (instance == null)
|
||||
@ -28,11 +30,13 @@ namespace IceCreamShopFileImplement
|
||||
public void SaveComponents() => SaveData(Components, ComponentFileName, "Components", x => x.GetXElement);
|
||||
public void SaveIceCreams() => SaveData(IceCreams, IceCreamFileName, "IceCreams", x => x.GetXElement);
|
||||
public void SaveOrders() => SaveData(Orders, OrderFileName, "Orders", x => x.GetXElement);
|
||||
public void SaveClients() => SaveData(Clients, OrderFileName, "Clients", x => x.GetXElement);
|
||||
private DataFileSingleton()
|
||||
{
|
||||
Components = LoadData(ComponentFileName, "Component", x => Component.Create(x)!)!;
|
||||
IceCreams = LoadData(IceCreamFileName, "IceCream", x => IceCream.Create(x)!)!;
|
||||
Orders = LoadData(OrderFileName, "Order", x => Order.Create(x)!)!;
|
||||
Clients = LoadData(ClientFileName, "Client", x => Client.Create(x)!)!;
|
||||
}
|
||||
private static List<T>? LoadData<T>(string filename, string xmlNodeName, Func<XElement, T> selectFunction)
|
||||
{
|
||||
|
@ -1,4 +1,5 @@
|
||||
using IceCreamShopContracts.BindingModels;
|
||||
using IceCreamShopFileImplement.Models;
|
||||
using IceCreamShopContracts.BindingModels;
|
||||
using IceCreamShopContracts.SearchModels;
|
||||
using IceCreamShopContracts.StoragesContracts;
|
||||
using IceCreamShopContracts.ViewModels;
|
||||
@ -7,34 +8,84 @@ namespace IceCreamShopFileImplement.Implements
|
||||
{
|
||||
public class ClientStorage : IClientStorage
|
||||
{
|
||||
private readonly DataFileSingleton _source;
|
||||
public ClientStorage()
|
||||
{
|
||||
_source = DataFileSingleton.GetInstance();
|
||||
}
|
||||
|
||||
public ClientViewModel? Delete(ClientBindingModel model)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
var res = _source.Clients.FirstOrDefault(x => x.Id == model.Id);
|
||||
if (res != null)
|
||||
{
|
||||
_source.Clients.Remove(res);
|
||||
_source.SaveClients();
|
||||
}
|
||||
return res?.GetViewModel;
|
||||
}
|
||||
|
||||
public ClientViewModel? GetElement(ClientSearchModel model)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
if (model.Id.HasValue)
|
||||
return _source.Clients.FirstOrDefault(x => x.Id == model.Id)?.GetViewModel;
|
||||
if (model.Email != null && model.Password != null)
|
||||
return _source.Clients
|
||||
.FirstOrDefault(x => x.Email.Equals(model.Email)
|
||||
&& x.Password.Equals(model.Password))
|
||||
?.GetViewModel;
|
||||
if (model.Email != null)
|
||||
return _source.Clients.FirstOrDefault(x => x.Email.Equals(model.Email))?.GetViewModel;
|
||||
return null;
|
||||
}
|
||||
|
||||
public List<ClientViewModel> GetFilteredList(ClientSearchModel model)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
if (model == null)
|
||||
{
|
||||
return new();
|
||||
}
|
||||
if (model.Id.HasValue)
|
||||
{
|
||||
var res = GetElement(model);
|
||||
return res != null ? new() { res } : new();
|
||||
}
|
||||
if (model.Email != null)
|
||||
{
|
||||
return _source.Clients
|
||||
.Where(x => x.Email.Contains(model.Email))
|
||||
.Select(x => x.GetViewModel)
|
||||
.ToList();
|
||||
}
|
||||
return new();
|
||||
}
|
||||
|
||||
public List<ClientViewModel> GetFullList()
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
return _source.Clients.Select(x => x.GetViewModel).ToList();
|
||||
}
|
||||
|
||||
public ClientViewModel? Insert(ClientBindingModel model)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
model.Id = _source.Clients.Count > 0 ? _source.Clients.Max(x => x.Id) + 1 : 1;
|
||||
var res = Client.Create(model);
|
||||
if (res != null)
|
||||
{
|
||||
_source.Clients.Add(res);
|
||||
_source.SaveClients();
|
||||
}
|
||||
return res?.GetViewModel;
|
||||
}
|
||||
|
||||
public ClientViewModel? Update(ClientBindingModel model)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
var res = _source.Clients.FirstOrDefault(x => x.Id == model.Id);
|
||||
if (res != null)
|
||||
{
|
||||
res.Update(model);
|
||||
_source.SaveClients();
|
||||
}
|
||||
return res?.GetViewModel;
|
||||
}
|
||||
}
|
||||
}
|
@ -35,6 +35,15 @@ namespace IceCreamShopFileImplement.Implements
|
||||
{
|
||||
return new();
|
||||
}
|
||||
|
||||
if (model.ClientId.HasValue)
|
||||
{
|
||||
return source.Orders
|
||||
.Where(x => x.ClientId == model.ClientId)
|
||||
.Select(x => x.GetViewModel)
|
||||
.ToList();
|
||||
}
|
||||
|
||||
return source.Orders
|
||||
.Where(x => x.Id == model.Id || model.DateFrom <= x.DateCreate && x.DateCreate <= model.DateTo)
|
||||
.Select(x => x.GetViewModel)
|
||||
@ -90,6 +99,13 @@ namespace IceCreamShopFileImplement.Implements
|
||||
{
|
||||
viewModel.IceCreamName = icecream.IceCreamName;
|
||||
}
|
||||
|
||||
var client = source.Clients.FirstOrDefault(x => x.Id == order.ClientId);
|
||||
if (client != null)
|
||||
{
|
||||
viewModel.ClientFIO = client.ClientFIO;
|
||||
}
|
||||
|
||||
return viewModel;
|
||||
}
|
||||
}
|
||||
|
74
IceCreamShop/IceCreamShopFileImplement/Models/Client.cs
Normal file
74
IceCreamShop/IceCreamShopFileImplement/Models/Client.cs
Normal file
@ -0,0 +1,74 @@
|
||||
using IceCreamShopContracts.BindingModels;
|
||||
using IceCreamShopContracts.ViewModels;
|
||||
using AbstractIceCreamShopDataModels.Models;
|
||||
using System.Xml.Linq;
|
||||
|
||||
namespace IceCreamShopFileImplement.Models
|
||||
{
|
||||
public class Client : IClientModel
|
||||
{
|
||||
public string ClientFIO { get; private set; } = string.Empty;
|
||||
|
||||
public string Email { get; private set; } = string.Empty;
|
||||
|
||||
public string Password { get; private set; } = string.Empty;
|
||||
|
||||
public int Id { get; private set; }
|
||||
|
||||
public static Client? Create(ClientBindingModel model)
|
||||
{
|
||||
if (model == null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
return new()
|
||||
{
|
||||
Id = model.Id,
|
||||
ClientFIO = model.ClientFIO,
|
||||
Email = model.Email,
|
||||
Password = model.Password
|
||||
};
|
||||
}
|
||||
public static Client? Create(XElement element)
|
||||
{
|
||||
if (element == null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
return new()
|
||||
{
|
||||
Id = Convert.ToInt32(element.Attribute("Id")!.Value),
|
||||
ClientFIO = element.Element("FIO")!.Value,
|
||||
Email = element.Element("Email")!.Value,
|
||||
Password = element.Element("Password")!.Value,
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
public void Update(ClientBindingModel model)
|
||||
{
|
||||
if (model == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
ClientFIO = model.ClientFIO;
|
||||
Email = model.Email;
|
||||
Password = model.Password;
|
||||
}
|
||||
|
||||
public ClientViewModel GetViewModel => new()
|
||||
{
|
||||
Id = Id,
|
||||
ClientFIO = ClientFIO,
|
||||
Email = Email,
|
||||
Password = Password,
|
||||
};
|
||||
|
||||
public XElement GetXElement => new("Client",
|
||||
new XAttribute("Id", Id),
|
||||
new XElement("FIO", ClientFIO),
|
||||
new XElement("Email", Email),
|
||||
new XElement("Password", Password)
|
||||
);
|
||||
}
|
||||
}
|
@ -15,8 +15,11 @@ namespace IceCreamShopFileImplement.Models
|
||||
public class Order : IOrderModel
|
||||
{
|
||||
public int Id { get; private set; }
|
||||
|
||||
public int IceCreamId { get; private set; }
|
||||
|
||||
public int ClientId { get; set; }
|
||||
|
||||
public int Count { get; private set; }
|
||||
|
||||
public double Sum { get; private set; }
|
||||
@ -36,6 +39,7 @@ namespace IceCreamShopFileImplement.Models
|
||||
{
|
||||
Id = model.Id,
|
||||
IceCreamId = model.IceCreamId,
|
||||
ClientId = model.ClientId,
|
||||
Count = model.Count,
|
||||
Sum = model.Sum,
|
||||
Status = model.Status,
|
||||
@ -53,6 +57,7 @@ namespace IceCreamShopFileImplement.Models
|
||||
{
|
||||
Id = Convert.ToInt32(element.Attribute("Id")!.Value),
|
||||
IceCreamId = Convert.ToInt32(element.Element("IceCreamId")!.Value),
|
||||
ClientId = Convert.ToInt32(element.Element("ClientId")!.Value),
|
||||
Sum = Convert.ToDouble(element.Element("Sum")!.Value),
|
||||
Count = Convert.ToInt32(element.Element("Count")!.Value),
|
||||
Status = (OrderStatus)Enum.Parse(typeof(OrderStatus), element.Element("Status")!.Value),
|
||||
@ -73,6 +78,7 @@ namespace IceCreamShopFileImplement.Models
|
||||
{
|
||||
Id = Id,
|
||||
IceCreamId = IceCreamId,
|
||||
ClientId = ClientId,
|
||||
Count = Count,
|
||||
Sum = Sum,
|
||||
Status = Status,
|
||||
@ -83,6 +89,7 @@ namespace IceCreamShopFileImplement.Models
|
||||
"Order",
|
||||
new XAttribute("Id", Id),
|
||||
new XElement("IceCreamId", IceCreamId.ToString()),
|
||||
new XElement("ClientId", ClientId),
|
||||
new XElement("Count", Count.ToString()),
|
||||
new XElement("Sum", Sum.ToString()),
|
||||
new XElement("Status", Status.ToString()),
|
||||
|
@ -13,11 +13,13 @@ namespace IceCreamShopListImplement
|
||||
public List<Component> Components { get; set; }
|
||||
public List<Order> Orders { get; set; }
|
||||
public List<IceCream> iceCreams { get; set; }
|
||||
public List<Client> Clients { get; set; }
|
||||
private DataListSingleton()
|
||||
{
|
||||
Components = new List<Component>();
|
||||
Orders = new List<Order>();
|
||||
iceCreams = new List<IceCream>();
|
||||
Clients = new List<Client>();
|
||||
}
|
||||
public static DataListSingleton GetInstance()
|
||||
{
|
||||
|
@ -2,39 +2,97 @@
|
||||
using IceCreamShopContracts.SearchModels;
|
||||
using IceCreamShopContracts.StoragesContracts;
|
||||
using IceCreamShopContracts.ViewModels;
|
||||
using IceCreamShopListImplement.Models;
|
||||
|
||||
namespace IceCreamShopListImplement.Implements
|
||||
{
|
||||
public class ClientStorage : IClientStorage
|
||||
{
|
||||
private readonly DataListSingleton _source;
|
||||
public ClientStorage()
|
||||
{
|
||||
_source = DataListSingleton.GetInstance();
|
||||
}
|
||||
|
||||
public ClientViewModel? Delete(ClientBindingModel model)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
for (int i = 0; i < _source.Clients.Count; ++i)
|
||||
{
|
||||
if (_source.Clients[i].Id == model.Id)
|
||||
{
|
||||
var element = _source.Clients[i];
|
||||
_source.Clients.RemoveAt(i);
|
||||
return element.GetViewModel;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public ClientViewModel? GetElement(ClientSearchModel model)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
foreach (var client in _source.Clients)
|
||||
{
|
||||
if (model.Id.HasValue && model.Id == client.Id)
|
||||
return client.GetViewModel;
|
||||
if (model.Email != null && model.Password != null &&
|
||||
client.Email.Equals(model.Email) && client.Password.Equals(model.Password))
|
||||
return client.GetViewModel;
|
||||
if (model.Email != null && client.Email.Equals(model.Email))
|
||||
return client.GetViewModel;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public List<ClientViewModel> GetFilteredList(ClientSearchModel model)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
if (model == null)
|
||||
{
|
||||
return new();
|
||||
}
|
||||
|
||||
var res = GetElement(model);
|
||||
return res != null ? new() { res } : new();
|
||||
}
|
||||
|
||||
public List<ClientViewModel> GetFullList()
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
var result = new List<ClientViewModel>();
|
||||
foreach (var client in _source.Clients)
|
||||
{
|
||||
result.Add(client.GetViewModel);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
public ClientViewModel? Insert(ClientBindingModel model)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
model.Id = 1;
|
||||
foreach (var client in _source.Clients)
|
||||
{
|
||||
if (model.Id <= client.Id)
|
||||
{
|
||||
model.Id = client.Id + 1;
|
||||
}
|
||||
}
|
||||
var res = Client.Create(model);
|
||||
if (res != null)
|
||||
{
|
||||
_source.Clients.Add(res);
|
||||
}
|
||||
return res?.GetViewModel;
|
||||
}
|
||||
|
||||
public ClientViewModel? Update(ClientBindingModel model)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
foreach (var client in _source.Clients)
|
||||
{
|
||||
if (client.Id == model.Id)
|
||||
{
|
||||
client.Update(model);
|
||||
return client.GetViewModel;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
@ -47,12 +47,25 @@ namespace IceCreamShopListImplement.Implements
|
||||
public List<OrderViewModel> GetFilteredList(OrderSearchModel model)
|
||||
{
|
||||
var result = new List<OrderViewModel>();
|
||||
if (!model.Id.HasValue) return result;
|
||||
|
||||
foreach (var order in _source.Orders)
|
||||
if (model.DateFrom.HasValue && model.DateTo.HasValue)
|
||||
{
|
||||
if (order.Id == model.Id || model.DateFrom <= order.DateCreate && order.DateCreate <= model.DateTo)
|
||||
result.Add(GetViewModel(order));
|
||||
foreach (var order in _source.Orders)
|
||||
{
|
||||
if (order.Id == model.Id || model.DateFrom <= order.DateCreate && order.DateCreate <= model.DateTo)
|
||||
{
|
||||
result.Add(GetViewModel(order));
|
||||
}
|
||||
}
|
||||
}
|
||||
if (model.ClientId.HasValue)
|
||||
{
|
||||
foreach (var order in _source.Orders)
|
||||
{
|
||||
if (order.ClientId == model.ClientId)
|
||||
{
|
||||
result.Add(GetViewModel(order));
|
||||
}
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
@ -110,6 +123,16 @@ namespace IceCreamShopListImplement.Implements
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
foreach (var client in _source.Clients)
|
||||
{
|
||||
if (client.Id == order.ClientId)
|
||||
{
|
||||
viewModel.ClientFIO = client.ClientFIO;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
return viewModel;
|
||||
}
|
||||
}
|
||||
|
51
IceCreamShop/IceCreamShopListImplement/Models/Client.cs
Normal file
51
IceCreamShop/IceCreamShopListImplement/Models/Client.cs
Normal file
@ -0,0 +1,51 @@
|
||||
using IceCreamShopContracts.BindingModels;
|
||||
using IceCreamShopContracts.ViewModels;
|
||||
using AbstractIceCreamShopDataModels.Models;
|
||||
|
||||
namespace IceCreamShopListImplement.Models
|
||||
{
|
||||
public class Client : IClientModel
|
||||
{
|
||||
public string ClientFIO { get; private set; } = string.Empty;
|
||||
|
||||
public string Email { get; private set; } = string.Empty;
|
||||
|
||||
public string Password { get; private set; } = string.Empty;
|
||||
|
||||
public int Id { get; private set; }
|
||||
|
||||
public static Client? Create(ClientBindingModel model)
|
||||
{
|
||||
if (model == null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
return new()
|
||||
{
|
||||
Id = model.Id,
|
||||
ClientFIO = model.ClientFIO,
|
||||
Email = model.Email,
|
||||
Password = model.Password
|
||||
};
|
||||
}
|
||||
|
||||
public void Update(ClientBindingModel model)
|
||||
{
|
||||
if (model == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
ClientFIO = model.ClientFIO;
|
||||
Email = model.Email;
|
||||
Password = model.Password;
|
||||
}
|
||||
|
||||
public ClientViewModel GetViewModel => new()
|
||||
{
|
||||
Id = Id,
|
||||
ClientFIO = ClientFIO,
|
||||
Email = Email,
|
||||
Password = Password,
|
||||
};
|
||||
}
|
||||
}
|
@ -18,6 +18,8 @@ namespace IceCreamShopListImplement.Models
|
||||
|
||||
public int IceCreamId { get; private set; }
|
||||
|
||||
public int ClientId { get; private set; }
|
||||
|
||||
public int Count { get; private set; }
|
||||
|
||||
public double Sum { get; private set; }
|
||||
@ -35,6 +37,7 @@ namespace IceCreamShopListImplement.Models
|
||||
{
|
||||
Id = model.Id,
|
||||
IceCreamId = model.IceCreamId,
|
||||
ClientId = model.ClientId,
|
||||
Count = model.Count,
|
||||
Sum = model.Sum,
|
||||
Status = model.Status,
|
||||
@ -54,6 +57,7 @@ namespace IceCreamShopListImplement.Models
|
||||
{
|
||||
Id = Id,
|
||||
IceCreamId = IceCreamId,
|
||||
ClientId = ClientId,
|
||||
Count = Count,
|
||||
Sum = Sum,
|
||||
Status = Status,
|
||||
|
Loading…
Reference in New Issue
Block a user