исправление ошибок

This commit is contained in:
анна 2024-04-29 20:07:03 +04:00
parent 13ec04b0ee
commit a67f3562c3
38 changed files with 202 additions and 79 deletions

View File

@ -10,6 +10,7 @@ using UniversityContracts.BindingModels;
using UniversityContracts.SearchModels; using UniversityContracts.SearchModels;
using UniversityContracts.StoragesContracts; using UniversityContracts.StoragesContracts;
using UniversityContracts.ViewModels; using UniversityContracts.ViewModels;
using Microsoft.Extensions.Logging;
namespace UniversityBusinessLogics.BusinessLogic namespace UniversityBusinessLogics.BusinessLogic
{ {

View File

@ -4,6 +4,7 @@ using UniversityContracts.SearchModels;
using UniversityContracts.StoragesContracts; using UniversityContracts.StoragesContracts;
using UniversityContracts.ViewModels; using UniversityContracts.ViewModels;
using System.Text.RegularExpressions; using System.Text.RegularExpressions;
using Microsoft.Extensions.Logging;
namespace UniversityBusinessLogics.BusinessLogic namespace UniversityBusinessLogics.BusinessLogic
{ {

View File

@ -4,9 +4,11 @@ using System.Linq;
using System.Text; using System.Text;
using System.Threading.Tasks; using System.Threading.Tasks;
using UniversityContracts.BindingModels; using UniversityContracts.BindingModels;
using UniversityContracts.BusinessLogicContracts;
using UniversityContracts.SearchModels; using UniversityContracts.SearchModels;
using UniversityContracts.StoragesContracts; using UniversityContracts.StoragesContracts;
using UniversityContracts.ViewModels; using UniversityContracts.ViewModels;
using Microsoft.Extensions.Logging;
namespace UniversityBusinessLogics.BusinessLogic namespace UniversityBusinessLogics.BusinessLogic
{ {

View File

@ -7,6 +7,9 @@ using UniversityContracts.BindingModels;
using UniversityContracts.BusinessLogicContracts; using UniversityContracts.BusinessLogicContracts;
using UniversityContracts.SearchModels; using UniversityContracts.SearchModels;
using UniversityContracts.StoragesContracts; using UniversityContracts.StoragesContracts;
using UniversityContracts.ViewModels;
using Microsoft.Extensions.Logging;
using System.Text.RegularExpressions;
namespace UniversityBusinessLogics.BusinessLogic namespace UniversityBusinessLogics.BusinessLogic
{ {
@ -50,15 +53,7 @@ namespace UniversityBusinessLogics.BusinessLogic
"Пароль пользователя должен содержать хотя бы одну цифру"); "Пароль пользователя должен содержать хотя бы одну цифру");
} }
_logger.LogDebug("{level} Проверка логина пользователя на уникальность {@Employee}", model); _logger.LogDebug("{level} Проверка логина пользователя на уникальность {@Employee}", model);
var element = _employeeStorage.GetElement(new EmployeeSearchModel
{
PhoneNumber = model.PhoneNumber,
});
if (element != null && element.Id != model.Id)
{
_logger.LogWarning("С номером {PhoneNumber}, уже есть пользователь: {@ExistEmployee}", model.PhoneNumber, element);
throw new InvalidOperationException($"Сотрудник с таким номером телефона уже есть");
}
} }
public bool Create(EmployeeBindingModel model) public bool Create(EmployeeBindingModel model)

View File

@ -1,10 +1,14 @@
using System; using BankContracts.ViewModels;
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 UniversityContracts.BindingModels;
using UniversityContracts.BusinessLogicContracts; using UniversityContracts.BusinessLogicContracts;
using UniversityContracts.SearchModels;
using UniversityContracts.StoragesContracts; using UniversityContracts.StoragesContracts;
using Microsoft.Extensions.Logging;
namespace UniversityBusinessLogics.BusinessLogic namespace UniversityBusinessLogics.BusinessLogic
{ {
@ -97,13 +101,13 @@ namespace UniversityBusinessLogics.BusinessLogic
var payments = ReadList(model); // Вызываем метод из бизнес логики, чтобы залогировать доп информацию var payments = ReadList(model); // Вызываем метод из бизнес логики, чтобы залогировать доп информацию
if (payments == null || payments.Count == 0) if (payments == null || payments.Count == 0)
{ {
fullPrice = _carStorage.GetElement(new() { Id = model.OperationId })?.Price ?? throw new InvalidOperationException("Не получена операция для оплаты"); ; fullPrice = _carStorage.GetElement(new() { Id = model.ClassId })?.Price ?? throw new InvalidOperationException("Не получена операция для оплаты"); ;
paidPrice = 0; paidPrice = 0;
return true; return true;
} }
fullPrice = payments[0].FullPrice; fullPrice = payments[0].FullPrice;
paidPrice = payments.Sum(x => x.PaidPrice); paidPrice = payments.Sum(x => x.PaidPrice);
_logger.LogInformation("По покупке({Id}) и операцийе({Id}) получена полная стоимостиь {fullPrice} и оплаченная стоимость {paidPrice}", model.PurchaseId, model.OperationId, fullPrice, paidPrice); _logger.LogInformation("По покупке({Id}) и операцийе({Id}) получена полная стоимостиь {fullPrice} и оплаченная стоимость {paidPrice}", model.PurchaseId, model.ClassId, fullPrice, paidPrice);
return true; return true;
} }
catch (Exception e) catch (Exception e)

View File

@ -8,6 +8,7 @@ using UniversityContracts.BusinessLogicContracts;
using UniversityContracts.SearchModels; using UniversityContracts.SearchModels;
using UniversityContracts.StoragesContracts; using UniversityContracts.StoragesContracts;
using UniversityContracts.ViewModels; using UniversityContracts.ViewModels;
using Microsoft.Extensions.Logging;
namespace UniversityBusinessLogics.BusinessLogic namespace UniversityBusinessLogics.BusinessLogic
{ {

View File

@ -12,7 +12,19 @@
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<PackageReference Include="Microsoft.EntityFrameworkCore" Version="6.0.0" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Design" Version="6.0.0">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
<PackageReference Include="Microsoft.EntityFrameworkCore.Tools" Version="6.0.0">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
<PackageReference Include="Microsoft.Extensions.DependencyInjection" Version="6.0.0" />
<PackageReference Include="Microsoft.Extensions.Logging" Version="6.0.0" />
<PackageReference Include="Microsoft.Extensions.Logging.Abstractions" Version="6.0.0" /> <PackageReference Include="Microsoft.Extensions.Logging.Abstractions" Version="6.0.0" />
<PackageReference Include="System.Text.Json" Version="6.0.0" />
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>

View File

@ -1,9 +1,12 @@
using UniversityBusinessLogics.BusinessLogic; using UniversityBusinessLogics.BusinessLogic;
using UniversityContracts.BusinessLogicContracts; using UniversityContracts.BusinessLogicContracts;
using UniversityContracts.StoragesContracts; using UniversityContracts.StoragesContracts;
using UniversityDatabaseImplement.Implements;
using Serilog; using Serilog;
using UniversityDatabaseImplement.Implements;
using UiversityDatabaseImplement.Implements;
var builder = WebApplication.CreateBuilder(args); var builder = WebApplication.CreateBuilder(args);
builder.Services.AddControllersWithViews(); builder.Services.AddControllersWithViews();

View File

@ -7,12 +7,26 @@
</PropertyGroup> </PropertyGroup>
<ItemGroup> <ItemGroup>
<PackageReference Include="Microsoft.EntityFrameworkCore" Version="6.0.0" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Design" Version="6.0.0">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
<PackageReference Include="Microsoft.EntityFrameworkCore.Tools" Version="6.0.0">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
<PackageReference Include="Microsoft.Extensions.DependencyInjection" Version="6.0.0" />
<PackageReference Include="Microsoft.Extensions.Logging" Version="6.0.0" />
<PackageReference Include="Newtonsoft.Json" Version="13.0.3" />
<PackageReference Include="Serilog" Version="3.1.1" /> <PackageReference Include="Serilog" Version="3.1.1" />
<PackageReference Include="System.Text.Json" Version="6.0.0" />
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<ProjectReference Include="..\UniversityBusinessLogics\UniversityBusinessLogics.csproj" /> <ProjectReference Include="..\UniversityBusinessLogics\UniversityBusinessLogics.csproj" />
<ProjectReference Include="..\UniversityContracts\UniversityContracts.csproj" /> <ProjectReference Include="..\UniversityContracts\UniversityContracts.csproj" />
<ProjectReference Include="..\UniversityDatabaseImplement\UniversityDatabaseImplement.csproj" />
</ItemGroup> </ItemGroup>
</Project> </Project>

View File

@ -3,6 +3,7 @@ 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 UniversityDataModels.Models;
namespace UniversityContracts.BindingModels namespace UniversityContracts.BindingModels
{ {

View File

@ -6,7 +6,7 @@ using System.Threading.Tasks;
namespace UniversityContracts.BindingModels namespace UniversityContracts.BindingModels
{ {
internal class PaymentBindingModel public class PaymentBindingModel
{ {
public DateOnly Date { get; set; } = DateOnly.FromDateTime(DateTime.Now); public DateOnly Date { get; set; } = DateOnly.FromDateTime(DateTime.Now);

View File

@ -1,5 +1,6 @@
using UniversityDataModels; using UniversityDataModels;
using UniversityDataModels.HelperInterfaces; using UniversityDataModels.HelperInterfaces;
using UniversityDataModels.Models;
namespace UniversityContracts.BindingModels namespace UniversityContracts.BindingModels
{ {

View File

@ -4,8 +4,8 @@
{ {
public int? Id { get; set; } public int? Id { get; set; }
public int? EmployeeId { get; set; } public int? EmployeeId { get; set; }
public string Model { get; set; } = string.Empty; public string Name { get; set; } = string.Empty;
public string Mark { get; set; } = string.Empty; public string Time { get; set; } = string.Empty;
public int Price { get; set; } public int Price { get; set; }
public List<int>? PurchasesIds { get; set; } public List<int>? PurchasesIds { get; set; }
} }

View File

@ -9,7 +9,7 @@ namespace UniversityContracts.SearchModels
public class PaymentSearchModel public class PaymentSearchModel
{ {
public int? Id { get; set; } public int? Id { get; set; }
public int? OperationId { get; set; } public int? ClassId { get; set; }
public int? PurchaseId { get; set; } public int? PurchaseId { get; set; }
public DateOnly? DateFrom { get; set; } public DateOnly? DateFrom { get; set; }

View File

@ -7,6 +7,6 @@
public DateOnly? DateFrom { get; set; } public DateOnly? DateFrom { get; set; }
public int? ClientId { get; set; } public int? ClientId { get; set; }
public List<int>? OperationsIds { get; set; } public List<int>? ClassesIds { get; set; }
} }
} }

View File

@ -1,4 +1,5 @@
using UniversityContracts.BindingModels; using BankContracts.ViewModels;
using UniversityContracts.BindingModels;
using UniversityContracts.SearchModels; using UniversityContracts.SearchModels;
using UniversityContracts.ViewModels; using UniversityContracts.ViewModels;

View File

@ -1,4 +1,5 @@
using UniversityContracts.BindingModels; using BankContracts.ViewModels;
using UniversityContracts.BindingModels;
using UniversityContracts.SearchModels; using UniversityContracts.SearchModels;
using UniversityContracts.ViewModels; using UniversityContracts.ViewModels;

View File

@ -6,6 +6,21 @@
<Nullable>enable</Nullable> <Nullable>enable</Nullable>
</PropertyGroup> </PropertyGroup>
<ItemGroup>
<PackageReference Include="Microsoft.EntityFrameworkCore" Version="6.0.0" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Design" Version="6.0.0">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
<PackageReference Include="Microsoft.EntityFrameworkCore.Tools" Version="6.0.0">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
<PackageReference Include="Microsoft.Extensions.DependencyInjection" Version="6.0.0" />
<PackageReference Include="Microsoft.Extensions.Logging" Version="6.0.0" />
<PackageReference Include="System.Text.Json" Version="6.0.0" />
</ItemGroup>
<ItemGroup> <ItemGroup>
<ProjectReference Include="..\UniversityDataModels\UniversityDataModels.csproj" /> <ProjectReference Include="..\UniversityDataModels\UniversityDataModels.csproj" />
</ItemGroup> </ItemGroup>

View File

@ -8,7 +8,7 @@ using UniversityDataModels;
namespace UniversityContracts.ViewModels namespace UniversityContracts.ViewModels
{ {
internal class EmployeeViewModel : IEmployeeModel public class EmployeeViewModel : IEmployeeModel
{ {
public int Id { get; set; } public int Id { get; set; }

View File

@ -6,6 +6,7 @@ using System.Linq;
using System.Text; using System.Text;
using System.Threading.Tasks; using System.Threading.Tasks;
using UniversityContracts.ViewModels; using UniversityContracts.ViewModels;
using UniversityDataModels.Models;
namespace BankContracts.ViewModels namespace BankContracts.ViewModels
{ {

View File

@ -30,7 +30,7 @@ namespace UniversityContracts.ViewModels
{ {
break; break;
} }
result.Append($"\n\t{i + 1}. {car.Mark} {car.Model} стоимостью {car.Price}"); result.Append($"\n\t{i + 1}. {car.Time} {car.Name} стоимостью {car.Price}");
} }
return result.ToString(); return result.ToString();
} }

View File

@ -1,4 +1,4 @@
<Project Sdk="Microsoft.NET.Sdk"> <Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup> <PropertyGroup>
<TargetFramework>net6.0</TargetFramework> <TargetFramework>net6.0</TargetFramework>
@ -6,4 +6,19 @@
<Nullable>enable</Nullable> <Nullable>enable</Nullable>
</PropertyGroup> </PropertyGroup>
<ItemGroup>
<PackageReference Include="Microsoft.EntityFrameworkCore" Version="6.0.0" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Design" Version="6.0.0">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
<PackageReference Include="Microsoft.EntityFrameworkCore.Tools" Version="6.0.0">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
<PackageReference Include="Microsoft.Extensions.DependencyInjection" Version="6.0.0" />
<PackageReference Include="Microsoft.Extensions.Logging" Version="6.0.0" />
<PackageReference Include="System.Text.Json" Version="6.0.0" />
</ItemGroup>
</Project> </Project>

View File

@ -20,10 +20,10 @@ namespace UniversityDatabaseImplement.Implements
public ClassViewModel? Delete(ClassBindingModel model) public ClassViewModel? Delete(ClassBindingModel model)
{ {
using var context = new UniversityDB(); using var context = new UniversityDB();
var element = context.Operations.FirstOrDefault(x => x.Id == model.Id); var element = context.Classes.FirstOrDefault(x => x.Id == model.Id);
if (element != null) if (element != null)
{ {
context.Operations.Remove(element); context.Classes.Remove(element);
context.SaveChanges(); context.SaveChanges();
return element.GetViewModel; return element.GetViewModel;
} }
@ -38,7 +38,7 @@ namespace UniversityDatabaseImplement.Implements
return null; return null;
} }
using var context = new UniversityDB(); using var context = new UniversityDB();
return context.Operations return context.Classes
.Include(x => x.Employee) .Include(x => x.Employee)
.FirstOrDefault(x => model.Id.HasValue && x.Id == model.Id)?.GetViewModel; .FirstOrDefault(x => model.Id.HasValue && x.Id == model.Id)?.GetViewModel;
} }
@ -53,7 +53,7 @@ namespace UniversityDatabaseImplement.Implements
} }
using var context = new UniversityDB(); using var context = new UniversityDB();
var query = context.Operations.Include(x => x.Employee); var query = context.Classes.Include(x => x.Employee);
if (model.EmployeeId.HasValue) if (model.EmployeeId.HasValue)
{ {
@ -77,7 +77,7 @@ namespace UniversityDatabaseImplement.Implements
public List<ClassViewModel> GetFullList() public List<ClassViewModel> GetFullList()
{ {
using var context = new UniversityDB(); using var context = new UniversityDB();
return context.Operations.Include(x => x.Employee) return context.Classes.Include(x => x.Employee)
.Select(x => x.GetViewModel) .Select(x => x.GetViewModel)
.ToList(); .ToList();
} }
@ -90,7 +90,7 @@ namespace UniversityDatabaseImplement.Implements
return null; return null;
} }
using var context = new UniversityDB(); using var context = new UniversityDB();
context.Operations.Add(newOperation); context.Classes.Add(newOperation);
context.SaveChanges(); context.SaveChanges();
return newOperation.GetViewModel; return newOperation.GetViewModel;
} }
@ -98,7 +98,7 @@ namespace UniversityDatabaseImplement.Implements
public ClassViewModel? Update(ClassBindingModel model) public ClassViewModel? Update(ClassBindingModel model)
{ {
using var context = new UniversityDB(); using var context = new UniversityDB();
var car = context.Operations.FirstOrDefault(x => x.Id == model.Id); var car = context.Classes.FirstOrDefault(x => x.Id == model.Id);
if (car == null) if (car == null)
{ {
return null; return null;

View File

@ -23,7 +23,7 @@ namespace UiversityDatabaseImplement.Implements
CheckSearchModel(model); CheckSearchModel(model);
using var context = new UniversityDB(); using var context = new UniversityDB();
return context.Clients.FirstOrDefault(x => x.PhoneNumber.Equals(model.PhoneNumber) && (string.IsNullOrEmpty(model.Password) || x.Password.Equals(model.Password)))?.GetViewModel; return context.Clients.FirstOrDefault(x => (string.IsNullOrEmpty(model.Password) || x.Password.Equals(model.Password)))?.GetViewModel;
} }
public ClassViewModel? Insert(ClientBindingModel model) public ClassViewModel? Insert(ClientBindingModel model)
{ {

View File

@ -18,7 +18,7 @@ namespace UniversityDatabaseImplement.Implements
} }
public CostViewModel? Delete(CostBindingModel model) public CostViewModel? Delete(CostBindingModel model)
{ {
using var context = new BankDB(); using var context = new UniversityDB();
var element = context.Costs.FirstOrDefault(x => x.Id == model.Id); var element = context.Costs.FirstOrDefault(x => x.Id == model.Id);
if (element != null) if (element != null)
{ {
@ -32,7 +32,7 @@ namespace UniversityDatabaseImplement.Implements
public CostViewModel? GetElement(CostSearchModel model) public CostViewModel? GetElement(CostSearchModel model)
{ {
CheckSearchModel(model); CheckSearchModel(model);
using var context = new BankDB(); using var context = new UniversityDB();
if (!model.Id.HasValue) if (!model.Id.HasValue)
{ {
return null; return null;

View File

@ -23,7 +23,7 @@ namespace UniversityDatabaseImplement.Implements
using var context = new UniversityDB(); using var context = new UniversityDB();
return context.Employees return context.Employees
.FirstOrDefault(x => x.PhoneNumber.Equals(model.PhoneNumber) && (string.IsNullOrEmpty(model.Password) || x.Password.Equals(model.Password)))?.GetViewModel; .FirstOrDefault(x => (string.IsNullOrEmpty(model.Password) || x.Password.Equals(model.Password)))?.GetViewModel;
} }
public EmployeeViewModel? Insert(EmployeeBindingModel model) public EmployeeViewModel? Insert(EmployeeBindingModel model)
{ {

View File

@ -5,13 +5,14 @@ using UniversityContracts.ViewModels;
using UniversityDatabaseImplement.Models; using UniversityDatabaseImplement.Models;
using Microsoft.EntityFrameworkCore; using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Query; using Microsoft.EntityFrameworkCore.Query;
using BankContracts.ViewModels;
namespace UniversityDatabaseImplement.Implements namespace UniversityDatabaseImplement.Implements
{ {
public class PaymentStorage : IPaymentStorage public class PaymentStorage : IPaymentStorage
{ {
private static IIncludableQueryable<Payment, Class?> Payments(UniversityDB context) private static IIncludableQueryable<Payment, Class?> Payments(UniversityDB context)
=> context.Payments.Include(x => x.OperationByPurchase).ThenInclude(x => x.Operation); => context.Payments.Include(x => x.ClassByPurchase).ThenInclude(x => x.Class);
public List<PaymentViewModel> GetFullList() public List<PaymentViewModel> GetFullList()
{ {
@ -31,9 +32,9 @@ namespace UniversityDatabaseImplement.Implements
{ {
throw new ArgumentException("Получена поисковая модель только с началом или концом периода"); throw new ArgumentException("Получена поисковая модель только с началом или концом периода");
} }
if (!model.DateFrom.HasValue && !model.OperationId.HasValue) if (!model.DateFrom.HasValue && !model.ClassId.HasValue)
{ {
throw new ArgumentNullException(nameof(model.OperationId), "Получена поисковая модель без OperationId"); throw new ArgumentNullException(nameof(model.ClassId), "Получена поисковая модель без OperationId");
} }
if (!model.DateFrom.HasValue && !model.PurchaseId.HasValue) if (!model.DateFrom.HasValue && !model.PurchaseId.HasValue)
@ -48,9 +49,9 @@ namespace UniversityDatabaseImplement.Implements
.ToList(); .ToList();
return Payments(context) return Payments(context)
.Where(x => x.OperationByPurchase != null && .Where(x => x.ClassByPurchase != null &&
x.OperationByPurchase.OperationId == model.OperationId && x.ClassByPurchase.ClassId == model.ClassId &&
x.OperationByPurchase.PurchaseId == model.PurchaseId) x.ClassByPurchase.PurchaseId == model.PurchaseId)
.Select(x => x.GetViewModel) .Select(x => x.GetViewModel)
.ToList(); .ToList();
} }

View File

@ -5,6 +5,7 @@ using UniversityContracts.StoragesContracts;
using UniversityContracts.ViewModels; using UniversityContracts.ViewModels;
using UniversityDatabaseImplement.Models; using UniversityDatabaseImplement.Models;
using Microsoft.EntityFrameworkCore; using Microsoft.EntityFrameworkCore;
using BankContracts.ViewModels;
namespace UniversityDatabaseImplement.Implements namespace UniversityDatabaseImplement.Implements
{ {
@ -14,7 +15,7 @@ namespace UniversityDatabaseImplement.Implements
{ {
if (model == null) if (model == null)
throw new ArgumentNullException("Передаваемая модель для поиска равна нулю", nameof(model)); throw new ArgumentNullException("Передаваемая модель для поиска равна нулю", nameof(model));
if (!model.Id.HasValue && !model.ClientId.HasValue && !model.DateFrom.HasValue && !model.DateTo.HasValue && model.OperationsIds == null) if (!model.Id.HasValue && !model.ClientId.HasValue && !model.DateFrom.HasValue && !model.DateTo.HasValue && model.ClassesIds == null)
throw new ArgumentException("Все передаваемые поля поисковой модели оказались пусты или равны null"); throw new ArgumentException("Все передаваемые поля поисковой модели оказались пусты или равны null");
if (model.DateFrom.HasValue != model.DateTo.HasValue) if (model.DateFrom.HasValue != model.DateTo.HasValue)
throw new ArgumentException($"Не указано начало {model.DateFrom} или конец {model.DateTo} периода для поиска по дате."); throw new ArgumentException($"Не указано начало {model.DateFrom} или конец {model.DateTo} периода для поиска по дате.");
@ -44,9 +45,9 @@ namespace UniversityDatabaseImplement.Implements
throw new ArgumentNullException(nameof(modelOperation), "Получена поисковая модель без Id"); throw new ArgumentNullException(nameof(modelOperation), "Получена поисковая модель без Id");
} }
using var context = new UniversityDB(); using var context = new UniversityDB();
var carByPurchase = context.OperationByPurchases var carByPurchase = context.ClassByPurchases
.Include(x => x.Payments) .Include(x => x.Payments)
.FirstOrDefault(x => x.OperationId == modelOperation.Id && x.PurchaseId == modelPurchase.Id); .FirstOrDefault(x => x.ClassId == modelOperation.Id && x.PurchaseId == modelPurchase.Id);
if (carByPurchase?.Payments == null) if (carByPurchase?.Payments == null)
{ {
throw new InvalidOperationException( throw new InvalidOperationException(
@ -93,16 +94,16 @@ namespace UniversityDatabaseImplement.Implements
if (model.DateTo.HasValue) if (model.DateTo.HasValue)
resultQuery = query resultQuery = query
.Include(x => x.Operations) .Include(x => x.Operations)
.ThenInclude(x => x.Operation) .ThenInclude(x => x.Class)
.Include(x => x.Costs)! .Include(x => x.Costs)!
.ThenInclude(x => x.Cost) .ThenInclude(x => x.Cost)
.Where(x => model.DateFrom <= x.DatePurchase && x.DatePurchase <= model.DateTo); .Where(x => model.DateFrom <= x.DatePurchase && x.DatePurchase <= model.DateTo);
else if (model.OperationsIds != null) else if (model.ClassesIds != null)
resultQuery = query resultQuery = query
.Where(x => x.Operations.Any(x => model.OperationsIds.Contains(x.OperationId))) .Where(x => x.Operations.Any(x => model.ClassesIds.Contains(x.ClassId)))
.Include(x => x.Operations) .Include(x => x.Operations)
.ThenInclude(x => x.Operation); .ThenInclude(x => x.Class);
return resultQuery? return resultQuery?
.Select(x => x.GetViewModel) .Select(x => x.GetViewModel)

View File

@ -1,5 +1,6 @@
using System.ComponentModel.DataAnnotations; using System.ComponentModel.DataAnnotations;
using UniversityDataModels.ProxyModels; using UniversityDataModels.Models;
namespace UniversityDatabaseImplement.Models namespace UniversityDatabaseImplement.Models
{ {

View File

@ -3,7 +3,6 @@ using UniversityContracts.SearchModels;
using UniversityContracts.ViewModels; using UniversityContracts.ViewModels;
using UniversityDatabaseImplement.Implements; using UniversityDatabaseImplement.Implements;
using UniversityDataModels; using UniversityDataModels;
using UniversityDataModels.ProxyModels;
using System.ComponentModel; using System.ComponentModel;
using System.ComponentModel.DataAnnotations; using System.ComponentModel.DataAnnotations;
@ -14,11 +13,11 @@ namespace UniversityDatabaseImplement.Models
[Required] [Required]
public int EmployeeId { get; private set; } public int EmployeeId { get; private set; }
[Required] [Required]
public string Model { get; private set; } = string.Empty; public string Name { get; private set; } = string.Empty;
[Required] [Required]
public double Price { get; private set; } public double Price { get; private set; }
[Required] [Required]
public string Mark { get; private set; } = string.Empty; public string Time { get; private set; } = string.Empty;
public int Id { get; private set; } public int Id { get; private set; }
[Required] [Required]
@ -36,9 +35,9 @@ namespace UniversityDatabaseImplement.Models
return new Class() return new Class()
{ {
EmployeeId = model.EmployeeId, EmployeeId = model.EmployeeId,
Model = model.Model, Name = model.Name,
Price = model.Price, Price = model.Price,
Mark = model.Mark, Time = model.Time,
Id = model.Id, Id = model.Id,
}; };
} }
@ -47,9 +46,9 @@ namespace UniversityDatabaseImplement.Models
{ {
EmployeePhoneNumber = Employee?.PhoneNumber??string.Empty, EmployeePhoneNumber = Employee?.PhoneNumber??string.Empty,
EmployeeId = EmployeeId, EmployeeId = EmployeeId,
Model = Model, Name = Name,
Price = Price, Price = Price,
Mark = Mark, Time = Time,
Id = Id, Id = Id,
Purchases = Purchases.Select(x=>x.Purchase?.GetViewModel2).ToList(), Purchases = Purchases.Select(x=>x.Purchase?.GetViewModel2).ToList(),
}; };

View File

@ -2,7 +2,8 @@
using UniversityContracts.ViewModels; using UniversityContracts.ViewModels;
using UniversityDataModels; using UniversityDataModels;
using System.ComponentModel.DataAnnotations; using System.ComponentModel.DataAnnotations;
using UniversityDataModels.ProxyModels; using UniversityDataModels.Models;
namespace UniversityDatabaseImplement.Models namespace UniversityDatabaseImplement.Models
{ {
@ -40,7 +41,6 @@ namespace UniversityDatabaseImplement.Models
public CostViewModel GetViewModel => new() public CostViewModel GetViewModel => new()
{ {
PhoneNumber = Employee?.PhoneNumber??string.Empty,
PurchaseModels = PurchasesModels, PurchaseModels = PurchasesModels,
EmployeeId = EmployeeId, EmployeeId = EmployeeId,
NameOfCost = NameOfCost, NameOfCost = NameOfCost,

View File

@ -1,5 +1,6 @@
using System.ComponentModel.DataAnnotations; using System.ComponentModel.DataAnnotations;
using UniversityDataModels.ProxyModels; using UniversityDataModels.Models;
namespace UniversityDatabaseImplement.Models namespace UniversityDatabaseImplement.Models
{ {

View File

@ -37,11 +37,9 @@ namespace UniversityDatabaseImplement.Models
FirstName = model.FirstName, FirstName = model.FirstName,
LastName = model.LastName, LastName = model.LastName,
MiddleName = model.MiddleName, MiddleName = model.MiddleName,
PhoneNumber = model.PhoneNumber,
Password = model.Password, Password = model.Password,
Id = model.Id, Id = model.Id,
Post = model.Post, Post = model.Post,
Email = model.Email,
}; };
} }
@ -50,11 +48,9 @@ namespace UniversityDatabaseImplement.Models
FirstName = FirstName, FirstName = FirstName,
LastName = LastName, LastName = LastName,
MiddleName = MiddleName, MiddleName = MiddleName,
PhoneNumber = PhoneNumber,
Password = Password, Password = Password,
Id = Id, Id = Id,
Post = Post, Post = Post,
Email = Email,
}; };
} }
} }

View File

@ -3,13 +3,14 @@ using UniversityContracts.ViewModels;
using UniversityDataModels; using UniversityDataModels;
using System.ComponentModel.DataAnnotations; using System.ComponentModel.DataAnnotations;
using System.Diagnostics; using System.Diagnostics;
using BankContracts.ViewModels;
namespace UniversityDatabaseImplement.Models namespace UniversityDatabaseImplement.Models
{ {
public class Payment : IPaymentModel public class Payment : IPaymentModel
{ {
[Required] [Required]
public int OperationByPurchaseId { get; private set; } public int ClassByPurchaseId { get; private set; }
[Required] [Required]
public DateOnly Date { get; private set; } public DateOnly Date { get; private set; }
@ -34,18 +35,18 @@ namespace UniversityDatabaseImplement.Models
Date = model.Date, Date = model.Date,
PaidPrice = model.PaidPrice, PaidPrice = model.PaidPrice,
Id = model.Id, Id = model.Id,
OperationByPurchaseId = model.OperationByPurchaseId, ClassByPurchaseId = model.ClassByPurchaseId,
}; };
} }
public PaymentViewModel GetViewModel => new() public PaymentViewModel GetViewModel => new()
{ {
Operation = OperationByPurchase?.Operation?.GetViewModel, Operation = ClassByPurchase?.Class?.GetViewModel,
OperationByPurchase = OperationByPurchase, ClassByPurchase = ClassByPurchase,
FullPrice = OperationByPurchase?.Operation?.Price ?? -1, FullPrice = ClassByPurchase?.Class?.Price ?? -1,
Date = Date, Date = Date,
PaidPrice = PaidPrice, PaidPrice = PaidPrice,
Id = Id, Id = Id,
OperationByPurchaseId = OperationByPurchaseId, ClassByPurchaseId = ClassByPurchaseId,
}; };
} }
} }

View File

@ -4,7 +4,8 @@ using UniversityDataModels;
using System.ComponentModel.DataAnnotations; using System.ComponentModel.DataAnnotations;
using System.ComponentModel.DataAnnotations.Schema; using System.ComponentModel.DataAnnotations.Schema;
using System.Linq.Expressions; using System.Linq.Expressions;
using UniversityDataModels.ProxyModels; using UniversityDataModels.Models;
namespace UniversityDatabaseImplement.Models namespace UniversityDatabaseImplement.Models
{ {
@ -14,7 +15,7 @@ namespace UniversityDatabaseImplement.Models
public DateOnly DatePurchase { get; private set; } public DateOnly DatePurchase { get; private set; }
private Dictionary<int, ClassByPurchaseModel>? _cachedOperations; private Dictionary<int, ClassByPurchaseModel>? _cachedOperations;
[NotMapped] [NotMapped]
public Dictionary<int, ClassByPurchaseModel> ClassModel => _cachedOperations ??= Class.Select(x => (ClassByPurchaseModel)x).ToDictionary(x => x.ClassId, x => x); public Dictionary<int, ClassByPurchaseModel> ClassModel => _cachedOperations ??= Class.Select (x => (ClassByPurchaseModel)x).ToDictionary(x => x.ClassId, x => x);
[NotMapped] [NotMapped]
public List<CostByPurchaseModel>? CostsModel => null; public List<CostByPurchaseModel>? CostsModel => null;
public int Id { get; private set; } public int Id { get; private set; }
@ -42,7 +43,7 @@ namespace UniversityDatabaseImplement.Models
public PurchaseViewModel GetViewModel => new() public PurchaseViewModel GetViewModel => new()
{ {
OperationsModel = OperationsModel, ClassModel = ClassModel,
Id = Id, Id = Id,
DatePurchase = DatePurchase, DatePurchase = DatePurchase,
ClientId = ClientId, ClientId = ClientId,
@ -52,13 +53,13 @@ namespace UniversityDatabaseImplement.Models
.Select(x => x.Cost.GetViewModel) .Select(x => x.Cost.GetViewModel)
.ToList() ?? new(), .ToList() ?? new(),
OperationViewModels = Operations? OperationViewModels = Operations?
.Select(x => x.Operation?.GetViewModel) .Select(x => x.Class?.GetViewModel)
.ToList() ?? new() .ToList() ?? new()
}; };
public PurchaseViewModel GetViewModel2 => new() public PurchaseViewModel GetViewModel2 => new()
{ {
OperationsModel = OperationsModel, ClassModel = ClassModel,
Id = Id, Id = Id,
DatePurchase = DatePurchase, DatePurchase = DatePurchase,
ClientId = ClientId, ClientId = ClientId,
@ -71,14 +72,14 @@ namespace UniversityDatabaseImplement.Models
public void UpdateOperations(UniversityDB context, PurchaseBindingModel model) public void UpdateOperations(UniversityDB context, PurchaseBindingModel model)
{ {
var oldOperations = context.OperationByPurchases.Where(x => x.PurchaseId == model.Id).ToDictionary(x => x.OperationId, x => x); var oldOperations = context.ClassByPurchases.Where(x => x.PurchaseId == model.Id).ToDictionary(x => x.ClassId, x => x);
var newOperations = model.OperationsModel.ToDictionary( var newOperations = model.ClassModel.ToDictionary(
x => x.Key, x => x.Key,
x => new ClassnByPurchase() x => new ClassByPurchase()
{ {
OperationId = x.Key, ClassId = x.Key,
PurchaseId = Id, PurchaseId = Id,
CountOperations = x.Value.CountOperations CountClass = x.Value.CountClass
} }
); );
@ -87,7 +88,7 @@ namespace UniversityDatabaseImplement.Models
oldOperations oldOperations
.Where(x => newOperations.ContainsKey(x.Key)) .Where(x => newOperations.ContainsKey(x.Key))
.Select(x => x.Value).ToList() .Select(x => x.Value).ToList()
.ForEach(x => x.CountOperations = newOperations[x.OperationId].CountOperations); .ForEach(x => x.CountClass = newOperations[x.ClassId].CountClass);
context.SaveChanges(); context.SaveChanges();
_cachedOperations = null; _cachedOperations = null;
} }

View File

@ -6,4 +6,24 @@
<Nullable>enable</Nullable> <Nullable>enable</Nullable>
</PropertyGroup> </PropertyGroup>
<ItemGroup>
<PackageReference Include="Microsoft.EntityFrameworkCore" Version="6.0.0" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Design" Version="6.0.0">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
<PackageReference Include="Microsoft.EntityFrameworkCore.Tools" Version="6.0.0">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
<PackageReference Include="Microsoft.Extensions.DependencyInjection" Version="6.0.0" />
<PackageReference Include="Microsoft.Extensions.Logging" Version="6.0.0" />
<PackageReference Include="Npgsql.EntityFrameworkCore.PostgreSQL" Version="6.0.0" />
<PackageReference Include="System.Text.Json" Version="6.0.0" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\UniversityContracts\UniversityContracts.csproj" />
</ItemGroup>
</Project> </Project>

View File

@ -1,6 +1,8 @@
using Serilog;
using UniversityBusinessLogics.BusinessLogic; using UniversityBusinessLogics.BusinessLogic;
using UniversityContracts.BusinessLogicContracts; using UniversityContracts.BusinessLogicContracts;
using UniversityContracts.StoragesContracts; using UniversityContracts.StoragesContracts;
using UniversityDatabaseImplement.Implements;
var builder = WebApplication.CreateBuilder(args); var builder = WebApplication.CreateBuilder(args);
@ -21,6 +23,20 @@ builder.Services.AddTransient<ICostStorage, CostStorage>();
builder.Services.AddTransient<IPurchaseStorage, PurchaseStorage>(); builder.Services.AddTransient<IPurchaseStorage, PurchaseStorage>();
builder.Services.AddTransient<IPaymentStorage, PaymentStorage>(); builder.Services.AddTransient<IPaymentStorage, PaymentStorage>();
builder.Services.AddLogging(option =>
{
var configuration = new ConfigurationBuilder()
.SetBasePath(Directory.GetCurrentDirectory())
.AddJsonFile(path: "appsettings.json", optional: false, reloadOnChange: true)
.Build();
var logger = new LoggerConfiguration()
.ReadFrom.Configuration(configuration)
.CreateLogger();
option.AddSerilog(logger);
});
var app = builder.Build(); var app = builder.Build();
// Configure the HTTP request pipeline. // Configure the HTTP request pipeline.

View File

@ -6,9 +6,27 @@
<ImplicitUsings>enable</ImplicitUsings> <ImplicitUsings>enable</ImplicitUsings>
</PropertyGroup> </PropertyGroup>
<ItemGroup>
<PackageReference Include="Microsoft.EntityFrameworkCore" Version="6.0.0" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Design" Version="6.0.0">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
<PackageReference Include="Microsoft.EntityFrameworkCore.Tools" Version="6.0.0">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
<PackageReference Include="Microsoft.Extensions.DependencyInjection" Version="6.0.0" />
<PackageReference Include="Microsoft.Extensions.Logging" Version="6.0.0" />
<PackageReference Include="Newtonsoft.Json.Bson" Version="1.0.2" />
<PackageReference Include="Serilog" Version="3.1.1" />
<PackageReference Include="System.Text.Json" Version="6.0.0" />
</ItemGroup>
<ItemGroup> <ItemGroup>
<ProjectReference Include="..\UniversityBusinessLogics\UniversityBusinessLogics.csproj" /> <ProjectReference Include="..\UniversityBusinessLogics\UniversityBusinessLogics.csproj" />
<ProjectReference Include="..\UniversityContracts\UniversityContracts.csproj" /> <ProjectReference Include="..\UniversityContracts\UniversityContracts.csproj" />
<ProjectReference Include="..\UniversityDatabaseImplement\UniversityDatabaseImplement.csproj" />
</ItemGroup> </ItemGroup>
</Project> </Project>