44 lines
1.4 KiB
C#
44 lines
1.4 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 ConstructionCompanyMongoDBImplement.Models
|
|
{
|
|
public class MaterialOrder : IMaterialOrderModel
|
|
{
|
|
public int MaterialId { get; set; }
|
|
public int OrderId { get; set; }
|
|
public int Quantity { get; set; }
|
|
public Material Material { get; set; } = new();
|
|
public Order Order { get; set; } = new();
|
|
public static MaterialOrder? Create(MaterialOrderBindingModel? model, List<Material> materials, List<Order> orders)
|
|
{
|
|
if (model == null)
|
|
{
|
|
return null;
|
|
}
|
|
return new MaterialOrder()
|
|
{
|
|
MaterialId = model.MaterialId,
|
|
OrderId = model.OrderId,
|
|
Quantity = model.Quantity,
|
|
Material = materials.First(x => x.Id == model.MaterialId),
|
|
Order = orders.First(x => x.Id == model.OrderId),
|
|
};
|
|
}
|
|
public MaterialOrderViewModel GetViewModel => new()
|
|
{
|
|
OrderId = OrderId,
|
|
MaterialId = MaterialId,
|
|
Quantity = Quantity,
|
|
OrderAdress = Order.Adress,
|
|
MaterialName = Material.MaterialName
|
|
};
|
|
}
|
|
}
|