Compare commits
No commits in common. "bb74221578f917d9ed37b97071012ee3c4bd1393" and "6a68de1873eac1a354b8aac728d2d926b126b35a" have entirely different histories.
bb74221578
...
6a68de1873
@ -66,9 +66,10 @@ namespace LawFirmView
|
|||||||
try
|
try
|
||||||
{
|
{
|
||||||
var operationResult = _logicS.SellDocument(
|
var operationResult = _logicS.SellDocument(
|
||||||
new DocumentBindingModel
|
new DocumentSearchModel
|
||||||
{
|
{
|
||||||
Id = Convert.ToInt32(comboBoxDocument.SelectedValue)
|
Id = Convert.ToInt32(comboBoxDocument.SelectedValue),
|
||||||
|
DocumentName = comboBoxDocument.Text
|
||||||
},
|
},
|
||||||
Convert.ToInt32(textBoxCount.Text)
|
Convert.ToInt32(textBoxCount.Text)
|
||||||
);
|
);
|
||||||
|
@ -17,16 +17,11 @@ 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)
|
||||||
@ -78,22 +73,6 @@ 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)
|
||||||
|
@ -116,68 +116,8 @@ 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;
|
|
||||||
}
|
|
||||||
|
|
||||||
int freeSpace = 0;
|
public bool SellDocument(DocumentSearchModel document, int count)
|
||||||
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);
|
||||||
}
|
}
|
||||||
|
@ -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 CheckThenSupplyMany(IDocumentModel document, int count);
|
bool SellDocument(DocumentSearchModel document, int count);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,7 +1,6 @@
|
|||||||
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;
|
||||||
@ -18,6 +17,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(IDocumentModel model, int count);
|
bool SellDocument(DocumentSearchModel model, int count);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -2,7 +2,6 @@
|
|||||||
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;
|
||||||
@ -81,9 +80,9 @@ namespace LawFirmFileImplement.Implements
|
|||||||
return shop.GetViewModel;
|
return shop.GetViewModel;
|
||||||
}
|
}
|
||||||
|
|
||||||
public bool SellDocument(IDocumentModel model, int count)
|
public bool SellDocument(DocumentSearchModel model, int count)
|
||||||
{
|
{
|
||||||
var document = source.Documents.FirstOrDefault(x => x.Id == model.Id);
|
var document = source.Documents.FirstOrDefault(x => model.Id.HasValue && x.Id == model.Id);
|
||||||
|
|
||||||
var countStore = count;
|
var countStore = count;
|
||||||
|
|
||||||
@ -143,9 +142,7 @@ namespace LawFirmFileImplement.Implements
|
|||||||
MaxCountDocuments = shop.MaxCountDocuments,
|
MaxCountDocuments = shop.MaxCountDocuments,
|
||||||
ShopDocuments = documents
|
ShopDocuments = documents
|
||||||
});
|
});
|
||||||
source.SaveShops();
|
|
||||||
return true;
|
return true;
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -158,7 +155,6 @@ namespace LawFirmFileImplement.Implements
|
|||||||
MaxCountDocuments = shop.MaxCountDocuments,
|
MaxCountDocuments = shop.MaxCountDocuments,
|
||||||
ShopDocuments = documents
|
ShopDocuments = documents
|
||||||
});
|
});
|
||||||
source.SaveShops();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (count > 0)
|
if (count > 0)
|
||||||
|
@ -2,7 +2,6 @@
|
|||||||
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;
|
||||||
@ -117,7 +116,7 @@ namespace LawFirmListImplements.Implements
|
|||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
public bool SellDocument(IDocumentModel model, int count)
|
public bool SellDocument(DocumentSearchModel model, int count)
|
||||||
{
|
{
|
||||||
throw new NotImplementedException();
|
throw new NotImplementedException();
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user