57 lines
1.9 KiB
C#
57 lines
1.9 KiB
C#
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 ConstructionCompanyPsqlImplement.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 static string CreateCommand(EmployeeOrderBindingModel? model)
|
|
{
|
|
if (model == null)
|
|
{
|
|
return "";
|
|
}
|
|
return $"INSERT INTO employee_order(employee_id, order_id) VALUES({model.EmployeeId}, {model.OrderId});";
|
|
}
|
|
public static string DeleteCommand(EmployeeOrderBindingModel? model)
|
|
{
|
|
if (model == null)
|
|
{
|
|
return "";
|
|
}
|
|
return $"DELETE FROM material WHERE employee_id = {model.EmployeeId} AND order_id = {model.OrderId}";
|
|
}
|
|
public EmployeeOrderViewModel GetViewModel => new()
|
|
{
|
|
OrderId = OrderId,
|
|
EmployeeId = EmployeeId,
|
|
OrderAdress = Order.Adress,
|
|
EmployeeName = Employee.EmployeeName
|
|
};
|
|
}
|
|
}
|