2023-04-24 13:36:40 +04:00
|
|
|
|
using ConstructionCompanyContracts.BindingModels;
|
2023-05-09 13:13:47 +04:00
|
|
|
|
using ConstructionCompanyContracts.ViewModels;
|
2023-04-24 13:36:40 +04:00
|
|
|
|
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 Position : IPositionModel
|
|
|
|
|
{
|
|
|
|
|
public string PositionName { get; private set; } = string.Empty;
|
|
|
|
|
|
|
|
|
|
public double Salary { get; set; }
|
|
|
|
|
|
|
|
|
|
public int Id { get; private set; }
|
|
|
|
|
public List<int> Employees { get; private set; } = new List<int>();
|
|
|
|
|
|
|
|
|
|
public static Position? Create(PositionBindingModel? model)
|
|
|
|
|
{
|
|
|
|
|
if (model == null)
|
|
|
|
|
{
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
return new Position()
|
|
|
|
|
{
|
|
|
|
|
Id = model.Id,
|
|
|
|
|
PositionName = model.PositionName,
|
|
|
|
|
Salary = model.Salary
|
|
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public static BsonDocument? CreateBSON(PositionBindingModel? model)
|
|
|
|
|
{
|
|
|
|
|
if (model == null)
|
|
|
|
|
{
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
return new BsonDocument
|
|
|
|
|
{
|
2023-05-09 13:13:47 +04:00
|
|
|
|
{"_id", model.Id},
|
2023-04-24 13:36:40 +04:00
|
|
|
|
{"PositionName", $"{model.PositionName}"},
|
|
|
|
|
{"Salary", $"{model.Salary}" },
|
|
|
|
|
{"EmployeesId", new BsonArray{}}
|
|
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
|
2023-05-09 22:06:53 +04:00
|
|
|
|
public static BsonDocument? UpdateBSON(PositionBindingModel? model, List<int> ids)
|
2023-04-24 13:36:40 +04:00
|
|
|
|
{
|
|
|
|
|
if (model == null)
|
|
|
|
|
{
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
return new BsonDocument
|
|
|
|
|
{
|
2023-05-09 13:13:47 +04:00
|
|
|
|
{"_id", model.Id},
|
2023-04-24 13:36:40 +04:00
|
|
|
|
{"PositionName", $"{model.PositionName}"},
|
|
|
|
|
{"Salary", $"{model.Salary}" },
|
|
|
|
|
{"EmployeesId", new BsonArray(ids)}
|
|
|
|
|
};
|
|
|
|
|
}
|
2023-05-09 13:13:47 +04:00
|
|
|
|
public PositionViewModel GetViewModel => new()
|
|
|
|
|
{
|
|
|
|
|
Id = Id,
|
|
|
|
|
PositionName = PositionName,
|
|
|
|
|
Salary = Salary
|
|
|
|
|
};
|
2023-04-24 13:36:40 +04:00
|
|
|
|
}
|
|
|
|
|
}
|