74 lines
1.6 KiB
C#
74 lines
1.6 KiB
C#
using CarServiceContracts.BindingModels;
|
|
using CarServiceContracts.Models;
|
|
using CarServiceContracts.ViewModels;
|
|
using System.ComponentModel.DataAnnotations;
|
|
using System.ComponentModel.DataAnnotations.Schema;
|
|
|
|
namespace CarServiceDatabase.Models
|
|
{
|
|
public class Item : IItemModel
|
|
{
|
|
public int Id { get; private set; }
|
|
[Required]
|
|
public string Name { get; private set; } = string.Empty;
|
|
[Required, Column(TypeName = "decimal (10,2)")]
|
|
public decimal Price { get; private set; }
|
|
[Required]
|
|
public int Count { get; private set; }
|
|
[Required]
|
|
public int WorkerId { get; private set; }
|
|
/// <summary>
|
|
/// Затраты на ремонт
|
|
/// </summary>
|
|
[ForeignKey("ItemId")]
|
|
public virtual List<ItemForRepair> ItemsForRepair { get; set; } = new();
|
|
public virtual Worker Worker { get; set; } = new();
|
|
public static Item? Create(ItemBindingModel? model)
|
|
{
|
|
if (model == null)
|
|
{
|
|
return null;
|
|
}
|
|
return new()
|
|
{
|
|
Id = model.Id,
|
|
Name = model.Name,
|
|
Price = model.Price,
|
|
Count = model.Count,
|
|
WorkerId = model.WorkerId
|
|
};
|
|
}
|
|
public static Item Create(ItemViewModel model)
|
|
{
|
|
return new()
|
|
{
|
|
Id = model.Id,
|
|
Name = model.Name,
|
|
Price = model.Price,
|
|
Count = model.Count,
|
|
WorkerId = model.WorkerId
|
|
};
|
|
}
|
|
public void Update(ItemBindingModel? model)
|
|
{
|
|
if (model == null)
|
|
{
|
|
return;
|
|
}
|
|
Id = model.Id;
|
|
Name = model.Name;
|
|
Price = model.Price;
|
|
Count = model.Count;
|
|
WorkerId = model.WorkerId;
|
|
}
|
|
public ItemViewModel GetViewModel => new()
|
|
{
|
|
Id = Id,
|
|
Name = Name,
|
|
Price = Price,
|
|
Count = Count,
|
|
WorkerId = WorkerId
|
|
};
|
|
}
|
|
}
|