PIbd-23_Nevaeva_K.A._Travel.../TravelCompany/TravelCompanyDatabaseImplement/Models/Condition.cs
2023-03-20 08:43:09 +04:00

66 lines
1.8 KiB
C#

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<TravelCondition> 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
};
}
}