2023-04-02 16:04:50 +04:00
|
|
|
|
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; }
|
2023-04-04 22:42:28 +04:00
|
|
|
|
public virtual Item Item { get; set; } = new();
|
|
|
|
|
public virtual RepairRequest RepairRequest { get; set; } = new();
|
2023-04-05 23:57:45 +04:00
|
|
|
|
public static ItemForRepair? Create(CarServiceDbContext context, ItemForRepairBindingModel? model)
|
2023-04-02 16:04:50 +04:00
|
|
|
|
{
|
|
|
|
|
if (model == null)
|
|
|
|
|
{
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
return new()
|
|
|
|
|
{
|
|
|
|
|
Id = model.Id,
|
|
|
|
|
Count = model.Count,
|
2023-04-05 23:57:45 +04:00
|
|
|
|
Item = context.Items.First(x => x.Id == model.ItemId),
|
|
|
|
|
RepairRequest = context.RepairRequests.First(x => x.Id == model.RepairRequestId)
|
2023-04-02 16:04:50 +04:00
|
|
|
|
};
|
|
|
|
|
}
|
2023-04-05 23:57:45 +04:00
|
|
|
|
public static ItemForRepair Create(CarServiceDbContext context, ItemForRepairViewModel model)
|
2023-04-02 16:04:50 +04:00
|
|
|
|
{
|
|
|
|
|
return new()
|
|
|
|
|
{
|
|
|
|
|
Id = model.Id,
|
|
|
|
|
Count = model.Count,
|
2023-04-05 23:57:45 +04:00
|
|
|
|
Item = context.Items.First(x => x.Id == model.ItemId),
|
|
|
|
|
RepairRequest = context.RepairRequests.First(x => x.Id == model.RepairRequestId)
|
2023-04-02 16:04:50 +04:00
|
|
|
|
};
|
|
|
|
|
}
|
2023-04-05 23:57:45 +04:00
|
|
|
|
public void Update(CarServiceDbContext context, ItemForRepairBindingModel? model)
|
2023-04-02 16:04:50 +04:00
|
|
|
|
{
|
|
|
|
|
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,
|
2023-04-05 23:57:45 +04:00
|
|
|
|
RepairRequestId = RepairRequestId,
|
|
|
|
|
ItemName = Item.Name
|
2023-04-02 16:04:50 +04:00
|
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
}
|