Compare commits

..

2 Commits

7 changed files with 97 additions and 11 deletions

View File

@ -66,10 +66,9 @@ namespace LawFirmView
try try
{ {
var operationResult = _logicS.SellDocument( var operationResult = _logicS.SellDocument(
new DocumentSearchModel new DocumentBindingModel
{ {
Id = Convert.ToInt32(comboBoxDocument.SelectedValue), Id = Convert.ToInt32(comboBoxDocument.SelectedValue)
DocumentName = comboBoxDocument.Text
}, },
Convert.ToInt32(textBoxCount.Text) Convert.ToInt32(textBoxCount.Text)
); );

View File

@ -17,11 +17,16 @@ namespace LawFirmBusinessLogic.BusinessLogics
{ {
private readonly ILogger _logger; private readonly ILogger _logger;
private readonly IOrderStorage _orderStorage; private readonly IOrderStorage _orderStorage;
private readonly IShopLogic _shopLogic;
private readonly IDocumentStorage _documentStorage;
public OrderLogic(ILogger<OrderLogic> logger, IOrderStorage orderStorage)
public OrderLogic(ILogger<OrderLogic> logger, IOrderStorage orderStorage, IShopLogic shopLogic, IDocumentStorage documentStorage)
{ {
_logger = logger; _logger = logger;
_orderStorage = orderStorage; _orderStorage = orderStorage;
_shopLogic = shopLogic;
_documentStorage = documentStorage;
} }
public bool CreateOrder(OrderBindingModel model) public bool CreateOrder(OrderBindingModel model)
@ -73,6 +78,22 @@ namespace LawFirmBusinessLogic.BusinessLogics
_logger.LogWarning("Status update to " + newStatus.ToString() +" operation failed. Order status incorrect."); _logger.LogWarning("Status update to " + newStatus.ToString() +" operation failed. Order status incorrect.");
return false; return false;
} }
if (newStatus == OrderStatus.Готов)
{
var document = _documentStorage.GetElement(new DocumentSearchModel() { Id = model.DocumentId});
if (document == null)
{
_logger.LogWarning("Status update to " + newStatus.ToString() + " operation failed. Document not found.");
return false;
}
if (_shopLogic.CheckThenSupplyMany(document, model.Count) == false)
{
_logger.LogWarning("Status update to " + newStatus.ToString() + " operation failed. Shop supply error.");
return false;
}
}
model.Status = newStatus; model.Status = newStatus;
if (model.Status == OrderStatus.Выдан) model.DateImplement = DateTime.Now; if (model.Status == OrderStatus.Выдан) model.DateImplement = DateTime.Now;
if (_orderStorage.Update(model) == null) if (_orderStorage.Update(model) == null)

View File

@ -116,8 +116,68 @@ namespace LawFirmBusinessLogic.BusinessLogics
} }
return true; return true;
} }
public bool CheckThenSupplyMany(IDocumentModel document, int count)
{
if (count <= 0)
{
_logger.LogWarning("Check then supply operation error. Document count < 0.");
return false;
}
public bool SellDocument(DocumentSearchModel document, int count) int freeSpace = 0;
foreach(var shop in _shopStorage.GetFullList())
{
freeSpace += shop.MaxCountDocuments;
foreach (var doc in shop.ShopDocuments)
{
freeSpace -= doc.Value.Item2;
}
}
if (freeSpace - count < 0)
{
_logger.LogWarning("Check then supply operation error. There's no place for new docs in shops.");
return false;
}
foreach (var shop in _shopStorage.GetFullList())
{
freeSpace = shop.MaxCountDocuments;
foreach (var doc in shop.ShopDocuments)
{
freeSpace -= doc.Value.Item2;
}
if (freeSpace == 0)
{
continue;
}
if (freeSpace - count >= 0)
{
if (SupplyDocuments(new() { Id = shop.Id}, document, count)) count = 0;
else
{
_logger.LogWarning("Supply error");
return false;
}
}
if (freeSpace - count < 0)
{
if (SupplyDocuments(new() { Id = shop.Id }, document, freeSpace)) count-= freeSpace;
else
{
_logger.LogWarning("Supply error");
return false;
}
}
if (count <= 0)
{
return true;
}
}
return false;
}
public bool SellDocument(IDocumentModel document, int count)
{; {;
return _shopStorage.SellDocument(document, count); return _shopStorage.SellDocument(document, count);
} }

View File

@ -18,7 +18,7 @@ namespace LawFirmContracts.BusinessLogicContracts
bool Update(ShopBindingModel model); bool Update(ShopBindingModel model);
bool Delete(ShopBindingModel model); bool Delete(ShopBindingModel model);
bool SupplyDocuments(ShopSearchModel model, IDocumentModel document, int count); bool SupplyDocuments(ShopSearchModel model, IDocumentModel document, int count);
bool SellDocument(IDocumentModel document, int count);
bool SellDocument(DocumentSearchModel document, int count); bool CheckThenSupplyMany(IDocumentModel document, int count);
} }
} }

View File

@ -1,6 +1,7 @@
using LawFirmContracts.BindingModels; using LawFirmContracts.BindingModels;
using LawFirmContracts.SearchModels; using LawFirmContracts.SearchModels;
using LawFirmContracts.ViewModels; using LawFirmContracts.ViewModels;
using LawFirmDataModels.Models;
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Linq; using System.Linq;
@ -17,6 +18,6 @@ namespace LawFirmContracts.StorageContracts
ShopViewModel? Insert(ShopBindingModel model); ShopViewModel? Insert(ShopBindingModel model);
ShopViewModel? Update(ShopBindingModel model); ShopViewModel? Update(ShopBindingModel model);
ShopViewModel? Delete(ShopBindingModel model); ShopViewModel? Delete(ShopBindingModel model);
bool SellDocument(DocumentSearchModel model, int count); bool SellDocument(IDocumentModel model, int count);
} }
} }

View File

@ -2,6 +2,7 @@
using LawFirmContracts.SearchModels; using LawFirmContracts.SearchModels;
using LawFirmContracts.StorageContracts; using LawFirmContracts.StorageContracts;
using LawFirmContracts.ViewModels; using LawFirmContracts.ViewModels;
using LawFirmDataModels.Models;
using LawFirmFileImplement.Models; using LawFirmFileImplement.Models;
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
@ -80,9 +81,9 @@ namespace LawFirmFileImplement.Implements
return shop.GetViewModel; return shop.GetViewModel;
} }
public bool SellDocument(DocumentSearchModel model, int count) public bool SellDocument(IDocumentModel model, int count)
{ {
var document = source.Documents.FirstOrDefault(x => model.Id.HasValue && x.Id == model.Id); var document = source.Documents.FirstOrDefault(x => x.Id == model.Id);
var countStore = count; var countStore = count;
@ -142,7 +143,9 @@ namespace LawFirmFileImplement.Implements
MaxCountDocuments = shop.MaxCountDocuments, MaxCountDocuments = shop.MaxCountDocuments,
ShopDocuments = documents ShopDocuments = documents
}); });
source.SaveShops();
return true; return true;
} }
} }
@ -155,6 +158,7 @@ namespace LawFirmFileImplement.Implements
MaxCountDocuments = shop.MaxCountDocuments, MaxCountDocuments = shop.MaxCountDocuments,
ShopDocuments = documents ShopDocuments = documents
}); });
source.SaveShops();
} }
if (count > 0) if (count > 0)

View File

@ -2,6 +2,7 @@
using LawFirmContracts.SearchModels; using LawFirmContracts.SearchModels;
using LawFirmContracts.StorageContracts; using LawFirmContracts.StorageContracts;
using LawFirmContracts.ViewModels; using LawFirmContracts.ViewModels;
using LawFirmDataModels.Models;
using LawFirmListImplements.Models; using LawFirmListImplements.Models;
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
@ -116,7 +117,7 @@ namespace LawFirmListImplements.Implements
return null; return null;
} }
public bool SellDocument(DocumentSearchModel model, int count) public bool SellDocument(IDocumentModel model, int count)
{ {
throw new NotImplementedException(); throw new NotImplementedException();
} }