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 Position : IPositionModel { public string PositionName { get; private set; } = string.Empty; public double Salary { get; set; } public int Id { get; private set; } public static Position? Create(PositionBindingModel? model) { if (model == null) { return null; } return new Position() { Id = model.Id, PositionName = model.PositionName, Salary = model.Salary }; } public void Update(PositionBindingModel? model) { if (model == null) { return; } PositionName = model.PositionName; Salary = model.Salary; } public static string CreateCommand(PositionBindingModel? model) { if (model == null) { return ""; } return $"INSERT INTO position(name, salary) VALUES(\'{model.PositionName}\', {model.Salary});"; } public static string UpdateCommand(PositionBindingModel? model) { if (model == null) { return ""; } return $"UPDATE position SET \"name\" = \'{model.PositionName}\', salary = {model.Salary} WHERE id = {model.Id}"; } public static string DeleteCommand(PositionBindingModel? model) { if (model == null) { return ""; } return $"DELETE FROM postition WHERE id = {model.Id}"; } public static string PositionsAVGCommnad(DateTime dateFrom, DateTime dateTo) { return $"SELECT \"position\".id, AVG(material_order.quantiny) FROM \"position\"\r\nJOIN employee ON employee.position_id = \"position\".id\r\nJOIN employee_order ON employee_order.employee_id = employee.id\r\nJOIN \"order\" ON \"order\".id = employee_order.order_id\r\nJOIN material_order ON material_order.order_id = \"order\".id\r\nJOIN material ON material.id = material_order.material_id\r\nWHERE \"order\".date_begin >= '{dateFrom}' AND \"order\".date_begin <= '{dateTo}'\r\nGROUP BY \"position\".id"; } public PositionViewModel GetViewModel => new() { Id = Id, PositionName = PositionName, Salary = Salary }; } }