Coursework_ComputerStore_Li.../ComputerStoreDatabaseImplement/Models/Request.cs
2023-04-07 20:46:13 +04:00

59 lines
1.5 KiB
C#

using ComputerStoreContracts.BindingModels;
using ComputerStoreContracts.ViewModels;
using ComputerStoreDataModels.Models;
using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations.Schema;
using System.ComponentModel.DataAnnotations;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ComputerStoreDatabaseImplement.Models
{
public class Request : IRequestModel
{
public int ID { get; private set; }
[Required]
public int OrderID { get; private set; }
[Required]
public double Price { get; private set; }
[ForeignKey("RequestID")]
public virtual List<RequestComponent> RequestComponents { get; private set; } = new();
public static Request? Create(RequestBindingModel model)
{
if (model == null)
{
return null;
}
return new Request()
{
ID = model.ID,
OrderID = model.OrderID,
Price = model.Price
};
}
public void Update(RequestBindingModel? model)
{
if (model == null)
{
return;
}
OrderID = model.OrderID;
Price = model.Price;
}
public RequestViewModel GetViewModel => new()
{
ID = ID,
OrderID = OrderID,
Price = Price
};
}
}