Теперь точно финал (надеюсь)

This commit is contained in:
Marselchi 2024-04-22 10:17:21 +04:00
parent cf10d844e0
commit dac2817806
3 changed files with 41 additions and 32 deletions

View File

@ -88,19 +88,23 @@ namespace ShipyardBusinessLogic.BusinessLogics
}
public bool StatusUpdate(OrderBindingModel model, OrderStatus newStatus)
{
var viewModel = _orderStorage.GetElement(new OrderSearchModel { Id = model.Id });
if (viewModel.Status + 1 != newStatus)
CheckModel(model, false);
var viewModel = _orderStorage.GetElement(new OrderSearchModel { Id = model.Id });
if (viewModel.Status + 1 != newStatus)
{
_logger.LogWarning("Status update to " + newStatus.ToString() + " operation failed. Order status incorrect.");
return false;
}
model.Status = newStatus;
if (model.Status == OrderStatus.Готов) model.DateImplement = DateTime.Now;
throw new InvalidOperationException("Невозможно перевести состояние заказа");
}
if (viewModel.ImplementerId.HasValue)
{
model.ImplementerId = viewModel.ImplementerId;
}
model.Status = newStatus;
if (model.Status == OrderStatus.Готов) model.DateImplement = DateTime.Now;
else
{
model.DateImplement = viewModel.DateImplement;
}
CheckModel(model, false);
if (_orderStorage.Update(model) == null)
{
model.Status--;
@ -111,10 +115,11 @@ namespace ShipyardBusinessLogic.BusinessLogics
}
public bool TakeOrderInWork(OrderBindingModel model)
{
lock (locker)
{
return StatusUpdate(model, OrderStatus.Выполняется);
}
lock (locker)
{
return StatusUpdate(model, OrderStatus.Выполняется);
}
}
public bool DeliveryOrder(OrderBindingModel model)

View File

@ -66,33 +66,40 @@ namespace ShipyardDataBaseImplement.Implements
{
using var context = new ShipyardDataBase();
if (model.DateFrom.HasValue && model.DateTo.HasValue)
{
{
return context.Orders
.Include(x => x.Ship)
.Include(x => x.Client)
.Include(x => x.Implementer)
.Where(x => x.DateCreate >= model.DateFrom && x.DateCreate <= model.DateTo)
.Select(x => x.GetViewModel)
.Include(x => x.Implementer)
.Where(x => x.DateCreate >= model.DateFrom && x.DateCreate <= model.DateTo)
.Select(x => x.GetViewModel)
.ToList();
}
else if (model.ClientId.HasValue)
{
{
return context.Orders
.Include(x => x.Ship)
.Include(x => x.Client)
.Include(x => x.Implementer)
.Where(x => x.ClientId == model.ClientId)
.Select(x => x.GetViewModel)
.Include(x => x.Client).Include(x => x.Implementer)
.Where(x => x.ClientId == model.ClientId)
.Select(x => x.GetViewModel)
.ToList();
}
else if (model.Status.HasValue)
{
{
return context.Orders
.Include(x => x.Ship)
.Include(x => x.Client).Include(x => x.Implementer)
.Where(x => x.Status == model.Status)
.Select(x => x.GetViewModel)
.ToList();
}
else if (model.Id.HasValue)
{
return context.Orders
.Include(x => x.Ship)
.Include(x => x.Client)
.Include(x => x.Implementer)
.Where(x => x.Id == model.Id)
.Select(x => x.GetViewModel)
.Include(x => x.Client).Include(x => x.Implementer)
.Where(x => x.Id == model.Id)
.Select(x => x.GetViewModel)
.ToList();
}
return new();

View File

@ -1,18 +1,15 @@
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<nlog xmlns="http://www.nlog-project.org/schemas/NLog.xsd"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
autoReload="true" internalLogLevel="Info">
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
autoReload="true" internalLogLevel="Info">
<targets>
<target xsi:type="File" name="tofile" fileName="logs/log-${shortdate}.log" />
<target xsi:type="File" name="tofile" fileName="log-${shortdate}.log" />
</targets>
<target name="console" xsi:type="Console" layout="Access Log|${level:uppercase=true}|${logger}|${message}">
<highlight-row condition="true" foregroundColor="red"/>
</target>
<rules>
<logger name="*" minlevel="Info" writeTo="tofile,console" />
<logger name="*" minlevel="Debug" writeTo="tofile" />
</rules>
</nlog>
</configuration>