Merge branch 'LabWork03_Base' into LabWork04_Base

This commit is contained in:
Данила Мочалов 2023-03-11 15:08:49 +04:00
commit 0084e1ed13
2 changed files with 20 additions and 16 deletions

View File

@ -3,6 +3,7 @@ using LawFirmContracts.SearchModels;
using LawFirmContracts.StorageContracts;
using LawFirmContracts.ViewModels;
using LawFirmDatabaseImplement.Models;
using Microsoft.EntityFrameworkCore;
using System;
using System.Collections.Generic;
using System.Linq;
@ -21,15 +22,12 @@ namespace LawFirmDatabaseImplement.Implements
return null;
}
using var context = new LawFirmDatabase();
/*return context.Documents.FirstOrDefault(x =>
(!string.IsNullOrEmpty(model.DocumentName) && x.DocumentName == model.DocumentName)
|| (model.Id.HasValue && x.Id == model.Id))?.GetViewModel;*/
var element = context.Documents.FirstOrDefault(x =>
(!string.IsNullOrEmpty(model.DocumentName) && x.DocumentName == model.DocumentName)
|| (model.Id.HasValue && x.Id == model.Id));
return element?.GetViewModel;
return context.Documents.Include(x => x.Blanks)
.ThenInclude(x => x.Blank)
.FirstOrDefault(x => (!string.IsNullOrEmpty(model.DocumentName) &&
x.DocumentName == model.DocumentName) ||
(model.Id.HasValue && x.Id == model.Id))
?.GetViewModel;
}
public List<DocumentViewModel> GetFilteredList(DocumentSearchModel model)
@ -39,20 +37,24 @@ namespace LawFirmDatabaseImplement.Implements
return new();
}
using var context = new LawFirmDatabase();
/*return context.Documents
return context.Documents
.Include(x => x.Blanks)
.ThenInclude(x => x.Blank)
.Where(x => x.DocumentName.Contains(model.DocumentName))
.ToList()
.Select(x => x.GetViewModel)
.ToList();*/
var filteredList = context.Documents.Where(x => x.DocumentName.Contains(model.DocumentName)).ToList();
return filteredList.Select(x=> x.GetViewModel).ToList();
.ToList();
}
public List<DocumentViewModel> GetFullList()
{
using var context = new LawFirmDatabase();
//return context.Documents.Select(x => x.GetViewModel).ToList();
var fullList = context.Documents.ToList();
return fullList.Select(x => x.GetViewModel).ToList();
return context.Documents
.Include(x => x.Blanks)
.ThenInclude(x => x.Blank)
.ToList()
.Select(x => x.GetViewModel)
.ToList();
}
public DocumentViewModel? Insert(DocumentBindingModel model)

View File

@ -42,6 +42,8 @@ namespace LawFirmDatabaseImplement.Models
public static Document? Create(LawFirmDatabase context, DocumentBindingModel model)
{
var blanks = context.Blanks;
return new Document()
{
Id = model.Id,