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 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 string CreateCommand(MaterialBindingModel? model) { if (model == null) { return ""; } return $"INSERT INTO material(name, quantity) VALUES(\'{model.MaterialName}\', {model.Quantity});"; } public static string UpdateCommand(MaterialBindingModel? model) { if (model == null) { return ""; } return $"UPDATE material SET \"name\" = \'{model.MaterialName}\', quantity = {model.Quantity} WHERE id = {model.Id}"; } public static string DeleteCommand(MaterialBindingModel? model) { if (model == null) { return ""; } return $"DELETE FROM material WHERE id = {model.Id}"; } public void Update(MaterialBindingModel? model) { if (model == null) { return; } MaterialName = model.MaterialName; Quantity = model.Quantity; } public MaterialViewModel GetViewModel => new() { Id = Id, MaterialName = MaterialName, Quantity = Quantity }; } }