PIbd-22_Gerimovich.I.M._Fur.../FurnitureAssembly/FurnitureAssemblyDatabaseImplement/Models/WorkPiece.cs

72 lines
1.9 KiB
C#
Raw Normal View History

2024-03-27 11:02:14 +04:00
using FurnitureAssemblyContracts.BindingModels;
using FurnitureAssemblyContracts.ViewModels;
using FurnitureAssemblyDataModels.Models;
using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using System.ComponentModel.DataAnnotations.Schema;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace FurnitureAssemblyDatabaseImplement.Models
{
public class WorkPiece : IWorkPieceModel
{
public int Id { get; private set; }
[Required]
public string WorkPieceName { get; private set; } = string.Empty;
[Required]
public double Cost { get; set; }
2024-06-21 14:50:51 +04:00
// для реализации связи многие ко многим с изделиями
2024-03-27 11:02:14 +04:00
[ForeignKey("WorkPieceId")]
public virtual List<FurnitureWorkPiece> FurnitureWorkPieces { get; set; } = new();
public static WorkPiece? Create(WorkPieceBindingModel model)
{
2024-06-21 14:50:51 +04:00
if(model == null)
2024-03-27 11:02:14 +04:00
{
return null;
}
return new WorkPiece()
{
Id = model.Id,
WorkPieceName = model.WorkPieceName,
Cost = model.Cost
};
}
public static WorkPiece Create(WorkPieceViewModel model)
{
return new WorkPiece
{
Id = model.Id,
WorkPieceName = model.WorkPieceName,
Cost = model.Cost
};
}
public void Update(WorkPieceBindingModel model)
{
2024-06-21 14:50:51 +04:00
if(model == null)
2024-03-27 11:02:14 +04:00
{
return;
}
WorkPieceName = model.WorkPieceName;
Cost = model.Cost;
}
public WorkPieceViewModel GetViewModel => new()
{
Id = Id,
WorkPieceName = WorkPieceName,
Cost = Cost
};
}
}