Петрушин Егор ПИбд-22 Лабораторная №3 Юридическая фирма #3

Closed
Egor_Petrushin wants to merge 3 commits from Lab3 into Lab2
9 changed files with 223 additions and 73 deletions
Showing only changes of commit 41531f9761 - Show all commits

View File

@ -14,7 +14,7 @@ namespace AbstractLawFirmDataBaseImplement
{
if (optionsBuilder.IsConfigured == false)
{
optionsBuilder.UseSqlServer(@"Data Source=GOKA\SQLEXPRESS;Initial Catalog=AbstractLawFirmDataBase Full;Integrated Security=True;MultipleActiveResultSets=True;;TrustServerCertificate=True");
optionsBuilder.UseSqlServer(@"Data Source=DESKTOP-N8BRIPR\SQLEXPRESS;Initial Catalog=AbstractLawFirmDataBaseFull;Integrated Security=True;MultipleActiveResultSets=True;;TrustServerCertificate=True");
}
base.OnConfiguring(optionsBuilder);
}

View File

@ -2,8 +2,10 @@
using AbstractLawFirmContracts.SearchModels;
using AbstractLawFirmContracts.StoragesContracts;
using AbstractLawFirmContracts.ViewModels;
using AbstractLawFirmDataBaseImplement;
using AbstractLawFirmDataBaseImplement.Models;
using System;
using System.Collections.Generic;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
@ -11,35 +13,72 @@ using System.Threading.Tasks;
namespace AbstractLawFirmDatabaseImplement.Implements
{
public class ComponentStorage : IComponentStorage
{
public ComponentViewModel? Delete(ComponentBindingModel model)
{
throw new NotImplementedException();
}
public ComponentViewModel? GetElement(ComponentSearchModel model)
{
throw new NotImplementedException();
}
public List<ComponentViewModel> GetFilteredList(ComponentSearchModel model)
{
throw new NotImplementedException();
}
public List<ComponentViewModel> GetFullList()
{
throw new NotImplementedException();
}
public ComponentViewModel? Insert(ComponentBindingModel model)
{
throw new NotImplementedException();
}
public ComponentViewModel? Update(ComponentBindingModel model)
{
throw new NotImplementedException();
}
{
public List<ComponentViewModel> GetFullList()
{
using var context = new AbstractLawFirmDataBase();
return context.Components
.Select(x => x.GetViewModel)
.ToList();
}
public List<ComponentViewModel> GetFilteredList(ComponentSearchModel model)
{
if (string.IsNullOrEmpty(model.ComponentName))
{
return new();
}
using var context = new AbstractLawFirmDataBase();
return context.Components
.Where(x => x.ComponentName.Contains(model.ComponentName))
.Select(x => x.GetViewModel)
.ToList();
}
public ComponentViewModel? GetElement(ComponentSearchModel model)
{
if (string.IsNullOrEmpty(model.ComponentName) && !model.Id.HasValue)
{
return null;
}
using var context = new AbstractLawFirmDataBase();
return context.Components
.FirstOrDefault(x =>
(!string.IsNullOrEmpty(model.ComponentName) && x.ComponentName == model.ComponentName) || (model.Id.HasValue && x.Id == model.Id)) ?.GetViewModel;
}
public ComponentViewModel? Insert(ComponentBindingModel model)
{
var newComponent = Component.Create(model);
if (newComponent == null)
{
return null;
}
using var context = new AbstractLawFirmDataBase();
context.Components.Add(newComponent);
context.SaveChanges();
return newComponent.GetViewModel;
}
public ComponentViewModel? Update(ComponentBindingModel model)
{
using var context = new AbstractLawFirmDataBase();
var component = context.Components.FirstOrDefault(x => x.Id == model.Id);
if (component == null)
{
return null;
}
component.Update(model);
context.SaveChanges();
return component.GetViewModel;
}
public ComponentViewModel? Delete(ComponentBindingModel model)
{
using var context = new AbstractLawFirmDataBase();
var element = context.Components.FirstOrDefault(rec => rec.Id == model.Id);
if (element != null)
{
context.Components.Remove(element);
context.SaveChanges();
return element.GetViewModel;
}
return null;
}
}
}

View File

@ -3,6 +3,9 @@ using AbstractLawFirmContracts.BindingModels.BindingModels;
using AbstractLawFirmContracts.SearchModels;
using AbstractLawFirmContracts.StoragesContracts;
using AbstractLawFirmContracts.ViewModels;
using AbstractLawFirmDataBaseImplement;
using AbstractLawFirmDataBaseImplement.Models;
using Microsoft.EntityFrameworkCore;
using System;
using System.Collections.Generic;
using System.Linq;
@ -12,35 +15,98 @@ using System.Threading.Tasks;
namespace AbstractLawFirmDatabaseImplement.Implements
{
public class DocumentStorage : IDocumentStorage
{
public DocumentViewModel? Delete(DocumentBindingModel model)
{
throw new NotImplementedException();
}
public DocumentViewModel? GetElement(DocumentSearchModel model)
{
throw new NotImplementedException();
}
public List<DocumentViewModel> GetFilteredList(DocumentSearchModel model)
{
throw new NotImplementedException();
}
public List<DocumentViewModel> GetFullList()
{
throw new NotImplementedException();
}
public DocumentViewModel? Insert(DocumentBindingModel model)
{
throw new NotImplementedException();
}
public DocumentViewModel? Update(DocumentBindingModel model)
{
throw new NotImplementedException();
}
{
public List<DocumentViewModel> GetFullList()
{
using var context = new AbstractLawFirmDataBase();
return context.Documents
.Include(x => x.Components)
.ThenInclude(x => x.Component)
.ToList()
.Select(x => x.GetViewModel)
.ToList();
}
public List<DocumentViewModel> GetFilteredList(DocumentSearchModel model)
{
if (string.IsNullOrEmpty(model.DocumentName))
{
return new();
}
using var context = new AbstractLawFirmDataBase();
return context.Documents
.Include(x => x.Components)
.ThenInclude(x => x.Component)
.Where(x => x.DocumentName.Contains(model.DocumentName))
.ToList()
.Select(x => x.GetViewModel)
.ToList();
}
public DocumentViewModel? GetElement(DocumentSearchModel model)
{
if (string.IsNullOrEmpty(model.DocumentName) &&
!model.Id.HasValue)
{
return null;
}
using var context = new AbstractLawFirmDataBase();
return context.Documents
.Include(x => x.Components)
.ThenInclude(x => x.Component)
.FirstOrDefault(x => (!string.IsNullOrEmpty(model.DocumentName) &&
x.DocumentName == model.DocumentName) ||
(model.Id.HasValue && x.Id ==
model.Id))
?.GetViewModel;
}
public DocumentViewModel? Insert(DocumentBindingModel model)
{
using var context = new AbstractLawFirmDataBase();
var newDocument = Document.Create(context, model);
if (newDocument == null)
{
return null;
}
context.Documents.Add(newDocument);
context.SaveChanges();
return newDocument.GetViewModel;
}
public DocumentViewModel? Update(DocumentBindingModel model)
{
using var context = new AbstractLawFirmDataBase();
using var transaction = context.Database.BeginTransaction();
try
{
var product = context.Documents.FirstOrDefault(rec =>
rec.Id == model.Id);
if (product == null)
{
return null;
}
product.Update(model);
context.SaveChanges();
product.UpdateComponents(context, model);
transaction.Commit();
return product.GetViewModel;
}
catch
{
transaction.Rollback();
throw;
}
}
public DocumentViewModel? Delete(DocumentBindingModel model)
{
using var context = new AbstractLawFirmDataBase();
var element = context.Documents
.Include(x => x.Components)
.FirstOrDefault(rec => rec.Id == model.Id);
if (element != null)
{
context.Documents.Remove(element);
context.SaveChanges();
return element.GetViewModel;
}
return null;
}
}
}

View File

@ -2,11 +2,14 @@
using AbstractLawFirmContracts.SearchModels;
using AbstractLawFirmContracts.ViewModels;
using AbstractLawFirmContracts.StoragesContracts;
using AbstractLawFirmDataBaseImplement.Models;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using AbstractLawFirmDataBaseImplement;
using Microsoft.EntityFrameworkCore;
namespace AbstractLawFirmDatabaseImplement.Implements
{
@ -14,32 +17,74 @@ namespace AbstractLawFirmDatabaseImplement.Implements
{
public OrderViewModel? Delete(OrderBindingModel model)
{
throw new NotImplementedException();
using var context = new AbstractLawFirmDataBase();
var element = context.Orders.FirstOrDefault(rec => rec.Id == model.Id);
if (element != null)
{
context.Orders.Remove(element);
context.SaveChanges();
return element.GetViewModel;
}
return null;
}
public OrderViewModel? GetElement(OrderSearchModel model)
{
throw new NotImplementedException();
if (!model.Id.HasValue)
{
return null;
}
using var context = new AbstractLawFirmDataBase();
return context.Orders
.FirstOrDefault(x =>
(model.Id.HasValue && x.Id == model.Id))?.GetViewModel;
}
public List<OrderViewModel> GetFilteredList(OrderSearchModel model)
{
throw new NotImplementedException();
if (!model.Id.HasValue)
{
return new();
}
using var context = new AbstractLawFirmDataBase();
return context.Orders
.Where(x => x.Id == model.Id)
.Select(x => x.GetViewModel)
.ToList();
}
public List<OrderViewModel> GetFullList()
{
throw new NotImplementedException();
using var context = new AbstractLawFirmDataBase();
return context.Orders
.Select(x => x.GetViewModel)
.ToList();
}
public OrderViewModel? Insert(OrderBindingModel model)
{
throw new NotImplementedException();
var newOrder = Order.Create(model);
if (newOrder == null)
{
return null;
}
using var context = new AbstractLawFirmDataBase();
context.Orders.Add(newOrder);
context.SaveChanges();
return newOrder.GetViewModel;
}
public OrderViewModel? Update(OrderBindingModel model)
{
throw new NotImplementedException();
using var context = new AbstractLawFirmDataBase();
var component = context.Orders.FirstOrDefault(x => x.Id == model.Id);
if (component == null)
{
return null;
}
component.Update(model);
context.SaveChanges();
return component.GetViewModel;
}
}
}

View File

@ -19,7 +19,7 @@ namespace AbstractLawFirmDatabaseImplement.Migrations
{
#pragma warning disable 612, 618
modelBuilder
.HasAnnotation("ProductVersion", "6.0.28")
.HasAnnotation("DocumentVersion", "6.0.28")
.HasAnnotation("Relational:MaxIdentifierLength", 128);
SqlServerModelBuilderExtensions.UseIdentityColumns(modelBuilder, 1L, 1);

View File

@ -17,7 +17,7 @@ namespace AbstractLawFirmDatabaseImplement.Migrations
{
#pragma warning disable 612, 618
modelBuilder
.HasAnnotation("ProductVersion", "6.0.28")
.HasAnnotation("DocumentVersion", "6.0.28")
.HasAnnotation("Relational:MaxIdentifierLength", 128);
SqlServerModelBuilderExtensions.UseIdentityColumns(modelBuilder, 1L, 1);

View File

@ -15,7 +15,7 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "AbstractLawFirmListImplemen
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "AbstractLawFirmFileImplement", "AbstractLawFirmFileImpliment\AbstractLawFirmFileImplement.csproj", "{8AF960C2-208F-4B7B-9F8B-36B63446B6B7}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "AbstractLawFirmDatabaseImplement", "AbstractLawFirmDatabaseImplement\AbstractLawFirmDatabaseImplement.csproj", "{BF41FCA1-C12C-4D56-B29C-8BF1D9AE69B1}"
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "AbstractLawFirmDataBaseImplement", "AbstractLawFirmDatabaseImplement\AbstractLawFirmDataBaseImplement.csproj", "{BF41FCA1-C12C-4D56-B29C-8BF1D9AE69B1}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution

View File

@ -19,7 +19,7 @@
<ItemGroup>
<ProjectReference Include="..\AbstractLawFirmBusinessLogic\AbstractLawFirmBusinessLogic.csproj" />
<ProjectReference Include="..\AbstractLawFirmDatabaseImplement\AbstractLawFirmDatabaseImplement.csproj" />
<ProjectReference Include="..\AbstractLawFirmDatabaseImplement\AbstractLawFirmDataBaseImplement.csproj" />
<ProjectReference Include="..\AbstractLawFirmFileImpliment\AbstractLawFirmFileImplement.csproj" />
<ProjectReference Include="..\AbstractLawFirmListImplement\AbstractLawFirmListImplement.csproj" />
</ItemGroup>

View File

@ -1,7 +1,7 @@
using AbstractLawFirmBusinessLogic.BusinessLogic;
using AbstractLawFirmContracts.BusinessLogicsContracts;
using AbstractLawFirmContracts.StoragesContracts;
using AbstractLawFirmFileImplement.Implements;
using AbstractLawFirmDatabaseImplement.Implements;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Logging;
using NLog.Extensions.Logging;