ISEbd-21_Zinovev_V.V._Furni.../FurnitureAssembly/FurnitureAssemblyDatabaseImplement/Models/Workpiece.cs
2024-05-04 20:14:41 +04:00

72 lines
1.9 KiB
C#
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

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; }
// для реализации связи многие ко многим с изделиями
[ForeignKey("WorkpieceId")]
public virtual List<FurnitureWorkpiece> FurnitureWorkpieces { get; set; } = new();
public static Workpiece? Create(WorkpieceBindingModel model)
{
if (model == null)
{
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)
{
if (model == null)
{
return;
}
WorkpieceName = model.WorkpieceName;
Cost = model.Cost;
}
public WorkpieceViewModel GetViewModel => new()
{
Id = Id,
WorkpieceName = WorkpieceName,
Cost = Cost
};
}
}