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

70 lines
1.8 KiB
C#
Raw Normal View History

using ConstructionCompanyContracts.BindingModels;
using ConstructionCompanyContracts.ViewModels;
using ConstructionCompanyDataModels.Models;
using MongoDB.Bson;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ConstructionCompanyMongoDBImplement.Models
{
public class Material : IMaterialModel
{
public string MaterialName { get; private set; } = string.Empty;
public int Quantity { get; set; }
public int Id { get; private set; }
public static Material? Create(MaterialBindingModel? model)
{
if (model == null)
{
return null;
}
return new Material()
{
Id = model.Id,
MaterialName = model.MaterialName,
Quantity = model.Quantity,
};
}
public static BsonDocument? CreateBSON(MaterialBindingModel? model)
{
if (model == null)
{
return null;
}
return new BsonDocument
{
{"_id", model.Id},
{"materialName", $"{model.MaterialName}"},
{"quantity", $"{model.Quantity}" }
};
}
public static BsonDocument? UpdateBSON(MaterialBindingModel? model)
{
if (model == null)
{
return null;
}
return new BsonDocument
{
{"_id", model.Id},
{"materialName", $"{model.MaterialName}"},
{"quantity", $"{model.Quantity}" }
};
}
public MaterialViewModel GetViewModel => new()
{
Id = Id,
MaterialName = MaterialName,
Quantity = Quantity
};
}
}