using ConstructionCompanyContracts.BindingModels; using ConstructionCompanyContracts.ViewModels; 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 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 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 }; } }