67 lines
1.9 KiB
C#
67 lines
1.9 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using System.ComponentModel.DataAnnotations;
|
|
using System.Linq;
|
|
using System.Text;
|
|
using System.Threading.Tasks;
|
|
using ZooContracts.BindingModels;
|
|
using ZooContracts.ViewModels;
|
|
using ZooDataModels.Models;
|
|
|
|
namespace ZooDatabaseImplements.Models
|
|
{
|
|
public class Payment : IPaymentModel
|
|
{
|
|
public int Id { get; private set; }
|
|
[Required]
|
|
public int RouteReserveId { get; private set; }
|
|
[Required]
|
|
public double PaySum { get; private set; }
|
|
[Required]
|
|
public DateTime? DateOfPayment { get; private set; } = DateTime.Now;
|
|
public virtual RouteReserve RouteReserve { get; private set; } = new();
|
|
public static Payment? Create(ZooDatabase context, PaymentBindingModel? model)
|
|
{
|
|
if (model == null)
|
|
{
|
|
return null;
|
|
}
|
|
|
|
return new Payment()
|
|
{
|
|
Id = model.Id,
|
|
RouteReserve = context.RouteReserves.First(x => x.Id == model.RouteReserveId),
|
|
PaySum = model.PaySum,
|
|
DateOfPayment = model.DateOfPayment
|
|
};
|
|
}
|
|
public void Update(PaymentBindingModel? model)
|
|
{
|
|
if (model == null)
|
|
{
|
|
return;
|
|
}
|
|
Id = model.Id;
|
|
RouteReserveId = model.RouteReserveId;
|
|
PaySum = model.PaySum;
|
|
DateOfPayment = model.DateOfPayment;
|
|
}
|
|
|
|
|
|
public PaymentViewModel GetViewModel
|
|
{
|
|
get
|
|
{
|
|
var context = new ZooDatabase();
|
|
return new()
|
|
{
|
|
Id = Id,
|
|
RouteReserveId = RouteReserveId,
|
|
PaySum = PaySum,
|
|
DateOfPayment = DateOfPayment
|
|
};
|
|
}
|
|
}
|
|
}
|
|
}
|