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

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.StoragesContracts;
using UniversityContracts.ViewModels;
using Microsoft.Extensions.Logging;
namespace UniversityBusinessLogics.BusinessLogic
{

View File

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

View File

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

View File

@ -7,6 +7,9 @@ using UniversityContracts.BindingModels;
using UniversityContracts.BusinessLogicContracts;
using UniversityContracts.SearchModels;
using UniversityContracts.StoragesContracts;
using UniversityContracts.ViewModels;
using Microsoft.Extensions.Logging;
using System.Text.RegularExpressions;
namespace UniversityBusinessLogics.BusinessLogic
{
@ -50,15 +53,7 @@ namespace UniversityBusinessLogics.BusinessLogic
"Пароль пользователя должен содержать хотя бы одну цифру");
}
_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)

View File

@ -1,10 +1,14 @@
using System;
using BankContracts.ViewModels;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using UniversityContracts.BindingModels;
using UniversityContracts.BusinessLogicContracts;
using UniversityContracts.SearchModels;
using UniversityContracts.StoragesContracts;
using Microsoft.Extensions.Logging;
namespace UniversityBusinessLogics.BusinessLogic
{
@ -97,13 +101,13 @@ namespace UniversityBusinessLogics.BusinessLogic
var payments = ReadList(model); // Вызываем метод из бизнес логики, чтобы залогировать доп информацию
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;
return true;
}
fullPrice = payments[0].FullPrice;
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;
}
catch (Exception e)

View File

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

View File

@ -12,7 +12,19 @@
</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="System.Text.Json" Version="6.0.0" />
</ItemGroup>
<ItemGroup>

View File

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

View File

@ -7,12 +7,26 @@
</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" Version="13.0.3" />
<PackageReference Include="Serilog" Version="3.1.1" />
<PackageReference Include="System.Text.Json" Version="6.0.0" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\UniversityBusinessLogics\UniversityBusinessLogics.csproj" />
<ProjectReference Include="..\UniversityContracts\UniversityContracts.csproj" />
<ProjectReference Include="..\UniversityDatabaseImplement\UniversityDatabaseImplement.csproj" />
</ItemGroup>
</Project>

View File

@ -3,6 +3,7 @@ using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using UniversityDataModels.Models;
namespace UniversityContracts.BindingModels
{

View File

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

View File

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

View File

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

View File

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

View File

@ -7,6 +7,6 @@
public DateOnly? DateFrom { 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.ViewModels;

View File

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

View File

@ -6,6 +6,21 @@
<Nullable>enable</Nullable>
</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>
<ProjectReference Include="..\UniversityDataModels\UniversityDataModels.csproj" />
</ItemGroup>

View File

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

View File

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

View File

@ -30,7 +30,7 @@ namespace UniversityContracts.ViewModels
{
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();
}

View File

@ -1,4 +1,4 @@
<Project Sdk="Microsoft.NET.Sdk">
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>net6.0</TargetFramework>
@ -6,4 +6,19 @@
<Nullable>enable</Nullable>
</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>

View File

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

View File

@ -23,7 +23,7 @@ namespace UiversityDatabaseImplement.Implements
CheckSearchModel(model);
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)
{

View File

@ -18,7 +18,7 @@ namespace UniversityDatabaseImplement.Implements
}
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);
if (element != null)
{
@ -32,7 +32,7 @@ namespace UniversityDatabaseImplement.Implements
public CostViewModel? GetElement(CostSearchModel model)
{
CheckSearchModel(model);
using var context = new BankDB();
using var context = new UniversityDB();
if (!model.Id.HasValue)
{
return null;

View File

@ -23,7 +23,7 @@ namespace UniversityDatabaseImplement.Implements
using var context = new UniversityDB();
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)
{

View File

@ -5,13 +5,14 @@ using UniversityContracts.ViewModels;
using UniversityDatabaseImplement.Models;
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Query;
using BankContracts.ViewModels;
namespace UniversityDatabaseImplement.Implements
{
public class PaymentStorage : IPaymentStorage
{
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()
{
@ -31,9 +32,9 @@ namespace UniversityDatabaseImplement.Implements
{
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)
@ -48,9 +49,9 @@ namespace UniversityDatabaseImplement.Implements
.ToList();
return Payments(context)
.Where(x => x.OperationByPurchase != null &&
x.OperationByPurchase.OperationId == model.OperationId &&
x.OperationByPurchase.PurchaseId == model.PurchaseId)
.Where(x => x.ClassByPurchase != null &&
x.ClassByPurchase.ClassId == model.ClassId &&
x.ClassByPurchase.PurchaseId == model.PurchaseId)
.Select(x => x.GetViewModel)
.ToList();
}

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@ -6,4 +6,24 @@
<Nullable>enable</Nullable>
</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>

View File

@ -1,6 +1,8 @@
using Serilog;
using UniversityBusinessLogics.BusinessLogic;
using UniversityContracts.BusinessLogicContracts;
using UniversityContracts.StoragesContracts;
using UniversityDatabaseImplement.Implements;
var builder = WebApplication.CreateBuilder(args);
@ -21,6 +23,20 @@ builder.Services.AddTransient<ICostStorage, CostStorage>();
builder.Services.AddTransient<IPurchaseStorage, PurchaseStorage>();
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();
// Configure the HTTP request pipeline.

View File

@ -6,9 +6,27 @@
<ImplicitUsings>enable</ImplicitUsings>
</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>
<ProjectReference Include="..\UniversityBusinessLogics\UniversityBusinessLogics.csproj" />
<ProjectReference Include="..\UniversityContracts\UniversityContracts.csproj" />
<ProjectReference Include="..\UniversityDatabaseImplement\UniversityDatabaseImplement.csproj" />
</ItemGroup>
</Project>