SUBD_SportCompetitions/SportCompetitionsMongo/Models/Member.cs

67 lines
1.9 KiB
C#

using MongoDB.Bson.Serialization.Attributes;
using SportCompetitionsContracts.BindingModels;
using SportCompetitionsContracts.ViewModels;
using SportCompetitionsDataModels.Models;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace SportCompetitionsMongo.Models
{
public class Member : IMemberModel
{
[BsonId]
[BsonElement("_id")]
public int Id { get; set; }
[BsonRequired]
public string MemberFCs { get; set; } = string.Empty;
[BsonRequired]
public DateTime MemberBirthDate { get; set; }
[BsonRequired]
public string MemberGender { get; set; } = string.Empty;
[BsonRequired]
[BsonElement("team_id")]
public int TeamId { get; set; }
[BsonIgnoreIfNull]
[BsonIgnoreIfDefault]
public virtual Team Team { get; set; }
public static Member? Create(MemberBindingModel model)
{
if (model == null) return null;
return new Member()
{
Id = model.Id,
MemberFCs = model.MemberFCs,
MemberBirthDate = model.MemberBirthDate,
MemberGender = model.MemberGender,
TeamId = model.TeamId,
};
}
public void Update(MemberBindingModel model)
{
if (model == null) return;
Id = model.Id;
MemberFCs = model.MemberFCs;
MemberBirthDate = model.MemberBirthDate;
MemberGender = model.MemberGender;
TeamId = model.TeamId;
}
public MemberViewModel GetViewModel => new()
{
Id = Id,
MemberFCs = MemberFCs,
MemberBirthDate = MemberBirthDate,
MemberGender = MemberGender,
TeamId = TeamId,
};
}
}