SUBD_Gerimovich_Ilya_PIbd-22/FurnitureAssembly/FurnitureAssemblyDatabaseImplement/Models/Komment.cs
platoff aeeee 2cefd91025 12
2024-05-24 13:05:47 +04:00

71 lines
1.8 KiB
C#

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 Komment : IKommentModel
{
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<UsersKomment> FurnitureWorkPieces { get; set; } = new();
public static Komment? Create(KommentBindingModel model)
{
if (model == null)
{
return null;
}
return new Komment()
{
Id = model.Id,
WorkPieceName = model.WorkPieceName,
Cost = model.Cost
};
}
public static Komment Create(KommentViewModel model)
{
return new Komment
{
Id = model.Id,
WorkPieceName = model.WorkPieceName,
Cost = model.Cost
};
}
public void Update(KommentBindingModel model)
{
if (model == null)
{
return;
}
WorkPieceName = model.WorkPieceName;
Cost = model.Cost;
}
public KommentViewModel GetViewModel => new()
{
Id = Id,
WorkPieceName = WorkPieceName,
Cost = Cost
};
}
}