ISEbd-21_Tukaeva_A_A_School/School/SchoolDatabaseImplements/Models/Payment.cs

69 lines
1.4 KiB
C#
Raw Normal View History

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 LessonId { get; private set; }
public double Sum { get; private set; }
public double Remains { get; private set; }
[Required]
public DateTime? DateOfPayment { get; private set; } = DateTime.Now;
public virtual Lesson Lesson { get; private set; } = new();
public static Payment? Create(SchoolDatabase context, PaymentBindingModel? model)
{
if (model == null)
{
return null;
}
return new Payment()
{
Id = model.Id,
Lesson = context.Lessons.First(x => x.Id == model.LessonId),
Sum = model.Sum,
Remains = model.Remains,
DateOfPayment = model.DateOfPayment
};
}
public void Update(PaymentBindingModel? model)
{
if (model == null)
{
return;
}
Id = model.Id;
LessonId = model.LessonId;
Sum = model.Sum;
Remains = model.Remains;
DateOfPayment = model.DateOfPayment;
}
public PaymentViewModel GetViewModel
{
get
{
var context = new SchoolDatabase();
return new()
{
Id = Id,
LessonId = LessonId,
Sum = Sum,
Remains = Remains,
DateOfPayment = DateOfPayment
};
}
}
}
}