ISEbd-21_Melnikov_I.O._CarS.../CarService/CarServiceDatabase/Models/ItemForRepair.cs

61 lines
1.3 KiB
C#
Raw Normal View History

using CarServiceContracts.BindingModels;
using CarServiceContracts.Models;
using CarServiceContracts.ViewModels;
using System.ComponentModel.DataAnnotations;
namespace CarServiceDatabase.Models
{
public class ItemForRepair : IItemForRepairModel
{
public int Id { get; private set; }
[Required]
public int Count { get; private set; }
[Required]
public int ItemId { get; private set; }
[Required]
public int RepairRequestId { get; private set; }
public static ItemForRepair? Create(ItemForRepairBindingModel? model)
{
if (model == null)
{
return null;
}
return new()
{
Id = model.Id,
Count = model.Count,
ItemId = model.ItemId,
RepairRequestId = model.RepairRequestId
};
}
public static ItemForRepair Create(ItemForRepairViewModel model)
{
return new()
{
Id = model.Id,
Count = model.Count,
ItemId = model.ItemId,
RepairRequestId = model.RepairRequestId
};
}
public void Update(ItemForRepairBindingModel? model)
{
if (model == null)
{
return;
}
Id = model.Id;
Count = model.Count;
ItemId = model.ItemId;
RepairRequestId = model.RepairRequestId;
}
public ItemForRepairViewModel GetViewModel => new()
{
Id = Id,
Count = Count,
ItemId = ItemId,
RepairRequestId = RepairRequestId
};
}
}