Спокойной ночи, малыши))

This commit is contained in:
Whoisthatjulia 2024-04-28 21:30:55 +04:00
parent a254af4259
commit 24f1159217
6 changed files with 48 additions and 10 deletions

View File

@ -6,4 +6,13 @@
<Nullable>enable</Nullable>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Microsoft.Extensions.Logging" Version="7.0.0" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\BankContracts\BankContracts.csproj" />
<ProjectReference Include="..\BankDataModels\BankDataModels.csproj" />
</ItemGroup>
</Project>

View File

@ -6,4 +6,15 @@
<Nullable>enable</Nullable>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Microsoft.EntityFrameworkCore.Design" Version="7.0.5">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\BankDataModels\BankDataModels.csproj" />
</ItemGroup>
</Project>

View File

@ -25,12 +25,12 @@ namespace BankContracts.ViewModels
$"Сделка, созданная {DatePurchase}, включает в себя операции:");
for (int i = 0; i < OperationViewModels.Count; i++)
{
var car = OperationViewModels[i];
if (car == null)
var operation = OperationViewModels[i];
if (operation == null)
{
break;
}
result.Append($"\n\t{i + 1}. {car.Mark} {car.Model} стоимостью {car.Price}");
result.Append($"\n\t{i + 1}. {operation.Mark} {operation.Model} стоимостью {operation.Price}");
}
return result.ToString();
}

View File

@ -6,4 +6,22 @@
<Nullable>enable</Nullable>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Microsoft.EntityFrameworkCore" Version="7.0.4" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Design" Version="7.0.4">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
<PackageReference Include="Microsoft.EntityFrameworkCore.Tools" Version="7.0.4">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
<PackageReference Include="Npgsql.EntityFrameworkCore.PostgreSQL" Version="7.0.3" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\BankContracts\BankContracts.csproj" />
<ProjectReference Include="..\BankDataModels\BankDataModels.csproj" />
</ItemGroup>
</Project>

View File

@ -98,14 +98,14 @@ namespace BankDatabaseImplement.Implements
public OperationViewModel? Update(OperationBindingModel model)
{
using var context = new BankDB();
var car = context.Operations.FirstOrDefault(x => x.Id == model.Id);
if (car == null)
var operation = context.Operations.FirstOrDefault(x => x.Id == model.Id);
if (operation == null)
{
return null;
}
car.Update(model);
operation.Update(model);
context.SaveChanges();
return car.GetViewModel;
return operation.GetViewModel;
}
}
}

View File

@ -44,15 +44,15 @@ namespace BankDatabaseImplement.Implements
throw new ArgumentNullException(nameof(modelOperation), "Получена поисковая модель без Id");
}
using var context = new BankDB();
var carByPurchase = context.OperationByPurchases
var operationByPurchase = context.OperationByPurchases
.Include(x => x.Payments)
.FirstOrDefault(x => x.OperationId == modelOperation.Id && x.PurchaseId == modelPurchase.Id);
if (carByPurchase?.Payments == null)
if (operationByPurchase?.Payments == null)
{
throw new InvalidOperationException(
$"Не существует связи между данной операции(Id={modelOperation.Id}) и покупкой(Id={modelPurchase.Id})");
}
return carByPurchase.Payments.Select(payment => payment.GetViewModel).ToList();
return operationByPurchase.Payments.Select(payment => payment.GetViewModel).ToList();
}
public PurchaseViewModel? GetElement(PurchaseSearchModel model)