PIbd-23_Abazov_A.A._Constru.../ConstructionCompany/ConstructionCompanyMongoDBImplement/Models/Employee.cs

72 lines
2.0 KiB
C#
Raw Normal View History

using ConstructionCompanyContracts.BindingModels;
using ConstructionCompanyContracts.ViewModels;
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();
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}"},
{"positionId", model.PositionID}
};
}
public static BsonDocument? UpdateBSON(EmployeeBindingModel? model)
{
if (model == null)
{
return null;
}
return new BsonDocument
{
{"_id", model.Id},
{"EmployeeName", $"{model.EmployeeName}"},
{"positionId", model.PositionID}
};
}
public EmployeeViewModel GetViewModel => new()
{
Id = Id,
EmployeeName = EmployeeName,
PositionID = PositionID,
PositionName = Position.PositionName
};
2023-04-24 13:36:40 +04:00
}
}