финал

This commit is contained in:
GokaPek 2024-03-26 00:07:11 +04:00
parent c92e3a3ee5
commit 41531f9761
9 changed files with 223 additions and 73 deletions

View File

@ -14,7 +14,7 @@ namespace AbstractLawFirmDataBaseImplement
{ {
if (optionsBuilder.IsConfigured == false) 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); base.OnConfiguring(optionsBuilder);
} }

View File

@ -2,6 +2,8 @@
using AbstractLawFirmContracts.SearchModels; using AbstractLawFirmContracts.SearchModels;
using AbstractLawFirmContracts.StoragesContracts; using AbstractLawFirmContracts.StoragesContracts;
using AbstractLawFirmContracts.ViewModels; using AbstractLawFirmContracts.ViewModels;
using AbstractLawFirmDataBaseImplement;
using AbstractLawFirmDataBaseImplement.Models;
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Linq; using System.Linq;
@ -12,34 +14,71 @@ namespace AbstractLawFirmDatabaseImplement.Implements
{ {
public class ComponentStorage : IComponentStorage 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() public List<ComponentViewModel> GetFullList()
{ {
throw new NotImplementedException(); 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) public ComponentViewModel? Insert(ComponentBindingModel model)
{ {
throw new NotImplementedException(); 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) public ComponentViewModel? Update(ComponentBindingModel model)
{ {
throw new NotImplementedException(); 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.SearchModels;
using AbstractLawFirmContracts.StoragesContracts; using AbstractLawFirmContracts.StoragesContracts;
using AbstractLawFirmContracts.ViewModels; using AbstractLawFirmContracts.ViewModels;
using AbstractLawFirmDataBaseImplement;
using AbstractLawFirmDataBaseImplement.Models;
using Microsoft.EntityFrameworkCore;
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Linq; using System.Linq;
@ -13,34 +16,97 @@ namespace AbstractLawFirmDatabaseImplement.Implements
{ {
public class DocumentStorage : IDocumentStorage 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() public List<DocumentViewModel> GetFullList()
{ {
throw new NotImplementedException(); 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) public DocumentViewModel? Insert(DocumentBindingModel model)
{ {
throw new NotImplementedException(); 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) public DocumentViewModel? Update(DocumentBindingModel model)
{ {
throw new NotImplementedException(); 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.SearchModels;
using AbstractLawFirmContracts.ViewModels; using AbstractLawFirmContracts.ViewModels;
using AbstractLawFirmContracts.StoragesContracts; using AbstractLawFirmContracts.StoragesContracts;
using AbstractLawFirmDataBaseImplement.Models;
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Linq; using System.Linq;
using System.Text; using System.Text;
using System.Threading.Tasks; using System.Threading.Tasks;
using AbstractLawFirmDataBaseImplement;
using Microsoft.EntityFrameworkCore;
namespace AbstractLawFirmDatabaseImplement.Implements namespace AbstractLawFirmDatabaseImplement.Implements
{ {
@ -14,32 +17,74 @@ namespace AbstractLawFirmDatabaseImplement.Implements
{ {
public OrderViewModel? Delete(OrderBindingModel model) 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) 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) 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() 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) 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) 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 #pragma warning disable 612, 618
modelBuilder modelBuilder
.HasAnnotation("ProductVersion", "6.0.28") .HasAnnotation("DocumentVersion", "6.0.28")
.HasAnnotation("Relational:MaxIdentifierLength", 128); .HasAnnotation("Relational:MaxIdentifierLength", 128);
SqlServerModelBuilderExtensions.UseIdentityColumns(modelBuilder, 1L, 1); SqlServerModelBuilderExtensions.UseIdentityColumns(modelBuilder, 1L, 1);

View File

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

View File

@ -15,7 +15,7 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "AbstractLawFirmListImplemen
EndProject EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "AbstractLawFirmFileImplement", "AbstractLawFirmFileImpliment\AbstractLawFirmFileImplement.csproj", "{8AF960C2-208F-4B7B-9F8B-36B63446B6B7}" Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "AbstractLawFirmFileImplement", "AbstractLawFirmFileImpliment\AbstractLawFirmFileImplement.csproj", "{8AF960C2-208F-4B7B-9F8B-36B63446B6B7}"
EndProject 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 EndProject
Global Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution GlobalSection(SolutionConfigurationPlatforms) = preSolution

View File

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

View File

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