66 lines
1.4 KiB
C#
66 lines
1.4 KiB
C#
using SchoolContracts.BindingModel;
|
|
using SchoolContracts.ViewModels;
|
|
using System;
|
|
using System.Collections.Generic;
|
|
using System.ComponentModel.DataAnnotations;
|
|
using System.Linq;
|
|
using System.Text;
|
|
using System.Threading.Tasks;
|
|
|
|
namespace SchoolDatabaseImplement.Models
|
|
{
|
|
public class Payment
|
|
{
|
|
public int Id { get; private set; }
|
|
[Required]
|
|
public int CircleLessonId { get; private set; }
|
|
[Required]
|
|
public double PaySum { get; private set; }
|
|
[Required]
|
|
public DateTime? DateOfPayment { get; private set; } = DateTime.Now;
|
|
public virtual CircleLesson CircleLesson { get; private set; } = new();
|
|
public static Payment? Create(SchoolDatabase context, PaymentBindingModel? model)
|
|
{
|
|
if (model == null)
|
|
{
|
|
return null;
|
|
}
|
|
|
|
return new Payment()
|
|
{
|
|
Id = model.Id,
|
|
CircleLesson = context.CircleLessons.First(x => x.Id == model.CircleLessonId),
|
|
PaySum = model.PaySum,
|
|
DateOfPayment = model.DateOfPayment
|
|
};
|
|
}
|
|
public void Update(PaymentBindingModel? model)
|
|
{
|
|
if (model == null)
|
|
{
|
|
return;
|
|
}
|
|
Id = model.Id;
|
|
CircleLessonId = model.CircleLessonId;
|
|
PaySum = model.PaySum;
|
|
DateOfPayment = model.DateOfPayment;
|
|
}
|
|
|
|
|
|
public PaymentViewModel GetViewModel
|
|
{
|
|
get
|
|
{
|
|
var context = new SchoolDatabase();
|
|
return new()
|
|
{
|
|
Id = Id,
|
|
CircleLessonId = CircleLessonId,
|
|
PaySum = PaySum,
|
|
DateOfPayment = DateOfPayment
|
|
};
|
|
}
|
|
}
|
|
}
|
|
}
|