2023-04-06 22:52:23 +04:00
|
|
|
|
using SchoolContracts.BindingModel;
|
|
|
|
|
using SchoolContracts.ViewModels;
|
2023-04-09 02:44:56 +04:00
|
|
|
|
using SchoolDataModels.Models;
|
2023-04-06 22:52:23 +04:00
|
|
|
|
using System;
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using System.ComponentModel.DataAnnotations;
|
|
|
|
|
using System.Linq;
|
|
|
|
|
using System.Text;
|
|
|
|
|
using System.Threading.Tasks;
|
|
|
|
|
|
|
|
|
|
namespace SchoolDatabaseImplement.Models
|
|
|
|
|
{
|
2023-04-09 02:44:56 +04:00
|
|
|
|
public class Payment : IPaymentModel
|
2023-04-06 22:52:23 +04:00
|
|
|
|
{
|
|
|
|
|
public int Id { get; private set; }
|
|
|
|
|
[Required]
|
2023-04-07 23:28:12 +04:00
|
|
|
|
public int CircleLessonId { get; private set; }
|
|
|
|
|
[Required]
|
2023-04-09 02:44:56 +04:00
|
|
|
|
public int PaySum { get; private set; }
|
|
|
|
|
[Required]
|
|
|
|
|
public int Remains { get; private set; }
|
2023-04-06 22:52:23 +04:00
|
|
|
|
[Required]
|
|
|
|
|
public DateTime? DateOfPayment { get; private set; } = DateTime.Now;
|
2023-04-07 23:28:12 +04:00
|
|
|
|
public virtual CircleLesson CircleLesson { get; private set; } = new();
|
2023-04-06 22:52:23 +04:00
|
|
|
|
public static Payment? Create(SchoolDatabase context, PaymentBindingModel? model)
|
|
|
|
|
{
|
|
|
|
|
if (model == null)
|
|
|
|
|
{
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return new Payment()
|
|
|
|
|
{
|
|
|
|
|
Id = model.Id,
|
2023-04-07 23:28:12 +04:00
|
|
|
|
CircleLesson = context.CircleLessons.First(x => x.Id == model.CircleLessonId),
|
|
|
|
|
PaySum = model.PaySum,
|
2023-04-09 02:44:56 +04:00
|
|
|
|
DateOfPayment = model.DateOfPayment,
|
|
|
|
|
Remains = model.Remains
|
2023-04-06 22:52:23 +04:00
|
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
public void Update(PaymentBindingModel? model)
|
|
|
|
|
{
|
|
|
|
|
if (model == null)
|
|
|
|
|
{
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
Id = model.Id;
|
2023-04-07 23:28:12 +04:00
|
|
|
|
CircleLessonId = model.CircleLessonId;
|
|
|
|
|
PaySum = model.PaySum;
|
2023-04-06 22:52:23 +04:00
|
|
|
|
DateOfPayment = model.DateOfPayment;
|
2023-04-09 02:44:56 +04:00
|
|
|
|
Remains = model.Remains;
|
2023-04-06 22:52:23 +04:00
|
|
|
|
}
|
2023-04-09 02:44:56 +04:00
|
|
|
|
public PaymentViewModel GetViewModel => new()
|
2023-04-06 22:52:23 +04:00
|
|
|
|
{
|
2023-04-09 02:44:56 +04:00
|
|
|
|
Id = Id,
|
|
|
|
|
CircleLessonId = CircleLessonId,
|
|
|
|
|
PaySum = PaySum,
|
|
|
|
|
DateOfPayment = DateOfPayment,
|
|
|
|
|
Remains = Remains
|
|
|
|
|
};
|
2023-04-06 22:52:23 +04:00
|
|
|
|
}
|
|
|
|
|
}
|