80 lines
2.1 KiB
C#
80 lines
2.1 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;
|
|
using Azure.Core;
|
|
using ComputerStoreContracts.SearchModels;
|
|
using Microsoft.EntityFrameworkCore;
|
|
using System.Xml.Linq;
|
|
|
|
namespace ComputerStoreDatabaseImplement.Models
|
|
{
|
|
public class Request : IRequestModel
|
|
{
|
|
public int ID { get; private set; }
|
|
|
|
[Required]
|
|
public int OrderID { get; private set; }
|
|
public virtual Order Order { get; set; }
|
|
|
|
public int? PCID { get; private set; }
|
|
|
|
[Required]
|
|
public double Price { get; private set; }
|
|
|
|
[ForeignKey("RequestID")]
|
|
public virtual List<RequestComponent> PCs { get; set; } = new();
|
|
|
|
public static Request? Create(ComputerStoreDatabase context, 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;
|
|
}
|
|
Price = model.Price;
|
|
PCID = model.PCID;
|
|
}
|
|
|
|
public void UpdatePCID(ComputerStoreDatabase context)
|
|
{
|
|
PCID = context.RequestComponents.First(x => x.RequestID == ID).PCID;
|
|
}
|
|
|
|
public RequestViewModel GetViewModel
|
|
{
|
|
get
|
|
{
|
|
var context = new ComputerStoreDatabase();
|
|
return new RequestViewModel()
|
|
{
|
|
ID = ID,
|
|
OrderID = OrderID,
|
|
Price = Price,
|
|
PCID = PCID,
|
|
PCName = context.PCs.First(rec => rec.ID == PCID).Name
|
|
};
|
|
}
|
|
}
|
|
}
|
|
}
|