PIbd-23_Abazov_A.A._Constru.../ConstructionCompany/ConstructionCompanyPsqlImplement/Models/Position.cs

75 lines
2.1 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 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 PositionViewModel GetViewModel => new()
{
Id = Id,
PositionName = PositionName,
Salary = Salary
};
}
}