готовая бизнес логика, осталось доделать отчеты и их логику

This commit is contained in:
Альфия Тукаева 2023-04-07 22:28:12 +03:00
parent eceb3f8f05
commit 15bcd7eb8a
54 changed files with 1210 additions and 146 deletions

View File

@ -0,0 +1,103 @@
using Microsoft.Extensions.Logging;
using SchoolContracts.BindingModels;
using SchoolContracts.BusinessLogicsContracts;
using SchoolContracts.SearchModel;
using SchoolContracts.StoragesContracts;
using SchoolContracts.ViewModels;
using SchoolDatabaseImplement.Implements;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace SchoolBusinessLogic.BusinessLogics
{
public class CircleExpenseLogic : ICircleExpenseLogic
{
private readonly ILogger _logger;
private readonly ICircleExpenseStorage _circleExpenseStorage;
public CircleExpenseLogic(ILogger<CircleExpenseLogic> logger, ICircleExpenseStorage circleExpenseStorage)
{
_logger= logger;
_circleExpenseStorage= circleExpenseStorage;
}
public bool Create(CircleExpenseBindingModel model)
{
CheckModel(model);
if (_circleExpenseStorage.Insert(model) == null)
{
_logger.LogWarning("Insert operation failed");
return false;
}
return true;
}
public bool Delete(CircleExpenseBindingModel model)
{
CheckModel(model, false);
_logger.LogInformation("Delete. Id: {Id}", model.Id);
if (_circleExpenseStorage.Delete(model) == null)
{
_logger.LogWarning("Delete operation failed");
return false;
}
return true;
}
public CircleExpenseViewModel? ReadElement(CircleExpenseSearchModel model)
{
if (model == null)
{
throw new ArgumentNullException(nameof(model));
}
_logger.LogInformation("ReadElement. Id: {Id}", model.Id);
var element = _circleExpenseStorage.GetElement(model);
if (element == null)
{
_logger.LogWarning("ReadElement element not found");
return null;
}
_logger.LogInformation("ReadElement found. Id: {Id}", element.Id);
return element;
}
public List<CircleExpenseViewModel>? ReadList(CircleExpenseSearchModel? model)
{
_logger.LogInformation("ReadList. Id: {Id}", model?.Id);
var list = model == null ? _circleExpenseStorage.GetFullList() : _circleExpenseStorage.GetFilteredList(model);
if (list == null)
{
_logger.LogWarning("ReadList return null list");
return null;
}
_logger.LogInformation("ReadList. Count: {Count}", list.Count);
return list;
}
public bool Update(CircleExpenseBindingModel model)
{
CheckModel(model);
if (_circleExpenseStorage.Update(model) == null)
{
_logger.LogWarning("Update operation failed");
return false;
}
return true;
}
private void CheckModel(CircleExpenseBindingModel model, bool withParams = true)
{
if (model == null)
{
throw new ArgumentException(nameof(model));
}
if (!withParams)
{
return;
}
_logger.LogInformation("CircleExpense. Id: {Id}", model.Id);
}
}
}

View File

@ -0,0 +1,103 @@
using Microsoft.Extensions.Logging;
using SchoolContracts.BindingModels;
using SchoolContracts.BusinessLogicsContracts;
using SchoolContracts.SearchModel;
using SchoolContracts.StoragesContracts;
using SchoolContracts.ViewModels;
using SchoolDatabaseImplement.Implements;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace SchoolBusinessLogic.BusinessLogics
{
public class CircleLessonLogic : ICircleLessonLogic
{
private readonly ILogger _logger;
private readonly ICircleLessonStorage _circleLessonStorage;
public CircleLessonLogic(ILogger<CircleLessonLogic> logger, ICircleLessonStorage circleLessonStorage)
{
_logger= logger;
_circleLessonStorage= circleLessonStorage;
}
public bool Create(CircleLessonBindingModel model)
{
CheckModel(model);
if (_circleLessonStorage.Insert(model) == null)
{
_logger.LogWarning("Insert operation failed");
return false;
}
return true;
}
public bool Delete(CircleLessonBindingModel model)
{
CheckModel(model, false);
_logger.LogInformation("Delete. Id: {Id}", model.Id);
if (_circleLessonStorage.Delete(model) == null)
{
_logger.LogWarning("Delete operation failed");
return false;
}
return true;
}
public CircleLessonViewModel? ReadElement(CircleLessonSearchModel model)
{
if (model == null)
{
throw new ArgumentNullException(nameof(model));
}
_logger.LogInformation("ReadElement. Id: {Id}", model.Id);
var element = _circleLessonStorage.GetElement(model);
if (element == null)
{
_logger.LogWarning("ReadElement element not found");
return null;
}
_logger.LogInformation("ReadElement found. Id: {Id}", element.Id);
return element;
}
public List<CircleLessonViewModel>? ReadList(CircleLessonSearchModel? model)
{
_logger.LogInformation("ReadList. Id: {Id}", model?.Id);
var list = model == null ? _circleLessonStorage.GetFullList() : _circleLessonStorage.GetFilteredList(model);
if (list == null)
{
_logger.LogWarning("ReadList return null list");
return null;
}
_logger.LogInformation("ReadList. Count: {Count}", list.Count);
return list;
}
public bool Update(CircleLessonBindingModel model)
{
CheckModel(model);
if (_circleLessonStorage.Update(model) == null)
{
_logger.LogWarning("Update operation failed");
return false;
}
return true;
}
private void CheckModel(CircleLessonBindingModel model, bool withParams = true)
{
if (model == null)
{
throw new ArgumentException(nameof(model));
}
if (!withParams)
{
return;
}
_logger.LogInformation("CircleLesson. Id: {Id}", model.Id);
}
}
}

View File

@ -0,0 +1,102 @@
using Microsoft.Extensions.Logging;
using SchoolContracts.BindingModels;
using SchoolContracts.BusinessLogicsContracts;
using SchoolContracts.SearchModel;
using SchoolContracts.StoragesContracts;
using SchoolContracts.ViewModels;
using SchoolDatabaseImplements.Implements;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace SchoolBusinessLogic.BusinessLogics
{
public class ExpenseLogic : IExpenseLogic
{
private readonly ILogger _logger;
private readonly IExpenseStorage _expenseStorage;
public ExpenseLogic(ILogger<CircleExpenseLogic> logger, IExpenseStorage expenseStorage)
{
_logger = logger;
_expenseStorage = expenseStorage;
}
public bool Create(ExpenseBindingModel model)
{
CheckModel(model);
if (_expenseStorage.Insert(model) == null)
{
_logger.LogWarning("Insert operation failed");
return false;
}
return true;
}
public bool Delete(ExpenseBindingModel model)
{
CheckModel(model, false);
_logger.LogInformation("Delete. Id: {Id}", model.Id);
if (_expenseStorage.Delete(model) == null)
{
_logger.LogWarning("Delete operation failed");
return false;
}
return true;
}
public ExpenseViewModel? ReadElement(ExpenseSearchModel model)
{
if (model == null)
{
throw new ArgumentNullException(nameof(model));
}
_logger.LogInformation("ReadElement. Id: {Id}", model.Id);
var element = _expenseStorage.GetElement(model);
if (element == null)
{
_logger.LogWarning("ReadElement element not found");
return null;
}
_logger.LogInformation("ReadElement found. Id: {Id}", element.Id);
return element;
}
public List<ExpenseViewModel>? ReadList(ExpenseSearchModel? model)
{
_logger.LogInformation("ReadList. Id: {Id}", model?.Id);
var list = model == null ? _expenseStorage.GetFullList() : _expenseStorage.GetFilteredList(model);
if (list == null)
{
_logger.LogWarning("ReadList return null list");
return null;
}
_logger.LogInformation("ReadList. Count: {Count}", list.Count);
return list;
}
public bool Update(ExpenseBindingModel model)
{
CheckModel(model);
if (_expenseStorage.Update(model) == null)
{
_logger.LogWarning("Update operation failed");
return false;
}
return true;
}
private void CheckModel(ExpenseBindingModel model, bool withParams = true)
{
if (model == null)
{
throw new ArgumentException(nameof(model));
}
if (!withParams)
{
return;
}
_logger.LogInformation("Expense. Id: {Id}", model.Id);
}
}
}

View File

@ -0,0 +1,56 @@
using Microsoft.Extensions.Logging;
using SchoolContracts.BindingModel;
using SchoolContracts.BusinessLogicsContracts;
using SchoolContracts.SearchModel;
using SchoolContracts.StoragesContracts;
using SchoolContracts.ViewModels;
namespace SchoolBusinessLogic.BusinessLogics
{
public class PaymentLogic : IPaymentLogic
{
private readonly ILogger _logger;
private readonly IPaymentStorage _paymentStorage;
public PaymentLogic(ILogger<PaymentLogic> logger, IPaymentStorage paymentStorage)
{
_logger = logger;
_paymentStorage = paymentStorage;
}
public bool Create(PaymentBindingModel model)
{
throw new NotImplementedException();
}
public bool Delete(PaymentBindingModel model)
{
throw new NotImplementedException();
}
public PaymentViewModel? ReadElement(PaymentSearchModel model)
{
throw new NotImplementedException();
}
public List<PaymentViewModel>? ReadList(PaymentSearchModel? model)
{
throw new NotImplementedException();
}
public bool Update(PaymentBindingModel model)
{
throw new NotImplementedException();
}
private void CheckModel(LessonBindingModel model, bool withParams = true)
{
if (model == null)
{
throw new ArgumentNullException(nameof(model));
}
if (!withParams)
{
return;
}
_logger.LogInformation("Lesson. Id: {Id}", model.Id);
}
}
}

View File

@ -0,0 +1,13 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace SchoolBusinessLogic.BusinessLogics
{
public class ReportLessonsLogic
{
}
}

View File

@ -1,4 +1,8 @@
using System; using Microsoft.Extensions.Logging;
using SchoolContracts.BusinessLogicsContracts;
using SchoolContracts.StoragesContracts;
using SchoolContracts.ViewModels;
using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Linq; using System.Linq;
using System.Text; using System.Text;
@ -6,8 +10,42 @@ using System.Threading.Tasks;
namespace SchoolContracts.BusinessLogics namespace SchoolContracts.BusinessLogics
{ {
public class ReportLogic public class ReportLogic : IReportLogic
{
private readonly ICircleStorage _circleStorage;
private readonly IExpenseStorage _expenseStorage;
/// <summary>
/// Получение списка кружков с указанием списка затрат по ним
/// </summary>
/// <returns></returns>
public List<ReportViewModel> GetCircles()
{
var expenses = _expenseStorage.GetFullList();
var circles = _circleStorage.GetFullList();
var list = new List<ReportViewModel>();
foreach(var circle in circles)
{
var record = new ReportViewModel
{
CircleNumber = circle.Id,
Expenses = new List<ReportExpensesViewModel>(),
CircleCount = 0
};
foreach (var expense in expenses)
{ {
}
list.Add(record);
}
return list;
}
/// <summary>
/// Получение списка занятий за определенный период
/// </summary>
/// <param name="model"></param>
/// <returns></returns>
} }
} }

View File

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

View File

@ -0,0 +1,18 @@
using SchoolDataModels.Models;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace SchoolContracts.BindingModels
{
public class CircleExpenseBindingModel : ICircleExpenseModel
{
public int CircleId { get; set; }
public int ExpenseId { get; set; }
public int Id { get; set; }
}
}

View File

@ -0,0 +1,18 @@
using SchoolDataModels.Models;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace SchoolContracts.BindingModels
{
public class CircleLessonBindingModel : ICircleLessonModel
{
public int CircleId { get; set; }
public int LessonId { get; set; }
public int Id { get; set; }
}
}

View File

@ -11,5 +11,6 @@ namespace SchoolContracts.BindingModels
{ {
public int Id { get; set; } public int Id { get; set; }
public double Sum { get; set;} public double Sum { get; set;}
public string ExpenseName { get; set;}
} }
} }

View File

@ -10,10 +10,9 @@ namespace SchoolContracts.BindingModel
public class PaymentBindingModel : IPaymentModel public class PaymentBindingModel : IPaymentModel
{ {
public int Id { get; set; } public int Id { get; set; }
public double Sum { get; set; } public double PaySum { get; set; }
public double Remains { get; set; }
public DateTime? DateOfPayment { get; set; } = DateTime.Now; public DateTime? DateOfPayment { get; set; } = DateTime.Now;
public int LessonId { get; set; } public int CircleLessonId { get; set; }
} }
} }

View File

@ -9,9 +9,18 @@ namespace SchoolContracts.BindingModel
public class ReportBindingModel public class ReportBindingModel
{ {
public string FileName { get; set; } = string.Empty; public string FileName { get; set; } = string.Empty;
/// <summary>
/// Выбранные кружки для отчета
/// </summary>
public List<int>? SelectedCircles { get; set; }
/// <summary>
/// Начало периода для отчета по затратам
/// </summary>
public DateTime? DateFrom { get; set; } public DateTime? DateFrom { get; set; }
/// <summary>
/// Конец периода для отчета по затратам
/// </summary>
public DateTime? DateTo { get; set; } public DateTime? DateTo { get; set; }
public int UserId { get; set; }
} }
} }

View File

@ -0,0 +1,21 @@
using SchoolContracts.BindingModel;
using SchoolContracts.BindingModels;
using SchoolContracts.SearchModel;
using SchoolContracts.ViewModels;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace SchoolContracts.BusinessLogicsContracts
{
public interface ICircleExpenseLogic
{
List<CircleExpenseViewModel>? ReadList(CircleExpenseSearchModel? model);
CircleExpenseViewModel? ReadElement(CircleExpenseSearchModel model);
bool Create(CircleExpenseBindingModel model);
bool Update(CircleExpenseBindingModel model);
bool Delete(CircleExpenseBindingModel model);
}
}

View File

@ -0,0 +1,21 @@
using SchoolContracts.BindingModel;
using SchoolContracts.BindingModels;
using SchoolContracts.SearchModel;
using SchoolContracts.ViewModels;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace SchoolContracts.BusinessLogicsContracts
{
public interface ICircleLessonLogic
{
List<CircleLessonViewModel>? ReadList(CircleLessonSearchModel? model);
CircleLessonViewModel? ReadElement(CircleLessonSearchModel model);
bool Create(CircleLessonBindingModel model);
bool Update(CircleLessonBindingModel model);
bool Delete(CircleLessonBindingModel model);
}
}

View File

@ -0,0 +1,20 @@
using SchoolContracts.BindingModels;
using SchoolContracts.SearchModel;
using SchoolContracts.ViewModels;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace SchoolContracts.BusinessLogicsContracts
{
public interface IExpenseLogic
{
List<ExpenseViewModel>? ReadList(ExpenseSearchModel? model);
ExpenseViewModel? ReadElement(ExpenseSearchModel model);
bool Create(ExpenseBindingModel model);
bool Update(ExpenseBindingModel model);
bool Delete(ExpenseBindingModel model);
}
}

View File

@ -12,8 +12,10 @@ namespace SchoolContracts.BusinessLogicsContracts
public interface IPaymentLogic public interface IPaymentLogic
{ {
List<PaymentViewModel>? ReadList(PaymentSearchModel? model); List<PaymentViewModel>? ReadList(PaymentSearchModel? model);
void CreateOrUpdate(PaymentBindingModel model); PaymentViewModel? ReadElement(PaymentSearchModel model);
void Delete(PaymentBindingModel model); bool Create(PaymentBindingModel model);
bool Update(PaymentBindingModel model);
bool Delete(PaymentBindingModel model);
} }
} }

View File

@ -0,0 +1,17 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace SchoolContracts.BusinessLogicsContracts
{
/// <summary>
/// Получение списка занятий с указанием, в каких кружках используются
/// </summary>
/// <returns></returns>
public interface IReportLessonsLogic
{
}
}

View File

@ -1,5 +1,6 @@
using SchoolContracts.BindingModel; using SchoolContracts.BindingModel;
using SchoolContracts.ViewModels; using SchoolContracts.ViewModels;
using SchoolDataModels.Models;
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Linq; using System.Linq;
@ -11,18 +12,30 @@ namespace SchoolContracts.BusinessLogicsContracts
public interface IReportLogic public interface IReportLogic
{ {
/// <summary> /// <summary>
/// Получение списка занятий с указанием, в каких кружках используются /// Получение списка кружков
/// </summary> /// </summary>
/// <returns></returns> /// <returns></returns>
List<ReportCircleLessonViewModel> GetCircleLesson(); List<ReportCirclesViewModel> GetCircles(ReportBindingModel model);
List<ReportLessonCircleViewModel> GetLessonCircle(); /// <summary>
void SaveCircleLessonToExcelFile(ReportBindingModel model); /// Получение списка затрат за определенный период
void SaveLessonCircleToExcelFile(ReportBindingModel model); /// </summary>
void SaveCircleLessonToWordFile(ReportBindingModel model); /// <param name="model"></param>
void SaveLessonCircleToWordFile(ReportBindingModel model); /// <returns></returns>
List<ReportCircleViewModel> GetOrders(ReportBindingModel model); //List<ReportOrdersViewModel> GetExpenses(ReportBindingModel model);
List<ReportCircleViewModel> GetCircles(ReportBindingModel model); /// <summary>
void SaveOrdersToPdfFileCircle(ReportBindingModel model); /// Сохранение компонент в файл-Word
void SaveOrdersToPdfFileLessons(ReportBindingModel model); /// </summary>
/// <param name="model"></param>
void SaveComponentsToWordFile(ReportBindingModel model);
/// <summary>
/// Сохранение компонент с указаеним продуктов в файл-Excel
/// </summary>
/// <param name="model"></param>
void SaveManufactureComponentToExcelFile(ReportBindingModel model);
/// <summary>
/// Сохранение заказов в файл-Pdf
/// </summary>
/// <param name="model"></param>
void SaveOrdersToPdfFile(ReportBindingModel model);
} }
} }

View File

@ -0,0 +1,13 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace SchoolContracts.SearchModel
{
public class CircleExpenseSearchModel
{
public int? Id { get; set; }
}
}

View File

@ -0,0 +1,13 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace SchoolContracts.SearchModel
{
public class CircleLessonSearchModel
{
public int? Id { get; set; }
}
}

View File

@ -12,5 +12,9 @@ namespace SchoolContracts.SearchModel
public DateTime? DateFrom { get; set; } public DateTime? DateFrom { get; set; }
public DateTime? DateTo { get; set; } public DateTime? DateTo { get; set; }
public int? ClientId { get; set; } public int? ClientId { get; set; }
/// <summary>
/// Id выбранных кружков
/// </summary>
public List<int>? SelectedCirclesIds { get; set; }
} }
} }

View File

@ -9,5 +9,8 @@ namespace SchoolContracts.SearchModel
public class ExpenseSearchModel public class ExpenseSearchModel
{ {
public int? Id { get; set; } public int? Id { get; set; }
public string ExpenseName { get; set; }
public DateTime? DateTo { get; set; }
public DateTime? DateFrom { get; set; }
} }
} }

View File

@ -9,8 +9,6 @@ namespace SchoolContracts.SearchModel
public class PaymentSearchModel public class PaymentSearchModel
{ {
public int? Id { get; set; } public int? Id { get; set; }
public DateTime? DateTo { get; set; } public int? CircleLessonId { get; set; }
public DateTime? DateFrom { get; set; }
public int? LessonId { get; set; }
} }
} }

View File

@ -0,0 +1,22 @@
using SchoolContracts.BindingModel;
using SchoolContracts.BindingModels;
using SchoolContracts.SearchModel;
using SchoolContracts.ViewModels;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace SchoolContracts.StoragesContracts
{
public interface ICircleExpenseStorage
{
List<CircleExpenseViewModel> GetFullList();
List<CircleExpenseViewModel> GetFilteredList(CircleExpenseSearchModel model);
CircleExpenseViewModel GetElement(CircleExpenseSearchModel model);
CircleExpenseViewModel? Insert(CircleExpenseBindingModel model);
CircleExpenseViewModel? Update(CircleExpenseBindingModel model);
CircleExpenseViewModel? Delete(CircleExpenseBindingModel model);
}
}

View File

@ -0,0 +1,22 @@
using SchoolContracts.BindingModel;
using SchoolContracts.BindingModels;
using SchoolContracts.SearchModel;
using SchoolContracts.ViewModels;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace SchoolContracts.StoragesContracts
{
public interface ICircleLessonStorage
{
List<CircleLessonViewModel> GetFullList();
List<CircleLessonViewModel> GetFilteredList(CircleLessonSearchModel model);
CircleLessonViewModel GetElement(CircleLessonSearchModel model);
CircleLessonViewModel? Insert(CircleLessonBindingModel model);
CircleLessonViewModel? Update(CircleLessonBindingModel model);
CircleLessonViewModel? Delete(CircleLessonBindingModel model);
}
}

View File

@ -13,7 +13,8 @@ namespace SchoolContracts.StoragesContracts
{ {
List<CircleViewModel> GetFullList(); List<CircleViewModel> GetFullList();
List<CircleViewModel> GetFilteredList(CircleSearchModel model); List<CircleViewModel> GetFilteredList(CircleSearchModel model);
CircleViewModel GetElement(CircleSearchModel model); List<ReportCircleLessonsViewModel> GetLessonCircles(CircleSearchModel model);
CircleViewModel? GetElement(CircleSearchModel model);
CircleViewModel? Insert(CircleBindingModel model); CircleViewModel? Insert(CircleBindingModel model);
CircleViewModel? Update(CircleBindingModel model); CircleViewModel? Update(CircleBindingModel model);
CircleViewModel? Delete(CircleBindingModel model); CircleViewModel? Delete(CircleBindingModel model);

View File

@ -0,0 +1,19 @@
using SchoolDataModels.Models;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace SchoolContracts.ViewModels
{
public class CircleExpenseViewModel : ICircleExpenseModel
{
[DisplayName("Id кружка")]
public int CircleId { get; set; }
[DisplayName("Id затраты")]
public int ExpenseId { get; set; }
public int Id { get; set; }
}
}

View File

@ -0,0 +1,19 @@
using SchoolDataModels.Models;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace SchoolContracts.ViewModels
{
public class CircleLessonViewModel : ICircleLessonModel
{
[DisplayName("Id кружка")]
public int CircleId { get; set; }
[DisplayName("Id занятия")]
public int LessonId { get; set; }
public int Id { get; set; }
}
}

View File

@ -10,6 +10,7 @@ namespace SchoolContracts.ViewModels
public class ExpenseViewModel : IExpenseModel public class ExpenseViewModel : IExpenseModel
{ {
public int Id { get; set; } public int Id { get; set; }
public string ExpenseName { get; set; }
public double Sum { get; set; } public double Sum { get; set; }
} }
} }

View File

@ -10,10 +10,9 @@ namespace SchoolContracts.ViewModels
public class PaymentViewModel : IPaymentModel public class PaymentViewModel : IPaymentModel
{ {
public int Id { get; set; } public int Id { get; set; }
public double Sum { get; set; } public double PaySum { get; set; }
public double Remains { get; set; }
public DateTime? DateOfPayment { get; set; } public DateTime? DateOfPayment { get; set; }
public int LessonId { get; set; } public int CircleLessonId { get; set; }
} }
} }

View File

@ -1,16 +0,0 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace SchoolContracts.ViewModels
{
public class ReportCircleLessonViewModel
{
public DateTime? StartDate { get; set; }
public List<string> Lessons { get; set; }
public int TotalCount { get; set; }
}
}

View File

@ -0,0 +1,23 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace SchoolContracts.ViewModels
{
/// <summary>
/// Модель для получения всех занятий по кружку для отчета
/// </summary>
public class ReportCircleLessonsViewModel
{
/// <summary>
/// Номер кружка
/// </summary>
public int CircleId { get; set; }
/// <summary>
/// Занятия в кружке
/// </summary>
public List<ReportLessonCirclesViewModel> CircleLessons { get; set; } = new();
}
}

View File

@ -1,17 +0,0 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace SchoolContracts.ViewModels
{
public class ReportCircleViewModel
{
public DateTime DateStart { get; set; }
public string ClientName { get; set; }
public double Sum { get; set; }
public Dictionary<string, int> Circles { get; set; }
}
}

View File

@ -0,0 +1,18 @@
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace SchoolContracts.ViewModels
{
public class ReportExpensesViewModel
{
[DisplayName("Название затраты")]
public string ExpenseName { get; set; } = string.Empty;
[DisplayName("Сумма")]
public double Sum { get; set; }
}
}

View File

@ -1,16 +0,0 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace SchoolContracts.ViewModels
{
public class ReportLessonCircleViewModel
{
public string LessonName { get; set; }
public List<DateTime> Circles { get; set; }
public int TotalCount { get; set; }
}
}

View File

@ -0,0 +1,23 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace SchoolContracts.ViewModels
{
/// <summary>
/// Модель для получения всех занятий по кружку для отчета
/// </summary>
public class ReportLessonCircleViewModel
{
/// <summary>
/// Номер кружка
/// </summary>
public int CircleId { get; set; }
/// <summary>
/// Занятия в кружке
/// </summary>
public List<ReportCircleLessonsViewModel> CircleLessons { get; set; } = new();
}
}

View File

@ -10,14 +10,15 @@ namespace SchoolContracts.ViewModels
public class ReportViewModel public class ReportViewModel
{ {
[DisplayName("Имя кружка")] [DisplayName("Имя кружка")]
int CircleNumber { get; set; } public int CircleNumber { get; set; }
[DisplayName("Дата кружка")] [DisplayName("Дата записи")]
DateTime Date { get; set; } public DateTime Date { get; set; }
[DisplayName("Сумма")] [DisplayName("Сумма затрат")]
double Sum { get; set; } public double Sum { get; set; }
[DisplayName("Кол-во занятий")] [DisplayName("Кол-во занятий")]
int CircleCount { get; set; } public int CircleCount { get; set; }
[DisplayName("Имя клиента")] [DisplayName("Название затраты")]
string ClientName { get; set; } = string.Empty; public List<ReportExpensesViewModel> Expenses{ get; set; }
} }
} }

View File

@ -1,15 +0,0 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace SchoolContracts.ViewModels
{
public class ReportViewerLessonModel
{
public string LessonName { get; set; }
public int Count { get; set; }
}
}

View File

@ -0,0 +1,23 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace SchoolDataModels.Models
{
/// <summary>
/// Кружок и затраты
/// </summary>
public interface ICircleExpenseModel : IId
{
/// <summary>
/// Id кружка
/// </summary>
public int CircleId { get;}
/// <summary>
/// Id затрат
/// </summary>
public int ExpenseId { get; }
}
}

View File

@ -0,0 +1,23 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace SchoolDataModels.Models
{
/// <summary>
/// Кружок и занятие
/// </summary>
public interface ICircleLessonModel : IId
{
/// <summary>
/// Id кружка
/// </summary>
public int CircleId { get; }
/// /// <summary>
/// Id занятия
/// </summary>
public int LessonId { get; }
}
}

View File

@ -15,5 +15,9 @@ namespace SchoolDataModels.Models
/// Сумма затраты /// Сумма затраты
/// </summary> /// </summary>
public double Sum { get; } public double Sum { get; }
/// <summary>
/// Название
/// </summary>
public string ExpenseName { get; }
} }
} }

View File

@ -12,13 +12,9 @@ namespace SchoolDataModels.Models
public interface IPaymentModel : IId public interface IPaymentModel : IId
{ {
/// <summary> /// <summary>
/// Сумма /// Оплаченная сумма
/// </summary> /// </summary>
public double Sum { get; set; } public double PaySum { get; set; }
/// <summary>
/// Остатки
/// </summary>
public double Remains { get; set; }
/// <summary> /// <summary>
/// Дата платежа /// Дата платежа
/// </summary> /// </summary>
@ -26,6 +22,6 @@ namespace SchoolDataModels.Models
/// <summary> /// <summary>
/// Id занятия /// Id занятия
/// </summary> /// </summary>
public int LessonId { get; set; } public int CircleLessonId { get; set; }
} }
} }

View File

@ -0,0 +1,94 @@
using Microsoft.EntityFrameworkCore;
using SchoolContracts.BindingModels;
using SchoolContracts.SearchModel;
using SchoolContracts.StoragesContracts;
using SchoolContracts.ViewModels;
using SchoolDatabaseImplement;
using SchoolDatabaseImplement.Models;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace SchoolDatabaseImplements.Implements
{
public class CircleExpenseStorage : ICircleExpenseStorage
{
public CircleExpenseViewModel? Delete(CircleExpenseBindingModel model)
{
using var context = new SchoolDatabase();
var circleExpense = context.CircleExpenses.FirstOrDefault(rec => rec.Id == model.Id);
if (circleExpense != null)
{
context.CircleExpenses.Remove(circleExpense);
context.SaveChanges();
return circleExpense.GetViewModel;
}
return null;
}
public CircleExpenseViewModel GetElement(CircleExpenseSearchModel model)
{
if (model == null)
{
return null;
}
using var context = new SchoolDatabase();
if (model.Id.HasValue)
{
return context.CircleExpenses.Include(x => x.Circle)
.Include(x => x.Expense)
.FirstOrDefault(x => x.Id == model.Id)?.GetViewModel;
}
return null;
}
public List<CircleExpenseViewModel> GetFilteredList(CircleExpenseSearchModel model)
{
using var context = new SchoolDatabase();
return context.CircleExpenses
.Where(x => x.Id == model.Id)
.Include(x => x.Circle)
.Include(x => x.Expense)
.Select(x => x.GetViewModel)
.ToList();
}
public List<CircleExpenseViewModel> GetFullList()
{
using var context = new SchoolDatabase();
return context.CircleExpenses
.Include(x => x.Circle)
.Include(x => x.Expense)
.Select(x => x.GetViewModel)
.ToList();
}
public CircleExpenseViewModel? Insert(CircleExpenseBindingModel model)
{
using var context = new SchoolDatabase();
var newCircleExpense = CircleExpense.Create(context, model);
if (newCircleExpense == null)
{
return null;
}
context.CircleExpenses.Add(newCircleExpense);
context.SaveChanges();
return newCircleExpense.GetViewModel;
}
public CircleExpenseViewModel? Update(CircleExpenseBindingModel model)
{
using var context = new SchoolDatabase();
var circleExpense = context.CircleExpenses.FirstOrDefault(x => x.Id == model.Id);
if (circleExpense == null)
{
return null;
}
circleExpense.Update(model);
context.SaveChanges();
return circleExpense.GetViewModel;
}
}
}

View File

@ -0,0 +1,94 @@
using Microsoft.EntityFrameworkCore;
using SchoolContracts.BindingModels;
using SchoolContracts.SearchModel;
using SchoolContracts.StoragesContracts;
using SchoolContracts.ViewModels;
using SchoolDatabaseImplement;
using SchoolDatabaseImplement.Models;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace SchoolDatabaseImplements.Implements
{
public class CircleLessonStorage : ICircleLessonStorage
{
public CircleLessonViewModel? Delete(CircleLessonBindingModel model)
{
using var context = new SchoolDatabase();
var circlelesson = context.CircleLessons.FirstOrDefault(rec => rec.Id == model.Id);
if (circlelesson != null)
{
context.CircleLessons.Remove(circlelesson);
context.SaveChanges();
return circlelesson.GetViewModel;
}
return null;
}
public CircleLessonViewModel? GetElement(CircleLessonSearchModel model)
{
if (model == null)
{
return null;
}
using var context = new SchoolDatabase();
if (model.Id.HasValue)
{
return context.CircleLessons.Include(x => x.Circle)
.Include(x => x.Lesson)
.FirstOrDefault(x => x.Id == model.Id)?.GetViewModel;
}
return null;
}
public List<CircleLessonViewModel> GetFilteredList(CircleLessonSearchModel model)
{
using var context = new SchoolDatabase();
return context.CircleLessons
.Where(x => x.Id == model.Id)
.Include(x => x.Circle)
.Include(x => x.Lesson)
.Select(x => x.GetViewModel)
.ToList();
}
public List<CircleLessonViewModel> GetFullList()
{
using var context = new SchoolDatabase();
return context.CircleLessons
.Include(x => x.Circle)
.Include(x => x.Lesson)
.Select(x => x.GetViewModel)
.ToList();
}
public CircleLessonViewModel? Insert(CircleLessonBindingModel model)
{
using var context = new SchoolDatabase();
var newCircleLesson = CircleLesson.Create(context, model);
if (newCircleLesson == null)
{
return null;
}
context.CircleLessons.Add(newCircleLesson);
context.SaveChanges();
return newCircleLesson.GetViewModel;
}
public CircleLessonViewModel? Update(CircleLessonBindingModel model)
{
using var context = new SchoolDatabase();
var circlelesson = context.CircleLessons.FirstOrDefault(x => x.Id == model.Id);
if (circlelesson == null)
{
return null;
}
circlelesson.Update(model);
context.SaveChanges();
return circlelesson.GetViewModel;
}
}
}

View File

@ -17,7 +17,6 @@ namespace SchoolDatabaseImplement.Implements
{ {
public List<CircleViewModel> GetFullList() public List<CircleViewModel> GetFullList()
{ {
using var context = new SchoolDatabase(); using var context = new SchoolDatabase();
return context.Circles return context.Circles
.Include(x => x.Client) .Include(x => x.Client)
@ -94,5 +93,37 @@ namespace SchoolDatabaseImplement.Implements
} }
return null; return null;
} }
public List<ReportCircleLessonsViewModel> GetLessonCircles(CircleSearchModel model)
{
if (model.SelectedCirclesIds == null)
{
return new();
}
using var context = new SchoolDatabase();
return context.Circles
.Where(c => model.SelectedCirclesIds.Contains(c.Id))
.Select(c => new ReportCircleLessonsViewModel()
{
CircleLessons = GetCircleLessons(context, new() { Id = c.Id })
})
.ToList();
}
/// <summary>
/// Получение списка занятий по выбранному кружку
/// </summary>
/// <param name="model"></param>
/// <returns></returns>
private static List<ReportLessonCirclesViewModel> GetCircleLessons(SchoolDatabase context, CircleSearchModel model)
{
return context.Circles
.Include(wir => wir.CircleLessons)
.Where(wir => wir.Id == model.Id)
.Select(wir => new ReportLessonCirclesViewModel()
{
LessonId = wir.CircleLessons.Id
})
.ToList();
}
} }
} }

View File

@ -1,7 +1,10 @@
using SchoolContracts.BindingModels; using Microsoft.EntityFrameworkCore;
using SchoolContracts.BindingModels;
using SchoolContracts.SearchModel; using SchoolContracts.SearchModel;
using SchoolContracts.StoragesContracts; using SchoolContracts.StoragesContracts;
using SchoolContracts.ViewModels; using SchoolContracts.ViewModels;
using SchoolDatabaseImplement;
using SchoolDatabaseImplement.Models;
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Linq; using System.Linq;
@ -14,32 +17,74 @@ namespace SchoolDatabaseImplements.Implements
{ {
public ExpenseViewModel? Delete(ExpenseBindingModel model) public ExpenseViewModel? Delete(ExpenseBindingModel model)
{ {
throw new NotImplementedException(); using var context = new SchoolDatabase();
var element = context.Expenses.FirstOrDefault(x => x.Id == model.Id);
if (element != null)
{
context.Expenses.Remove(element);
context.SaveChanges();
return element.GetViewModel;
}
return null;
} }
public ExpenseViewModel GetElement(ExpenseSearchModel model) public ExpenseViewModel GetElement(ExpenseSearchModel model)
{ {
throw new NotImplementedException(); using var context = new SchoolDatabase();
if (model.Id.HasValue)//сначала ищем по Id
{
return context.Expenses
.FirstOrDefault(x => x.Id == model.Id)?.GetViewModel;
}
if (!string.IsNullOrEmpty(model.ExpenseName))//затем по названию
{
return context.Expenses
.FirstOrDefault(x => x.ExpenseName == model.ExpenseName)?.GetViewModel;
}
return null;
} }
public List<ExpenseViewModel> GetFilteredList(ExpenseSearchModel model) public List<ExpenseViewModel> GetFilteredList(ExpenseSearchModel model)
{ {
throw new NotImplementedException(); using var context = new SchoolDatabase();
return context.Expenses
.Where (x => x.Id == model.Id)
.Select(x => x.GetViewModel)
.ToList();
} }
public List<ExpenseViewModel> GetFullList() public List<ExpenseViewModel> GetFullList()
{ {
throw new NotImplementedException(); using var context = new SchoolDatabase();
return context.Expenses
.Select(x => x.GetViewModel)
.ToList();
} }
public ExpenseViewModel? Insert(ExpenseBindingModel model) public ExpenseViewModel? Insert(ExpenseBindingModel model)
{ {
throw new NotImplementedException(); using var context = new SchoolDatabase();
var newExpense = Expense.Create(model);
if (newExpense == null)
{
return null;
}
context.Expenses.Add(newExpense);
context.SaveChanges();
return newExpense.GetViewModel;
} }
public ExpenseViewModel? Update(ExpenseBindingModel model) public ExpenseViewModel? Update(ExpenseBindingModel model)
{ {
throw new NotImplementedException(); using var context = new SchoolDatabase();
var expense = context.Expenses.FirstOrDefault(x => x.Id == model.Id);
if (expense == null)
{
return null;
}
expense.Update(model);
context.SaveChanges();
return expense.GetViewModel;
} }
} }
} }

View File

@ -76,7 +76,7 @@ namespace SchoolDatabaseImplement.Implements
public LessonViewModel? Delete(LessonBindingModel model) public LessonViewModel? Delete(LessonBindingModel model)
{ {
using var context = new SchoolDatabase(); using var context = new SchoolDatabase();
var element = context.Lessons.FirstOrDefault(rec => rec.Id == model.Id); var element = context.Lessons.FirstOrDefault(x => x.Id == model.Id);
if (element != null) if (element != null)
{ {
context.Lessons.Remove(element); context.Lessons.Remove(element);

View File

@ -19,7 +19,7 @@ namespace SchoolDatabaseImplement.Implements
{ {
using var context = new SchoolDatabase(); using var context = new SchoolDatabase();
return context.Payments return context.Payments
.Include(rec => rec.Lesson) .Include(rec => rec.CircleLesson)
.Select(x => x.GetViewModel) .Select(x => x.GetViewModel)
.ToList(); .ToList();
} }
@ -31,17 +31,16 @@ namespace SchoolDatabaseImplement.Implements
return null; return null;
} }
using var context = new SchoolDatabase(); using var context = new SchoolDatabase();
var list = context.Payments.Where(x => x.LessonId == model.LessonId) var list = context.Payments.Where(x => x.CircleLessonId == model.CircleLessonId)
.OrderBy(x => x.DateOfPayment) .OrderBy(x => x.DateOfPayment)
.Include(x => x.Lesson); .Include(x => x.CircleLesson);
return list return list
.Select(x => new PaymentViewModel .Select(x => new PaymentViewModel
{ {
DateOfPayment = x.DateOfPayment, DateOfPayment = x.DateOfPayment,
Id = x.Id, Id = x.Id,
Remains = x.Remains, PaySum = x.PaySum,
Sum = x.Sum, CircleLessonId = x.CircleLessonId
LessonId = x.LessonId
}) })
.ToList(); .ToList();
} }
@ -53,15 +52,14 @@ namespace SchoolDatabaseImplement.Implements
} }
using var context = new SchoolDatabase(); using var context = new SchoolDatabase();
{ {
var payment = context.Payments.Include(x=> x.Lesson) var payment = context.Payments.Include(x=> x.CircleLesson)
.FirstOrDefault(x => x.LessonId == model.LessonId); .FirstOrDefault(x => x.CircleLessonId == model.CircleLessonId);
return payment != null? new PaymentViewModel return payment != null ? new PaymentViewModel
{ {
DateOfPayment = payment.DateOfPayment, DateOfPayment = payment.DateOfPayment,
Id = payment.Id, Id = payment.Id,
Remains = payment.Lesson.LessonPrice, PaySum = payment.PaySum,
Sum = payment.Sum, CircleLessonId = payment.CircleLessonId
LessonId = payment.LessonId
} : } :
null; null;
} }
@ -83,7 +81,7 @@ namespace SchoolDatabaseImplement.Implements
{ {
var context = new SchoolDatabase(); var context = new SchoolDatabase();
var element = context.Payments. var element = context.Payments.
Include(x => x.Lesson) Include(x => x.CircleLesson)
.FirstOrDefault(rec => rec.Id == model.Id); .FirstOrDefault(rec => rec.Id == model.Id);
if (element == null) if (element == null)
{ {
@ -98,7 +96,7 @@ namespace SchoolDatabaseImplement.Implements
var context = new SchoolDatabase(); var context = new SchoolDatabase();
var element = context.Payments var element = context.Payments
.Include(x => x.Lesson) .Include(x => x.CircleLesson)
.FirstOrDefault(rec => rec.Id == model.Id); .FirstOrDefault(rec => rec.Id == model.Id);
if (element != null) if (element != null)
{ {

View File

@ -22,7 +22,7 @@ namespace SchoolDatabaseImplement.Models
public int ClientId { get; private set; } public int ClientId { get; private set; }
public virtual Client Client { get; private set; } = new(); public virtual Client Client { get; private set; } = new();
[ForeignKey("CircleId")] [ForeignKey("CircleId")]
public virtual List<CircleLesson> CircleLessons { get; set; } = new(); public virtual CircleLesson CircleLessons { get; set; } = new();
[ForeignKey("CircleId")] [ForeignKey("CircleId")]
public virtual List<CircleExpense> CircleExpenses { get; set; } = new(); public virtual List<CircleExpense> CircleExpenses { get; set; } = new();
public static Circle Create(SchoolDatabase context, CircleBindingModel model) public static Circle Create(SchoolDatabase context, CircleBindingModel model)

View File

@ -1,4 +1,7 @@
using Microsoft.EntityFrameworkCore; using Microsoft.EntityFrameworkCore;
using SchoolContracts.BindingModel;
using SchoolContracts.BindingModels;
using SchoolContracts.ViewModels;
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.ComponentModel.DataAnnotations; using System.ComponentModel.DataAnnotations;
@ -17,5 +20,27 @@ namespace SchoolDatabaseImplement.Models
public int CircleId { get; set; } public int CircleId { get; set; }
public virtual Expense Expense { get; set; } = new(); public virtual Expense Expense { get; set; } = new();
public virtual Circle Circle { get; set; } = new(); public virtual Circle Circle { get; set; } = new();
public static CircleExpense? Create(SchoolDatabase context, CircleExpenseBindingModel model)
{
if (model == null)
{
return null;
}
return new()
{
Id = model.Id,
Circle = context.Circles.First(x => x.Id == model.CircleId),
Expense = context.Expenses.First(x => x.Id == model.ExpenseId)
};
}
public void Update(CircleExpenseBindingModel model)
{
Id = model.Id;
}
public CircleExpenseViewModel GetViewModel => new()
{
Id = Id
};
} }
} }

View File

@ -1,4 +1,7 @@
using System; using SchoolContracts.BindingModel;
using SchoolContracts.BindingModels;
using SchoolContracts.ViewModels;
using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.ComponentModel; using System.ComponentModel;
using System.ComponentModel.DataAnnotations; using System.ComponentModel.DataAnnotations;
@ -21,5 +24,26 @@ namespace SchoolDatabaseImplement.Models
public int Count { get; set; } public int Count { get; set; }
public virtual Lesson Lesson { get; set; } = new(); public virtual Lesson Lesson { get; set; } = new();
public virtual Circle Circle { get; set; } = new(); public virtual Circle Circle { get; set; } = new();
[ForeignKey("CircleLessonId")]
public virtual List<Payment> Payments { get; set; } = new();
public static CircleLesson Create(SchoolDatabase context, CircleLessonBindingModel model)
{
return new CircleLesson()
{
Id = model.Id,
Circle = context.Circles.First(x => x.Id == model.CircleId),
Lesson = context.Lessons.First(x => x.Id == model.LessonId)
};
}
public void Update(CircleLessonBindingModel model)
{
Id = model.Id;
}
public CircleLessonViewModel GetViewModel => new()
{
Id = Id
};
} }
} }

View File

@ -53,8 +53,7 @@ namespace SchoolDatabaseImplement.Models
public ExpenseViewModel GetViewModel => new() public ExpenseViewModel GetViewModel => new()
{ {
Id = Id, Id = Id
//TODO
}; };
} }

View File

@ -1,4 +1,7 @@
using SchoolDataModels.Models; using SchoolContracts.BindingModel;
using SchoolContracts.BindingModels;
using SchoolContracts.ViewModels;
using SchoolDataModels.Models;
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.ComponentModel.DataAnnotations; using System.ComponentModel.DataAnnotations;
@ -12,9 +15,39 @@ namespace SchoolDatabaseImplement.Models
public class Expense : IExpenseModel public class Expense : IExpenseModel
{ {
public int Id { get; private set; } public int Id { get; private set; }
public string ExpenseName { get; private set; } = string.Empty;
[Required] [Required]
public double Sum { get; private set; } public double Sum { get; private set; }
[ForeignKey("ExpenseId")] [ForeignKey("ExpenseId")]
public virtual List<CircleExpense> CircleExpenses { get; set; } = new(); public virtual List<CircleExpense> CircleExpenses { get; set; } = new();
public static Expense? Create(ExpenseBindingModel model)
{
if (model == null)
{
return null;
}
return new()
{
Id = model.Id,
ExpenseName = model.ExpenseName,
Sum = model.Sum
};
}
public void Update(ExpenseBindingModel model)
{
if (model == null)
{
return;
}
ExpenseName = model.ExpenseName;
Sum = model.Sum;
}
public ExpenseViewModel GetViewModel => new()
{
Id = Id,
ExpenseName = ExpenseName,
Sum = Sum
};
} }
} }

View File

@ -13,12 +13,12 @@ namespace SchoolDatabaseImplement.Models
{ {
public int Id { get; private set; } public int Id { get; private set; }
[Required] [Required]
public int LessonId { get; private set; } public int CircleLessonId { get; private set; }
public double Sum { get; private set; } [Required]
public double Remains { get; private set; } public double PaySum { get; private set; }
[Required] [Required]
public DateTime? DateOfPayment { get; private set; } = DateTime.Now; public DateTime? DateOfPayment { get; private set; } = DateTime.Now;
public virtual Lesson Lesson { get; private set; } = new(); public virtual CircleLesson CircleLesson { get; private set; } = new();
public static Payment? Create(SchoolDatabase context, PaymentBindingModel? model) public static Payment? Create(SchoolDatabase context, PaymentBindingModel? model)
{ {
if (model == null) if (model == null)
@ -29,9 +29,8 @@ namespace SchoolDatabaseImplement.Models
return new Payment() return new Payment()
{ {
Id = model.Id, Id = model.Id,
Lesson = context.Lessons.First(x => x.Id == model.LessonId), CircleLesson = context.CircleLessons.First(x => x.Id == model.CircleLessonId),
Sum = model.Sum, PaySum = model.PaySum,
Remains = model.Remains,
DateOfPayment = model.DateOfPayment DateOfPayment = model.DateOfPayment
}; };
} }
@ -42,9 +41,8 @@ namespace SchoolDatabaseImplement.Models
return; return;
} }
Id = model.Id; Id = model.Id;
LessonId = model.LessonId; CircleLessonId = model.CircleLessonId;
Sum = model.Sum; PaySum = model.PaySum;
Remains = model.Remains;
DateOfPayment = model.DateOfPayment; DateOfPayment = model.DateOfPayment;
} }
@ -57,9 +55,8 @@ namespace SchoolDatabaseImplement.Models
return new() return new()
{ {
Id = Id, Id = Id,
LessonId = LessonId, CircleLessonId = CircleLessonId,
Sum = Sum, PaySum = PaySum,
Remains = Remains,
DateOfPayment = DateOfPayment DateOfPayment = DateOfPayment
}; };
} }