SUBD_Gerimovich_Ilya_PIbd-22/FurnitureAssembly/FurnitureAssemblyDatabaseImplement/Models/Komment.cs

71 lines
1.8 KiB
C#
Raw Normal View History

2024-05-24 12:23:50 +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
{
2024-05-24 13:05:47 +04:00
public class Komment : IKommentModel
2024-05-24 12:23:50 +04:00
{
public int Id { get; private set; }
[Required]
public string WorkPieceName { get; private set; } = string.Empty;
[Required]
public double Cost { get; set; }
[ForeignKey("WorkPieceId")]
2024-05-24 13:05:47 +04:00
public virtual List<UsersKomment> FurnitureWorkPieces { get; set; } = new();
2024-05-24 12:23:50 +04:00
2024-05-24 13:05:47 +04:00
public static Komment? Create(KommentBindingModel model)
2024-05-24 12:23:50 +04:00
{
if (model == null)
{
return null;
}
2024-05-24 13:05:47 +04:00
return new Komment()
2024-05-24 12:23:50 +04:00
{
Id = model.Id,
WorkPieceName = model.WorkPieceName,
Cost = model.Cost
};
}
2024-05-24 13:05:47 +04:00
public static Komment Create(KommentViewModel model)
2024-05-24 12:23:50 +04:00
{
2024-05-24 13:05:47 +04:00
return new Komment
2024-05-24 12:23:50 +04:00
{
Id = model.Id,
WorkPieceName = model.WorkPieceName,
Cost = model.Cost
};
}
2024-05-24 13:05:47 +04:00
public void Update(KommentBindingModel model)
2024-05-24 12:23:50 +04:00
{
if (model == null)
{
return;
}
WorkPieceName = model.WorkPieceName;
Cost = model.Cost;
}
2024-05-24 13:05:47 +04:00
public KommentViewModel GetViewModel => new()
2024-05-24 12:23:50 +04:00
{
Id = Id,
WorkPieceName = WorkPieceName,
Cost = Cost
};
}
}