using System; using System.Collections.Generic; using System.ComponentModel; using System.Linq; using System.Text; using System.Threading.Tasks; using TravelCompanyContracts.BindingModels; using TravelCompanyContracts.ViewModels; using TravelCompanyDataModels.Models; using System.ComponentModel.DataAnnotations; using System.ComponentModel.DataAnnotations.Schema; namespace TravelCompanyDatabaseImplement.Models { public class Condition : IConditionModel { public int Id { get; private set; } [Required] public string ConditionName { get; private set; } = string.Empty; [Required] public double Cost { get; set; } [ForeignKey("ConditionId")] public virtual List TravelConditions { get; set; } = new(); public static Condition? Create(ConditionBindingModel model) { if (model == null) { return null; } return new Condition() { Id = model.Id, ConditionName = model.ConditionName, Cost = model.Cost }; } public static Condition Create(ConditionViewModel model) { return new Condition { Id = model.Id, ConditionName = model.ConditionName, Cost = model.Cost }; } public void Update(ConditionBindingModel model) { if (model == null) { return; } ConditionName = model.ConditionName; Cost = model.Cost; } public ConditionViewModel GetViewModel => new() { Id = Id, ConditionName = ConditionName, Cost = Cost }; } }