Compare commits

...

3 Commits

Author SHA1 Message Date
33e0d1f750 fix 2023-04-10 10:44:37 +04:00
42ebe7410b merge 2023-04-10 10:39:35 +04:00
07dc03d48a fix 2023-04-10 10:35:15 +04:00
2 changed files with 13 additions and 11 deletions

View File

@ -43,6 +43,7 @@ namespace LawFirmDatabaseImplement.Implements
return context.Orders
.Include(x => x.Client)
.Include(x => x.Implementer)
.Include(x => x.Document)
.Where(x => x.ClientId == model.ClientId)
.Select(x => x.GetViewModel)
.ToList();
@ -50,7 +51,8 @@ namespace LawFirmDatabaseImplement.Implements
if (model.Status!= null)
{
return context.Orders
.Include(x => x.Client)
.Include(x => x.Document)
.Include(x => x.Client)
.Include(x => x.Implementer)
.Where(x => model.Status.Equals(x.Status))
.Select(x => x.GetViewModel)
@ -58,7 +60,8 @@ namespace LawFirmDatabaseImplement.Implements
}
return context.Orders
.Include(x => x.Document)
.Include(x => x.Implementer)
.Include(x => x.Client)
.Include(x => x.Implementer)
.Where(x => x.Id == model.Id || model.DateFrom <= x.DateCreate && x.DateCreate <= model.DateTo)
.Select(x => x.GetViewModel)
.ToList();
@ -67,7 +70,7 @@ namespace LawFirmDatabaseImplement.Implements
public List<OrderViewModel> GetFullList()
{
using var context = new LawFirmDatabase();
return context.Orders.Include(x => x.Document).Include(x => x.Implementer).Select(x => x.GetViewModel).ToList();
return context.Orders.Include(x => x.Document).Include(x => x.Client).Include(x => x.Implementer).Select(x => x.GetViewModel).ToList();
}
public OrderViewModel? Insert(OrderBindingModel model)
@ -80,7 +83,7 @@ namespace LawFirmDatabaseImplement.Implements
using var context = new LawFirmDatabase();
context.Orders.Add(newOrder);
context.SaveChanges();
return context.Orders.Include(x => x.Document).FirstOrDefault(x => x.Id == newOrder.Id)?.GetViewModel;
return context.Orders.Include(x => x.Document).Include(x => x.Client).Include(x => x.Implementer).FirstOrDefault(x => x.Id == newOrder.Id)?.GetViewModel;
}
public OrderViewModel? Update(OrderBindingModel model)
@ -93,12 +96,13 @@ namespace LawFirmDatabaseImplement.Implements
}
order.Update(model);
context.SaveChanges();
return context.Orders.Include(x => x.Document).Include(x => x.Implementer).FirstOrDefault(x => x.Id == model.Id)?.GetViewModel;
return context.Orders.Include(x => x.Document).Include(x => x.Client).Include(x => x.Implementer).FirstOrDefault(x => x.Id == model.Id)?.GetViewModel;
}
public OrderViewModel? Delete(OrderBindingModel model)
{
using var context = new LawFirmDatabase();
var element = context.Orders
.Include(x => x.Document)
.Include(x => x.Client)
.Include(x => x.Implementer)
.FirstOrDefault(x => x.Id == model.Id);

View File

@ -31,7 +31,7 @@ namespace LawFirmDatabaseImplement.Models
public DateTime? DateImplement { get; private set; }
public virtual Document Document { get; set; }
public virtual Client Client { get; set; }
public Implementer? Implementer { get; private set; }
public virtual Implementer? Implementer { get; set; }
public static Order? Create(OrderBindingModel? model)
{
@ -67,10 +67,8 @@ namespace LawFirmDatabaseImplement.Models
public OrderViewModel GetViewModel {
get
{
var context = new LawFirmDatabase();
return new ()
{
DocumentId = DocumentId,
ClientId = ClientId,
ImplementerId = ImplementerId,
@ -80,9 +78,9 @@ namespace LawFirmDatabaseImplement.Models
DateImplement = DateImplement,
Id = Id,
Status = Status,
DocumentName = context.Documents.FirstOrDefault(x => x.Id == DocumentId)?.DocumentName ?? string.Empty,
ClientFIO = context.Clients.FirstOrDefault(x => x.Id == ClientId)?.ClientFIO ?? string.Empty,
ImplementerFIO = context.Implementers.FirstOrDefault(x => x.Id == ImplementerId)?.ImplementerFIO?? string.Empty,
DocumentName = Document.DocumentName,
ClientFIO = Client.ClientFIO,
ImplementerFIO = Implementer?.ImplementerFIO ?? string.Empty,
};
}
}