62 lines
1.7 KiB
C#
62 lines
1.7 KiB
C#
using CarCenterDataModels.Models;
|
|
using System;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using System.Text;
|
|
using System.Threading.Tasks;
|
|
using System.ComponentModel.DataAnnotations;
|
|
using System.ComponentModel.DataAnnotations.Schema;
|
|
using CarCenterContracts.BindingModels;
|
|
using CarCenterContracts.ViewModels;
|
|
|
|
namespace CarCenterDatabaseImplement.Models
|
|
{
|
|
public class Configuration : IConfigurationModel
|
|
{
|
|
public int Id { get; set; }
|
|
[Required]
|
|
public string Name { get; set; }
|
|
public int BossId { get; set; }
|
|
public virtual Boss Boss { get; set; } = new();
|
|
public static Configuration? Create(CarCenterDatabase context, ConfigurationBindingModel model)
|
|
{
|
|
if (model == null)
|
|
{
|
|
return null;
|
|
}
|
|
return new Configuration()
|
|
{
|
|
Id = model.Id,
|
|
Name = model.Name,
|
|
BossId = model.BossId,
|
|
Boss = context.Bosses.First(x => x.Id == model.BossId),
|
|
};
|
|
|
|
}
|
|
public static Configuration? Create(CarCenterDatabase context, ConfigurationViewModel model)
|
|
{
|
|
return new Configuration()
|
|
{
|
|
Id = model.Id,
|
|
Name = model.Name,
|
|
BossId = model.BossId,
|
|
Boss = context.Bosses.First(x => x.Id == model.BossId),
|
|
};
|
|
}
|
|
|
|
public void Update(ConfigurationBindingModel? model)
|
|
{
|
|
if (model == null)
|
|
{
|
|
return;
|
|
}
|
|
Name = model.Name;
|
|
}
|
|
public ConfigurationViewModel GetViewModel => new()
|
|
{
|
|
Id = Id,
|
|
Name = Name,
|
|
};
|
|
}
|
|
}
|