using ConstructionCompanyContracts.BindingModels; using ConstructionCompanyContracts.ViewModels; using ConstructionCompanyDataModels.Models; using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace ConstructionCompanyMongoDBImplement.Models { public class EmployeeOrder : IEmployeeOrderModel { public int EmployeeId { get; set; } public int OrderId { get; set; } public Employee Employee { get; set; } = new(); public Order Order { get; set; } = new(); public static EmployeeOrder? Create(EmployeeOrderBindingModel? model, List employees, List orders) { if (model == null) { return null; } return new EmployeeOrder() { EmployeeId = model.EmployeeId, OrderId = model.OrderId, Employee = employees.First(x => x.Id == model.EmployeeId), Order = orders.First(x => x.Id == model.OrderId), }; } public EmployeeOrderViewModel GetViewModel => new() { OrderId = OrderId, EmployeeId = EmployeeId, OrderAdress = Order.Adress, EmployeeName = Employee.EmployeeName }; } }