private IQueryable<MAOrder> GetOrders()
{
var query = context.Orders.AsSplitQuery()
.Include(x => x.Counterparty)
.Include(x => x.Positions).ThenInclude(x => x.Category)
.Include(x => x.Positions).ThenInclude(x => x.Status)
.Include(x => x.Status)
.Include(x => x.PaymentType)
.Include(x => x.Creator)
.Include(x => x.Worker);
return query;
}
return GetOrders().Where(x => !x.IsCompleted && x.IsInArchive == isInArchive && !x.Presets.Any()).Select(x => new MAOrder
{
Id = x.Id,
DateStart = x.DateStart,
Amount = x.Amount,
IsCompleted = x.IsCompleted,
IsPaid = x.IsPaid,
IsReady = x.IsReady,
Positions = x.Positions.Select(p => new MAOrderPosition
{
Comment = p.Comment,
Cost = p.Cost,
Count = p.Count,
Description = p.Description,
IsCompleted = p.IsCompleted,
IsReady = p.IsReady,
IsReOrder = x.IsReOrder,
Status = p.Status == null ? null : new MAOrderStatus
{
Id = p.Id,
Name = p.Status.Name,
Color = p.Status.Color,
},
Category = p.Category == null ? null : new MAOrderCategory
{
Id = p.Category.Id,
Name = p.Category.Name,
Color = p.Category.Color,
}
}).ToList(),
Counterparty = x.Counterparty == null ? null : new MACounterparty
{
Id = x.Counterparty.Id,
Name = x.Counterparty.Name,
Telephone = x.Counterparty.Telephone
},
Status = x.Status == null ? null : new MAOrderStatus
{
Id = x.Status.Id,
Name = x.Status.Name,
Color = x.Status.Color
}
}).AsNoTracking().ToListAsync();
.Select(x => new MAOrder
{
Positions = x.Positions.Select(p => new MAOrderPosition
{
Status = p.Status == null ? null : new MAOrderStatus
{
Name = p.Status.Name,
Color = p.Status.Color
}
})
})