Required selling and check methods were moved + some additons.
This commit is contained in:
parent
6e08782795
commit
d1891a4b1b
@ -147,45 +147,13 @@ namespace DressAtelierBusinessLogic.BusinessLogic
|
|||||||
atelierModel.Address = atelier.Address;
|
atelierModel.Address = atelier.Address;
|
||||||
atelierModel.DressesList = atelier.DressesList;
|
atelierModel.DressesList = atelier.DressesList;
|
||||||
atelierModel.OpeningDate = atelier.OpeningDate;
|
atelierModel.OpeningDate = atelier.OpeningDate;
|
||||||
if(_atelierStorage.Update(atelierModel) == null)
|
if(_atelierStorage.Update(atelierModel) == null || atelier.DressesList.Count > atelier.MaxTotalOfDresses)
|
||||||
{
|
{
|
||||||
_logger.LogWarning("Restocking operation failed");
|
_logger.LogWarning("Restocking operation failed");
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
public bool CheckGoods(DressBindingModel model, int quantity)
|
|
||||||
{
|
|
||||||
var ateliers = _atelierStorage.GetFilteredList(new AtelierSearchModel { DressID = model.ID});
|
|
||||||
int requiredQuantity = quantity;
|
|
||||||
using (TransactionScope scope = new TransactionScope())
|
|
||||||
{
|
|
||||||
try
|
|
||||||
{
|
|
||||||
foreach(var atelier in ateliers)
|
|
||||||
{
|
|
||||||
if (atelier.DressesList[model.ID].Item2 == requiredQuantity)
|
|
||||||
{
|
|
||||||
atelier.DressesList.Remove(model.ID);
|
|
||||||
scope.Complete();
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
requiredQuantity -= atelier.DressesList[model.ID].Item2;
|
|
||||||
atelier.DressesList.Remove(model.ID);
|
|
||||||
}
|
|
||||||
|
|
||||||
if(requiredQuantity > 0)
|
|
||||||
{
|
|
||||||
throw new Exception("Not enough dresses in ateliers");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
catch(Exception ex)
|
|
||||||
{
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -17,6 +17,5 @@ namespace DressAtelierContracts.BusinessLogicContracts
|
|||||||
bool Create(AtelierBindingModel model);
|
bool Create(AtelierBindingModel model);
|
||||||
bool Update(AtelierBindingModel model);
|
bool Update(AtelierBindingModel model);
|
||||||
bool Delete(AtelierBindingModel model);
|
bool Delete(AtelierBindingModel model);
|
||||||
bool CheckGoods(DressBindingModel model, int quantity);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -17,5 +17,7 @@ namespace DressAtelierContracts.StorageContracts
|
|||||||
AtelierViewModel? Insert(AtelierBindingModel model);
|
AtelierViewModel? Insert(AtelierBindingModel model);
|
||||||
AtelierViewModel? Update(AtelierBindingModel model);
|
AtelierViewModel? Update(AtelierBindingModel model);
|
||||||
AtelierViewModel? Delete(AtelierBindingModel model);
|
AtelierViewModel? Delete(AtelierBindingModel model);
|
||||||
|
AtelierViewModel? CheckDressesQuantity(DressBindingModel model, int quantity);
|
||||||
|
bool SellDresses(DressBindingModel model, int quantity);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -8,6 +8,7 @@ using System.Collections.Generic;
|
|||||||
using System.Linq;
|
using System.Linq;
|
||||||
using System.Text;
|
using System.Text;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
|
using System.Transactions;
|
||||||
|
|
||||||
namespace DressAtelierFileImplement.Implements
|
namespace DressAtelierFileImplement.Implements
|
||||||
{
|
{
|
||||||
@ -96,6 +97,60 @@ namespace DressAtelierFileImplement.Implements
|
|||||||
return _source.Ateliers.Select(x => x.GetViewModel).ToList();
|
return _source.Ateliers.Select(x => x.GetViewModel).ToList();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public AtelierViewModel? CheckDressesQuantity(DressBindingModel model, int quantity)
|
||||||
|
{
|
||||||
|
var ateliers = GetFilteredList(new AtelierSearchModel { DressID = model.ID });
|
||||||
|
foreach(var atelier in ateliers)
|
||||||
|
{
|
||||||
|
if (atelier.DressesList[model.ID].Item2 >= quantity)
|
||||||
|
{
|
||||||
|
return atelier;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
public bool SellDresses(DressBindingModel model, int quantity)
|
||||||
|
{
|
||||||
|
var specatelier = CheckDressesQuantity(model, quantity);
|
||||||
|
|
||||||
|
if (specatelier == null)
|
||||||
|
{
|
||||||
|
var ateliers = GetFilteredList(new AtelierSearchModel { DressID = model.ID });
|
||||||
|
int requiredQuantity = quantity;
|
||||||
|
|
||||||
|
using TransactionScope scope = new TransactionScope();
|
||||||
|
try
|
||||||
|
{
|
||||||
|
foreach (var atelier in ateliers)
|
||||||
|
{
|
||||||
|
if (atelier.DressesList[model.ID].Item2 >= requiredQuantity)
|
||||||
|
{
|
||||||
|
atelier.DressesList.Remove(model.ID);
|
||||||
|
_source.SaveAteliers();
|
||||||
|
scope.Complete();
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
requiredQuantity -= atelier.DressesList[model.ID].Item2;
|
||||||
|
atelier.DressesList.Remove(model.ID);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (requiredQuantity > 0)
|
||||||
|
{
|
||||||
|
throw new Exception("Not enough dresses in ateliers");
|
||||||
|
}
|
||||||
|
_source.SaveAteliers();
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
specatelier.DressesList.Remove(model.ID);
|
||||||
|
_source.SaveAteliers();
|
||||||
|
return true;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -87,7 +87,7 @@ namespace DressAtelierFileImplement.Models
|
|||||||
Name = atelier.Name;
|
Name = atelier.Name;
|
||||||
Address = atelier.Address;
|
Address = atelier.Address;
|
||||||
CurrentDresses = atelier.DressesList.ToDictionary(x => x.Key, x => x.Value.Item2);
|
CurrentDresses = atelier.DressesList.ToDictionary(x => x.Key, x => x.Value.Item2);
|
||||||
DressesList = null;
|
DressesList.Clear();
|
||||||
OpeningDate = atelier.OpeningDate;
|
OpeningDate = atelier.OpeningDate;
|
||||||
MaxTotalOfDresses = atelier.MaxTotalOfDresses;
|
MaxTotalOfDresses = atelier.MaxTotalOfDresses;
|
||||||
}
|
}
|
||||||
|
@ -98,5 +98,15 @@ namespace DressAtelierListImplement.Implements
|
|||||||
}
|
}
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public AtelierViewModel? CheckDressesQuantity(DressBindingModel model, int quantity)
|
||||||
|
{
|
||||||
|
throw new NotImplementedException();
|
||||||
|
}
|
||||||
|
|
||||||
|
public bool SellDresses(DressBindingModel model, int quantity)
|
||||||
|
{
|
||||||
|
throw new NotImplementedException();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
138
SewingDresses/FormAtelier.Designer.cs
generated
138
SewingDresses/FormAtelier.Designer.cs
generated
@ -28,85 +28,105 @@
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
private void InitializeComponent()
|
private void InitializeComponent()
|
||||||
{
|
{
|
||||||
this.cancelButton = new System.Windows.Forms.Button();
|
cancelButton = new Button();
|
||||||
this.saveAtelierButton = new System.Windows.Forms.Button();
|
saveAtelierButton = new Button();
|
||||||
this.atelierAddressLabel = new System.Windows.Forms.Label();
|
atelierAddressLabel = new Label();
|
||||||
this.atelierNameLabel = new System.Windows.Forms.Label();
|
atelierNameLabel = new Label();
|
||||||
this.atelierAddressTextBox = new System.Windows.Forms.TextBox();
|
atelierAddressTextBox = new TextBox();
|
||||||
this.atelierNameTextBox = new System.Windows.Forms.TextBox();
|
atelierNameTextBox = new TextBox();
|
||||||
this.SuspendLayout();
|
labelMaxQuantity = new Label();
|
||||||
|
atelierTextBoxCapacity = new TextBox();
|
||||||
|
SuspendLayout();
|
||||||
//
|
//
|
||||||
// cancelButton
|
// cancelButton
|
||||||
//
|
//
|
||||||
this.cancelButton.Location = new System.Drawing.Point(310, 95);
|
cancelButton.Location = new Point(310, 129);
|
||||||
this.cancelButton.Name = "cancelButton";
|
cancelButton.Name = "cancelButton";
|
||||||
this.cancelButton.Size = new System.Drawing.Size(80, 25);
|
cancelButton.Size = new Size(80, 25);
|
||||||
this.cancelButton.TabIndex = 11;
|
cancelButton.TabIndex = 11;
|
||||||
this.cancelButton.Text = "Cancel";
|
cancelButton.Text = "Cancel";
|
||||||
this.cancelButton.UseVisualStyleBackColor = true;
|
cancelButton.UseVisualStyleBackColor = true;
|
||||||
this.cancelButton.Click += new System.EventHandler(this.cancelButton_Click);
|
cancelButton.Click += cancelButton_Click;
|
||||||
//
|
//
|
||||||
// saveAtelierButton
|
// saveAtelierButton
|
||||||
//
|
//
|
||||||
this.saveAtelierButton.Location = new System.Drawing.Point(224, 95);
|
saveAtelierButton.Location = new Point(224, 129);
|
||||||
this.saveAtelierButton.Name = "saveAtelierButton";
|
saveAtelierButton.Name = "saveAtelierButton";
|
||||||
this.saveAtelierButton.Size = new System.Drawing.Size(80, 25);
|
saveAtelierButton.Size = new Size(80, 25);
|
||||||
this.saveAtelierButton.TabIndex = 10;
|
saveAtelierButton.TabIndex = 10;
|
||||||
this.saveAtelierButton.Text = "Save";
|
saveAtelierButton.Text = "Save";
|
||||||
this.saveAtelierButton.UseVisualStyleBackColor = true;
|
saveAtelierButton.UseVisualStyleBackColor = true;
|
||||||
this.saveAtelierButton.Click += new System.EventHandler(this.saveAtelierButton_Click);
|
saveAtelierButton.Click += saveAtelierButton_Click;
|
||||||
//
|
//
|
||||||
// atelierAddressLabel
|
// atelierAddressLabel
|
||||||
//
|
//
|
||||||
this.atelierAddressLabel.AutoSize = true;
|
atelierAddressLabel.AutoSize = true;
|
||||||
this.atelierAddressLabel.Font = new System.Drawing.Font("Segoe UI", 14.25F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point);
|
atelierAddressLabel.Font = new Font("Segoe UI", 14.25F, FontStyle.Regular, GraphicsUnit.Point);
|
||||||
this.atelierAddressLabel.Location = new System.Drawing.Point(1, 46);
|
atelierAddressLabel.Location = new Point(1, 46);
|
||||||
this.atelierAddressLabel.Name = "atelierAddressLabel";
|
atelierAddressLabel.Name = "atelierAddressLabel";
|
||||||
this.atelierAddressLabel.Size = new System.Drawing.Size(83, 25);
|
atelierAddressLabel.Size = new Size(83, 25);
|
||||||
this.atelierAddressLabel.TabIndex = 9;
|
atelierAddressLabel.TabIndex = 9;
|
||||||
this.atelierAddressLabel.Text = "Address:";
|
atelierAddressLabel.Text = "Address:";
|
||||||
//
|
//
|
||||||
// atelierNameLabel
|
// atelierNameLabel
|
||||||
//
|
//
|
||||||
this.atelierNameLabel.AutoSize = true;
|
atelierNameLabel.AutoSize = true;
|
||||||
this.atelierNameLabel.Font = new System.Drawing.Font("Segoe UI", 14.25F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point);
|
atelierNameLabel.Font = new Font("Segoe UI", 14.25F, FontStyle.Regular, GraphicsUnit.Point);
|
||||||
this.atelierNameLabel.Location = new System.Drawing.Point(1, 10);
|
atelierNameLabel.Location = new Point(1, 10);
|
||||||
this.atelierNameLabel.Name = "atelierNameLabel";
|
atelierNameLabel.Name = "atelierNameLabel";
|
||||||
this.atelierNameLabel.Size = new System.Drawing.Size(66, 25);
|
atelierNameLabel.Size = new Size(66, 25);
|
||||||
this.atelierNameLabel.TabIndex = 8;
|
atelierNameLabel.TabIndex = 8;
|
||||||
this.atelierNameLabel.Text = "Name:";
|
atelierNameLabel.Text = "Name:";
|
||||||
//
|
//
|
||||||
// atelierAddressTextBox
|
// atelierAddressTextBox
|
||||||
//
|
//
|
||||||
this.atelierAddressTextBox.Location = new System.Drawing.Point(90, 48);
|
atelierAddressTextBox.Location = new Point(90, 48);
|
||||||
this.atelierAddressTextBox.Name = "atelierAddressTextBox";
|
atelierAddressTextBox.Name = "atelierAddressTextBox";
|
||||||
this.atelierAddressTextBox.Size = new System.Drawing.Size(300, 23);
|
atelierAddressTextBox.Size = new Size(300, 23);
|
||||||
this.atelierAddressTextBox.TabIndex = 7;
|
atelierAddressTextBox.TabIndex = 7;
|
||||||
//
|
//
|
||||||
// atelierNameTextBox
|
// atelierNameTextBox
|
||||||
//
|
//
|
||||||
this.atelierNameTextBox.Location = new System.Drawing.Point(90, 12);
|
atelierNameTextBox.Location = new Point(90, 12);
|
||||||
this.atelierNameTextBox.Name = "atelierNameTextBox";
|
atelierNameTextBox.Name = "atelierNameTextBox";
|
||||||
this.atelierNameTextBox.Size = new System.Drawing.Size(300, 23);
|
atelierNameTextBox.Size = new Size(300, 23);
|
||||||
this.atelierNameTextBox.TabIndex = 6;
|
atelierNameTextBox.TabIndex = 6;
|
||||||
|
//
|
||||||
|
// labelMaxQuantity
|
||||||
|
//
|
||||||
|
labelMaxQuantity.AutoSize = true;
|
||||||
|
labelMaxQuantity.Font = new Font("Segoe UI", 14.25F, FontStyle.Regular, GraphicsUnit.Point);
|
||||||
|
labelMaxQuantity.Location = new Point(1, 87);
|
||||||
|
labelMaxQuantity.Name = "labelMaxQuantity";
|
||||||
|
labelMaxQuantity.Size = new Size(88, 25);
|
||||||
|
labelMaxQuantity.TabIndex = 13;
|
||||||
|
labelMaxQuantity.Text = "Capacity:";
|
||||||
|
//
|
||||||
|
// atelierTextBoxCapacity
|
||||||
|
//
|
||||||
|
atelierTextBoxCapacity.Location = new Point(90, 87);
|
||||||
|
atelierTextBoxCapacity.Name = "atelierTextBoxCapacity";
|
||||||
|
atelierTextBoxCapacity.Size = new Size(41, 23);
|
||||||
|
atelierTextBoxCapacity.TabIndex = 12;
|
||||||
//
|
//
|
||||||
// FormAtelier
|
// FormAtelier
|
||||||
//
|
//
|
||||||
this.AutoScaleDimensions = new System.Drawing.SizeF(7F, 15F);
|
AutoScaleDimensions = new SizeF(7F, 15F);
|
||||||
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
|
AutoScaleMode = AutoScaleMode.Font;
|
||||||
this.ClientSize = new System.Drawing.Size(396, 129);
|
ClientSize = new Size(396, 166);
|
||||||
this.Controls.Add(this.cancelButton);
|
Controls.Add(labelMaxQuantity);
|
||||||
this.Controls.Add(this.saveAtelierButton);
|
Controls.Add(atelierTextBoxCapacity);
|
||||||
this.Controls.Add(this.atelierAddressLabel);
|
Controls.Add(cancelButton);
|
||||||
this.Controls.Add(this.atelierNameLabel);
|
Controls.Add(saveAtelierButton);
|
||||||
this.Controls.Add(this.atelierAddressTextBox);
|
Controls.Add(atelierAddressLabel);
|
||||||
this.Controls.Add(this.atelierNameTextBox);
|
Controls.Add(atelierNameLabel);
|
||||||
this.Name = "FormAtelier";
|
Controls.Add(atelierAddressTextBox);
|
||||||
this.Text = "FormAtelier";
|
Controls.Add(atelierNameTextBox);
|
||||||
this.Load += new System.EventHandler(this.FormAtelier_Load);
|
Name = "FormAtelier";
|
||||||
this.ResumeLayout(false);
|
Text = "FormAtelier";
|
||||||
this.PerformLayout();
|
Load += FormAtelier_Load;
|
||||||
|
ResumeLayout(false);
|
||||||
|
PerformLayout();
|
||||||
}
|
}
|
||||||
|
|
||||||
#endregion
|
#endregion
|
||||||
@ -117,5 +137,7 @@
|
|||||||
private Label atelierNameLabel;
|
private Label atelierNameLabel;
|
||||||
private TextBox atelierAddressTextBox;
|
private TextBox atelierAddressTextBox;
|
||||||
private TextBox atelierNameTextBox;
|
private TextBox atelierNameTextBox;
|
||||||
|
private Label labelMaxQuantity;
|
||||||
|
private TextBox atelierTextBoxCapacity;
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -21,7 +21,7 @@ namespace SewingDresses
|
|||||||
private readonly IAtelierLogic _logic;
|
private readonly IAtelierLogic _logic;
|
||||||
private int? _id;
|
private int? _id;
|
||||||
public int ID { set { _id = value; } }
|
public int ID { set { _id = value; } }
|
||||||
public FormAtelier(ILogger<FormAtelier> logger,IAtelierLogic logic)
|
public FormAtelier(ILogger<FormAtelier> logger, IAtelierLogic logic)
|
||||||
{
|
{
|
||||||
InitializeComponent();
|
InitializeComponent();
|
||||||
_logger = logger;
|
_logger = logger;
|
||||||
@ -30,7 +30,7 @@ namespace SewingDresses
|
|||||||
|
|
||||||
private void FormAtelier_Load(object sender, EventArgs e)
|
private void FormAtelier_Load(object sender, EventArgs e)
|
||||||
{
|
{
|
||||||
if(_id.HasValue)
|
if (_id.HasValue)
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
@ -43,20 +43,20 @@ namespace SewingDresses
|
|||||||
{
|
{
|
||||||
atelierNameTextBox.Text = view.Name;
|
atelierNameTextBox.Text = view.Name;
|
||||||
atelierAddressTextBox.Text = view.Address;
|
atelierAddressTextBox.Text = view.Address;
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
catch(Exception ex)
|
catch (Exception ex)
|
||||||
{
|
{
|
||||||
_logger.LogError(ex, "Error receiving atelier");
|
_logger.LogError(ex, "Error receiving atelier");
|
||||||
MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK,MessageBoxIcon.Error);
|
MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void saveAtelierButton_Click(object sender, EventArgs e)
|
private void saveAtelierButton_Click(object sender, EventArgs e)
|
||||||
{
|
{
|
||||||
if(string.IsNullOrEmpty(atelierNameTextBox.Text) || string.IsNullOrEmpty(atelierAddressTextBox.Text))
|
if (string.IsNullOrEmpty(atelierNameTextBox.Text) || string.IsNullOrEmpty(atelierAddressTextBox.Text))
|
||||||
{
|
{
|
||||||
MessageBox.Show("Fill all fields", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
MessageBox.Show("Fill all fields", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
||||||
return;
|
return;
|
||||||
@ -69,10 +69,11 @@ namespace SewingDresses
|
|||||||
ID = _id ?? 0,
|
ID = _id ?? 0,
|
||||||
Name = atelierNameTextBox.Text,
|
Name = atelierNameTextBox.Text,
|
||||||
Address = atelierAddressTextBox.Text,
|
Address = atelierAddressTextBox.Text,
|
||||||
|
MaxTotalOfDresses = Convert.ToInt32(atelierTextBoxCapacity.Text),
|
||||||
DressesList = new Dictionary<int, (IDressModel, int)>()
|
DressesList = new Dictionary<int, (IDressModel, int)>()
|
||||||
};
|
};
|
||||||
var operationResult = _id.HasValue ? _logic.Update(model) : _logic.Create(model);
|
var operationResult = _id.HasValue ? _logic.Update(model) : _logic.Create(model);
|
||||||
if(!operationResult)
|
if (!operationResult)
|
||||||
{
|
{
|
||||||
throw new Exception("Error during saving. Extra info in logs.");
|
throw new Exception("Error during saving. Extra info in logs.");
|
||||||
}
|
}
|
||||||
@ -80,7 +81,7 @@ namespace SewingDresses
|
|||||||
DialogResult = DialogResult.OK;
|
DialogResult = DialogResult.OK;
|
||||||
Close();
|
Close();
|
||||||
}
|
}
|
||||||
catch(Exception ex)
|
catch (Exception ex)
|
||||||
{
|
{
|
||||||
_logger.LogError(ex, "Error saving atelier");
|
_logger.LogError(ex, "Error saving atelier");
|
||||||
MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user