2023-04-09 17:23:33 +04:00
|
|
|
|
using ConstructionCompanyContracts.BindingModels;
|
|
|
|
|
using ConstructionCompanyContracts.ViewModels;
|
|
|
|
|
using ConstructionCompanyDataModels.Models;
|
2023-05-11 13:03:42 +04:00
|
|
|
|
using MongoDB.Bson;
|
2023-04-09 17:23:33 +04:00
|
|
|
|
using System;
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using System.Linq;
|
|
|
|
|
using System.Text;
|
|
|
|
|
using System.Threading.Tasks;
|
|
|
|
|
|
|
|
|
|
namespace ConstructionCompanyPsqlImplement.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 static string CreateCommand(MaterialOrderBindingModel? model)
|
|
|
|
|
{
|
|
|
|
|
if (model == null)
|
|
|
|
|
{
|
|
|
|
|
return "";
|
|
|
|
|
}
|
2023-04-10 13:02:23 +04:00
|
|
|
|
return $"INSERT INTO material_order(material_id, order_id, quantiny) VALUES({model.MaterialId}, {model.OrderId}, {model.Quantity});";
|
2023-04-09 17:23:33 +04:00
|
|
|
|
}
|
|
|
|
|
public static string DeleteCommand(MaterialOrderBindingModel? model)
|
|
|
|
|
{
|
|
|
|
|
if (model == null)
|
|
|
|
|
{
|
|
|
|
|
return "";
|
|
|
|
|
}
|
|
|
|
|
return $"DELETE FROM material WHERE material_id = {model.MaterialId} AND order_id = {model.OrderId}";
|
|
|
|
|
}
|
2023-05-11 13:03:42 +04:00
|
|
|
|
|
|
|
|
|
public BsonDocument CreateBSON =>
|
|
|
|
|
new BsonDocument
|
|
|
|
|
{
|
|
|
|
|
{"materialId", MaterialId - 1 },
|
|
|
|
|
{"quantity", Quantity }
|
|
|
|
|
};
|
2023-04-09 17:23:33 +04:00
|
|
|
|
public MaterialOrderViewModel GetViewModel => new()
|
|
|
|
|
{
|
|
|
|
|
OrderId = OrderId,
|
|
|
|
|
MaterialId = MaterialId,
|
|
|
|
|
Quantity = Quantity,
|
|
|
|
|
OrderAdress = Order.Adress,
|
|
|
|
|
MaterialName = Material.MaterialName
|
|
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
}
|