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

View File

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