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

63 lines
1.5 KiB
C#
Raw Permalink Normal View History

using SchoolContracts.BindingModel;
using SchoolContracts.ViewModels;
using SchoolDataModels.Models;
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 : IPaymentModel
{
public int Id { get; private set; }
[Required]
public int CircleLessonId { get; private set; }
[Required]
public int PaySum { get; private set; }
[Required]
public int Remains { 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,
Remains = model.Remains
};
}
public void Update(PaymentBindingModel? model)
{
if (model == null)
{
return;
}
Id = model.Id;
CircleLessonId = model.CircleLessonId;
PaySum = model.PaySum;
DateOfPayment = model.DateOfPayment;
Remains = model.Remains;
}
public PaymentViewModel GetViewModel => new()
{
Id = Id,
CircleLessonId = CircleLessonId,
PaySum = PaySum,
DateOfPayment = DateOfPayment,
Remains = Remains
};
}
}