72 lines
2.1 KiB
C#
72 lines
2.1 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 Record : IRecordModel
|
|
{
|
|
[BsonId]
|
|
[BsonElement("_id")]
|
|
public int Id { get; set; }
|
|
|
|
[BsonRequired]
|
|
public string RecordName { get; set; } = string.Empty;
|
|
[BsonRequired]
|
|
public string RecordDecriptiption { get; set; } = string.Empty;
|
|
|
|
[BsonRequired]
|
|
public DateTime RecordDate { get; set; }
|
|
[BsonRequired]
|
|
public int RecordValue { get; set; }
|
|
|
|
[BsonRequired]
|
|
[BsonElement("member_id")]
|
|
public int MemberId { get; set; }
|
|
[BsonIgnoreIfNull]
|
|
[BsonIgnoreIfDefault]
|
|
public virtual Member Member { get; set; }
|
|
|
|
public static Record? Create(RecordBindingModel model)
|
|
{
|
|
if (model == null) return null;
|
|
return new Record()
|
|
{
|
|
Id = model.Id,
|
|
RecordName = model.RecordName,
|
|
RecordDate = model.RecordDate,
|
|
RecordDecriptiption = model.RecordDecriptiption,
|
|
MemberId = model.MemberId,
|
|
RecordValue = model.RecordValue,
|
|
};
|
|
}
|
|
|
|
public void Update(RecordBindingModel model)
|
|
{
|
|
if (model == null) return;
|
|
Id = model.Id;
|
|
RecordName = model.RecordName;
|
|
RecordDate = model.RecordDate;
|
|
RecordDecriptiption = model.RecordDecriptiption;
|
|
MemberId = model.MemberId;
|
|
RecordValue = model.RecordValue;
|
|
}
|
|
|
|
public RecordViewModel GetViewModel => new()
|
|
{
|
|
Id = Id,
|
|
RecordName = RecordName,
|
|
RecordDate = RecordDate,
|
|
RecordDecriptiption =RecordDecriptiption,
|
|
MemberId = MemberId,
|
|
RecordValue = RecordValue,
|
|
};
|
|
}
|
|
}
|