52 lines
1.5 KiB
C#
52 lines
1.5 KiB
C#
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 ZooDataModels.Models;
|
|
using ZooContracts.BindingModels;
|
|
using ZooContracts.ViewModels;
|
|
|
|
namespace ZooDatabaseImplements.Models
|
|
{
|
|
public class Route : IRouteModel
|
|
{
|
|
public int Id { get; private set; }
|
|
[Required]
|
|
public DateTime DateStart { get; private set; } = DateTime.Now;
|
|
[Required]
|
|
public int ClientId { get; private set; }
|
|
public virtual Client Client { get; private set; } = new();
|
|
[ForeignKey("RouteId")]
|
|
public virtual RouteReserve RouteReserves { get; set; } = new();
|
|
[ForeignKey("RouteId")]
|
|
public virtual List<RouteCost> RouteCosts { get; set; } = new();
|
|
public static Route Create(ZooDatabase context, RouteBindingModel model)
|
|
{
|
|
return new Route()
|
|
{
|
|
Id = model.Id,
|
|
DateStart = model.DateStart,
|
|
Client = context.Clients.First(x => x.Id == model.ClientId)
|
|
};
|
|
}
|
|
|
|
public void Update(RouteBindingModel model)
|
|
{
|
|
Id = model.Id;
|
|
DateStart = model.DateStart;
|
|
ClientId = model.ClientId;
|
|
}
|
|
|
|
public RouteViewModel GetViewModel => new()
|
|
{
|
|
Id = Id,
|
|
DateStart = DateStart,
|
|
ClientId = ClientId,
|
|
ClientName = Client.ClientName
|
|
};
|
|
}
|
|
}
|