ISEbd-21_Haliullov_K.A._Jur.../JurassicZoo/ZooDatabaseImplements/Models/RouteReserve.cs

48 lines
1.4 KiB
C#
Raw Normal View History

2023-04-09 01:27:52 +04:00
using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations.Schema;
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 RouteReserve : IRouteReserveModel
{
public int Id { get; set; }
[Required]
public int RouteId { get; set; }
[Required]
public int ReserveId { get; set; }
[Required]
public int Count { get; set; }
public virtual Reserve Reserve { get; set; } = new();
public virtual Route Route { get; set; } = new();
[ForeignKey("RouteReserveId")]
public virtual List<Payment> Payments { get; set; } = new();
public static RouteReserve Create(ZooDatabase context, RouteReserveBindingModel model)
{
return new RouteReserve()
{
Id = model.Id,
Route = context.Routes.First(x => x.Id == model.RouteId),
Reserve = context.Reserves.First(x => x.Id == model.ReserveId)
};
}
public void Update(RouteReserveBindingModel model)
{
Id = model.Id;
}
public RouteReserveViewModel GetViewModel => new()
{
Id = Id
};
}
}