2023-05-09 13:13:47 +04:00
|
|
|
|
using ConstructionCompanyContracts.BindingModels;
|
2023-05-09 22:06:53 +04:00
|
|
|
|
using ConstructionCompanyContracts.ViewModels;
|
2023-05-09 13:13:47 +04:00
|
|
|
|
using ConstructionCompanyDataModels.Models;
|
|
|
|
|
using MongoDB.Bson;
|
2023-04-24 13:36:40 +04:00
|
|
|
|
using System;
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using System.Linq;
|
|
|
|
|
using System.Text;
|
|
|
|
|
using System.Threading.Tasks;
|
|
|
|
|
|
|
|
|
|
namespace ConstructionCompanyMongoDBImplement.Models
|
|
|
|
|
{
|
|
|
|
|
public class Employee : IEmployeeModel
|
|
|
|
|
{
|
|
|
|
|
public string EmployeeName { get; private set; } = string.Empty;
|
|
|
|
|
|
|
|
|
|
public int Id { get; private set; }
|
|
|
|
|
public int PositionID { get; private set; }
|
|
|
|
|
public Position Position { get; set; } = new();
|
2023-05-09 13:13:47 +04:00
|
|
|
|
|
|
|
|
|
public static Employee? Create(EmployeeBindingModel? model, List<Position> positions)
|
|
|
|
|
{
|
|
|
|
|
if (model == null)
|
|
|
|
|
{
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
return new Employee()
|
|
|
|
|
{
|
|
|
|
|
Id = model.Id,
|
|
|
|
|
EmployeeName = model.EmployeeName,
|
|
|
|
|
PositionID = model.PositionID,
|
|
|
|
|
Position = positions.First(x => x.Id == model.PositionID)
|
|
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public static BsonDocument? CreateBSON(EmployeeBindingModel? model)
|
|
|
|
|
{
|
|
|
|
|
if (model == null)
|
|
|
|
|
{
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
return new BsonDocument
|
|
|
|
|
{
|
|
|
|
|
{"_id", model.Id},
|
|
|
|
|
{"EmployeeName", $"{model.EmployeeName}"},
|
2023-05-11 12:11:29 +04:00
|
|
|
|
{"positionId", model.PositionID}
|
2023-05-09 13:13:47 +04:00
|
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public static BsonDocument? UpdateBSON(EmployeeBindingModel? model)
|
|
|
|
|
{
|
|
|
|
|
if (model == null)
|
|
|
|
|
{
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
return new BsonDocument
|
|
|
|
|
{
|
|
|
|
|
{"_id", model.Id},
|
|
|
|
|
{"EmployeeName", $"{model.EmployeeName}"},
|
2023-05-11 12:11:29 +04:00
|
|
|
|
{"positionId", model.PositionID}
|
2023-05-09 13:13:47 +04:00
|
|
|
|
};
|
|
|
|
|
}
|
2023-05-09 22:06:53 +04:00
|
|
|
|
public EmployeeViewModel GetViewModel => new()
|
|
|
|
|
{
|
|
|
|
|
Id = Id,
|
|
|
|
|
EmployeeName = EmployeeName,
|
|
|
|
|
PositionID = PositionID,
|
|
|
|
|
PositionName = Position.PositionName
|
|
|
|
|
};
|
2023-04-24 13:36:40 +04:00
|
|
|
|
}
|
|
|
|
|
}
|