PIbd-21_Medvedkov_Coursach/ComputerShopDatabaseImplement/Models/Request.cs

59 lines
1.3 KiB
C#
Raw Normal View History

2024-05-01 04:42:57 +04:00
using ComputerShopContracts.BindingModels;
using ComputerShopContracts.ViewModels;
using ComputerShopDataModels.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 ComputerShopDatabaseImplement.Models
{
public class Request : IRequestModel
{
public int Id { get; set; }
public int? AssemblyId { get; set; }
public virtual Assembly? Assembly { get; set; } = new();
[Required]
public DateTime DateRequest { get; set; }
public static Request Create(ComputerShopDatabase context, RequestBindingModel model)
{
return new Request() {
Id = model.Id,
AssemblyId = model.AssemblyId,
Assembly = model.AssemblyId.HasValue ? context.Assemblies.First(x => x.Id == model.AssemblyId) : null,
DateRequest = model.DateRequest,
};
}
public void Update(RequestBindingModel model)
{
if (model == null) {
return;
}
}
public RequestViewModel GetViewModel => new()
{
Id = Id,
AssemblyId = AssemblyId,
Assembly = Assembly,
DateRequest = DateRequest,
};
public void ConnectAssembly(ComputerShopDatabase context, int assemblyId)
{
AssemblyId = assemblyId;
Assembly = context.Assemblies.First(x => x.Id == assemblyId);
}
}
}