Logic fixes.

This commit is contained in:
Yuee Shiness 2023-06-03 14:45:16 +04:00
parent 52b4de4084
commit babb2989e3
9 changed files with 55 additions and 62 deletions

View File

@ -121,6 +121,11 @@ namespace DressAtelierBusinessLogic.BusinessLogic
}
}
public bool CheckQuantity(int quantity)
{
return _atelierStorage.CheckDressesQuantity(quantity);
}
public (bool result,int quantity) AddDress(AtelierBindingModel? atelierModel, DressBindingModel dressModel, int quantity)
{
@ -139,10 +144,6 @@ namespace DressAtelierBusinessLogic.BusinessLogic
ID = atelierModel.ID
});
if(atelier.CurrentQuantity >= atelier.MaxTotalOfDresses)
{
throw new Exception("Storage overflow");
}
if(!atelier.DressesList.ContainsKey(dress.ID))
{

View File

@ -64,17 +64,22 @@ namespace DressAtelierBusinessLogic.BusinessLogic
int quantity = model.Count;
using TransactionScope scope = new TransactionScope();
try
{
using (TransactionScope scope = new TransactionScope())
{
if(ateliers.Sum(x => x.MaxTotalOfDresses - x.DressesList.Sum(y => y.Value.Item2)) < quantity)
{
throw new OverflowException("There is not enough space in ateliers");
}
foreach (var atelier in ateliers)
{
quantity = _atelierLogic.AddDress(new AtelierBindingModel { ID = atelier.ID }, new DressBindingModel { ID = model.ID }, quantity).quantity;
quantity = _atelierLogic.AddDress(new AtelierBindingModel { ID = atelier.ID }, new DressBindingModel { ID = model.DressID }, quantity).quantity;
}
if (quantity > 0)
{
throw new Exception("Shops' storages are full.");
model.Status = OrderStatus.Given;
model.DateImplement = DateTime.Now;
_orderStorage.Update(model);
}
}
catch (Exception ex)
@ -82,11 +87,7 @@ namespace DressAtelierBusinessLogic.BusinessLogic
throw new OverflowException("Shops' storages are full.");
}
scope.Complete();
model.Status = OrderStatus.Given;
model.DateImplement = DateTime.Now;
_orderStorage.Update(model);
return true;
}

View File

@ -17,6 +17,7 @@ namespace DressAtelierContracts.BusinessLogicContracts
bool Create(AtelierBindingModel model);
bool Update(AtelierBindingModel model);
bool Delete(AtelierBindingModel model);
bool CheckQuantity(int quantity);
bool SellDress(DressSearchModel model, int quantity);
}
}

View File

@ -17,7 +17,7 @@ namespace DressAtelierContracts.StorageContracts
AtelierViewModel? Insert(AtelierBindingModel model);
AtelierViewModel? Update(AtelierBindingModel model);
AtelierViewModel? Delete(AtelierBindingModel model);
AtelierViewModel? CheckDressesQuantity(DressSearchModel model, int quantity);
bool CheckDressesQuantity(int quantity);
bool SellDresses(DressSearchModel model, int quantity);
}
}

View File

@ -98,37 +98,33 @@ namespace DressAtelierFileImplement.Implements
return _source.Ateliers.Select(x => x.GetViewModel).ToList();
}
public AtelierViewModel? CheckDressesQuantity(DressSearchModel model, int quantity)
public bool CheckDressesQuantity(int quantity)
{
var ateliers = GetFilteredList(new AtelierSearchModel { DressID = model.ID });
var ateliers = GetFullList();
foreach(var atelier in ateliers)
{
if (atelier.DressesList[model.ID.Value].Item2 >= quantity)
if (atelier.CurrentQuantity >= atelier.MaxTotalOfDresses || atelier.MaxTotalOfDresses < quantity)
{
return atelier;
return false;
}
}
return null;
return true;
}
public bool SellDresses(DressSearchModel model, int quantity)
{
(IDressModel, int) qnt = (null,0);
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
{
using (TransactionScope scope = new TransactionScope())
{
foreach (var atelier in ateliers)
{
if(requiredQuantity - atelier.DressesList[model.ID.Value].Item2 > 0)
if (requiredQuantity - atelier.DressesList[model.ID.Value].Item2 > 0)
{
requiredQuantity -= atelier.DressesList[model.ID.Value].Item2;
atelier.DressesList.Remove(model.ID.Value);
@ -155,26 +151,16 @@ namespace DressAtelierFileImplement.Implements
throw new Exception("Not enough dresses in ateliers");
}
_source.SaveAteliers();
scope.Complete();
}
return true;
}
catch (Exception ex)
{
return false;
}
}
qnt = specatelier.DressesList[model.ID.Value];
qnt.Item2 -= quantity;
specatelier.DressesList[model.ID.Value] = qnt;
specatelier.DressesList.Remove(model.ID.Value);
Update(new AtelierBindingModel
{
ID = specatelier.ID,
DressesList = specatelier.DressesList
});
return true;
}

View File

@ -88,7 +88,7 @@ namespace DressAtelierFileImplement.Implements
return null;
}
var order = model.GetViewModel;
var dress = _source.Dresses.FirstOrDefault(un => un.ID == order.ID);
var dress = _source.Dresses.FirstOrDefault(un => un.ID == model.DressID);
order.DressName = dress == null ? "" : dress.DressName;
return order;

View File

@ -99,12 +99,12 @@ namespace DressAtelierListImplement.Implements
return null;
}
public AtelierViewModel? CheckDressesQuantity(DressSearchModel model, int quantity)
public bool SellDresses(DressSearchModel model, int quantity)
{
throw new NotImplementedException();
}
public bool SellDresses(DressSearchModel model, int quantity)
public bool CheckDressesQuantity(int quantity)
{
throw new NotImplementedException();
}

View File

@ -102,6 +102,10 @@ namespace SewingDresses
_logger.LogInformation("Restocking of atelier");
try
{
if(!_logicAtelier.CheckQuantity(Convert.ToInt32(quantityTextBox.Text)))
{
throw new OverflowException("Max capacity is lower than restocking size");
}
_logicAtelier.AddDress(new AtelierBindingModel
{

View File

@ -103,7 +103,7 @@ namespace SewingDresses
{
if (dataGridView.SelectedRows.Count == 1)
{
int id = Convert.ToInt32(dataGridView.SelectedRows[0].Cells["DressID"].Value);
int id = Convert.ToInt32(dataGridView.SelectedRows[0].Cells["ID"].Value);
_logger.LogInformation("Order №{id}. Changing status to 'In process'", id);
try
{
@ -137,7 +137,7 @@ namespace SewingDresses
{
if (dataGridView.SelectedRows.Count == 1)
{
int id = Convert.ToInt32(dataGridView.SelectedRows[0].Cells["DressID"].Value);
int id = Convert.ToInt32(dataGridView.SelectedRows[0].Cells["ID"].Value);
_logger.LogInformation("Order №{id}. Changing status to 'Ready'", id);
try
{
@ -171,7 +171,7 @@ namespace SewingDresses
{
if (dataGridView.SelectedRows.Count == 1)
{
int id = Convert.ToInt32(dataGridView.SelectedRows[0].Cells["DressID"].Value);
int id = Convert.ToInt32(dataGridView.SelectedRows[0].Cells["ID"].Value);
_logger.LogInformation("Order №{id}. Changing status to 'Given'", id);
try
{