Compare commits

..

No commits in common. "0b296d433f419d21eee0c781bb32a258a42f0167" and "842ec7cded66b3d62c8b82bbfef91bc8f2bfa7eb" have entirely different histories.

2 changed files with 9 additions and 10 deletions

View File

@ -21,7 +21,7 @@ namespace LawFirmDatabaseImplement.Implements
return null; return null;
} }
using var context = new LawFirmDatabase(); using var context = new LawFirmDatabase();
return context.Orders.Include(x => x.Document).Include(x => x.Client).FirstOrDefault(x => (model.Id.HasValue && x.Id == model.Id))?.GetViewModel; return context.Orders.Include(x => x.Document).FirstOrDefault(x => (model.Id.HasValue && x.Id == model.Id))?.GetViewModel;
} }
public List<OrderViewModel> GetFilteredList(OrderSearchModel model) public List<OrderViewModel> GetFilteredList(OrderSearchModel model)
@ -34,14 +34,12 @@ namespace LawFirmDatabaseImplement.Implements
if (model.ClientId.HasValue) if (model.ClientId.HasValue)
{ {
return context.Orders return context.Orders
.Include(x => x.Document)
.Include(x => x.Client) .Include(x => x.Client)
.Where(x => x.ClientId == model.ClientId) .Where(x => x.ClientId == model.ClientId)
.Select(x => x.GetViewModel) .Select(x => x.GetViewModel)
.ToList(); .ToList();
} }
return context.Orders return context.Orders
.Include(x => x.Client)
.Include(x => x.Document) .Include(x => x.Document)
.Where(x => x.Id == model.Id || model.DateFrom <= x.DateCreate && x.DateCreate <= model.DateTo) .Where(x => x.Id == model.Id || model.DateFrom <= x.DateCreate && x.DateCreate <= model.DateTo)
.Select(x => x.GetViewModel) .Select(x => x.GetViewModel)
@ -51,7 +49,7 @@ namespace LawFirmDatabaseImplement.Implements
public List<OrderViewModel> GetFullList() public List<OrderViewModel> GetFullList()
{ {
using var context = new LawFirmDatabase(); using var context = new LawFirmDatabase();
return context.Orders.Include(x => x.Document).Include(x => x.Client).Select(x => x.GetViewModel).ToList(); return context.Orders.Include(x => x.Document).Select(x => x.GetViewModel).ToList();
} }
public OrderViewModel? Insert(OrderBindingModel model) public OrderViewModel? Insert(OrderBindingModel model)
@ -64,7 +62,7 @@ namespace LawFirmDatabaseImplement.Implements
using var context = new LawFirmDatabase(); using var context = new LawFirmDatabase();
context.Orders.Add(newOrder); context.Orders.Add(newOrder);
context.SaveChanges(); context.SaveChanges();
return context.Orders.Include(x => x.Document).Include(x => x.Client).FirstOrDefault(x => x.Id == newOrder.Id)?.GetViewModel; return context.Orders.Include(x => x.Document).FirstOrDefault(x => x.Id == newOrder.Id)?.GetViewModel;
} }
public OrderViewModel? Update(OrderBindingModel model) public OrderViewModel? Update(OrderBindingModel model)
@ -77,7 +75,7 @@ namespace LawFirmDatabaseImplement.Implements
} }
order.Update(model); order.Update(model);
context.SaveChanges(); context.SaveChanges();
return context.Orders.Include(x => x.Document).Include(x => x.Client).FirstOrDefault(x => x.Id == model.Id)?.GetViewModel; return context.Orders.Include(x => x.Document).FirstOrDefault(x => x.Id == model.Id)?.GetViewModel;
} }
public OrderViewModel? Delete(OrderBindingModel model) public OrderViewModel? Delete(OrderBindingModel model)
{ {

View File

@ -63,6 +63,7 @@ namespace LawFirmDatabaseImplement.Models
public OrderViewModel GetViewModel { public OrderViewModel GetViewModel {
get get
{ {
var context = new LawFirmDatabase();
return new () return new ()
{ {
@ -74,8 +75,8 @@ namespace LawFirmDatabaseImplement.Models
DateImplement = DateImplement, DateImplement = DateImplement,
Id = Id, Id = Id,
Status = Status, Status = Status,
DocumentName = Document.DocumentName, DocumentName = context.Documents.FirstOrDefault(x => x.Id == DocumentId)?.DocumentName ?? string.Empty,
ClientFIO = Client.ClientFIO ClientFIO = context.Clients.FirstOrDefault(x => x.Id == ClientId)?.ClientFIO ?? string.Empty
}; };
} }
} }