PIbd-23_Abazov_A.A._Constru.../ConstructionCompany/ConstructionCompanyMongoDBImplement/Models/EmployeeOrder.cs

41 lines
1.3 KiB
C#
Raw Normal View History

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<Employee> employees, List<Order> 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
};
}
}