46 lines
1.2 KiB
C#
46 lines
1.2 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 RouteCost : IRouteCostModel
|
|||
|
{
|
|||
|
public int Id { get; set; }
|
|||
|
[Required]
|
|||
|
public int CostId { get; set; }
|
|||
|
[Required]
|
|||
|
public int RouteId { get; set; }
|
|||
|
public virtual Cost Cost { get; set; } = new();
|
|||
|
public virtual Route Route { get; set; } = new();
|
|||
|
public static RouteCost? Create(ZooDatabase context, RouteCostBindingModel model)
|
|||
|
{
|
|||
|
if (model == null)
|
|||
|
{
|
|||
|
return null;
|
|||
|
}
|
|||
|
return new()
|
|||
|
{
|
|||
|
Id = model.Id,
|
|||
|
Route = context.Routes.First(x => x.Id == model.RouteId),
|
|||
|
Cost = context.Costs.First(x => x.Id == model.CostId)
|
|||
|
};
|
|||
|
}
|
|||
|
public void Update(RouteCostBindingModel model)
|
|||
|
{
|
|||
|
Id = model.Id;
|
|||
|
}
|
|||
|
|
|||
|
public RouteCostViewModel GetViewModel => new()
|
|||
|
{
|
|||
|
Id = Id
|
|||
|
};
|
|||
|
}
|
|||
|
}
|