71 lines
2.0 KiB
C#
71 lines
2.0 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 Result : IResultModel
|
|
{
|
|
[BsonId]
|
|
[BsonElement("_id")]
|
|
public int Id { get; set; }
|
|
|
|
[BsonRequired]
|
|
public string ResultName { get; set; } = string.Empty;
|
|
|
|
|
|
[BsonRequired]
|
|
public int ResultPosition { get; set; }
|
|
[BsonRequired]
|
|
[BsonElement("team_id")]
|
|
public int TeamId { get; set; }
|
|
[BsonRequired]
|
|
[BsonElement("competition_id")]
|
|
public int CompetitionId { get; set; }
|
|
[BsonIgnoreIfNull]
|
|
[BsonIgnoreIfDefault]
|
|
public virtual Team Team { get; set; }
|
|
[BsonIgnoreIfNull]
|
|
[BsonIgnoreIfDefault]
|
|
public virtual Competition Competition { get; set; }
|
|
|
|
public static Result? Create(ResultBindingModel model)
|
|
{
|
|
if (model == null) return null;
|
|
return new Result()
|
|
{
|
|
Id = model.Id,
|
|
ResultName = model.ResultName,
|
|
CompetitionId = model.CompetitionId,
|
|
TeamId = model.TeamId,
|
|
ResultPosition = model.ResultPosition,
|
|
};
|
|
}
|
|
|
|
public void Update(ResultBindingModel model)
|
|
{
|
|
if (model == null) return;
|
|
Id = model.Id;
|
|
ResultName = model.ResultName;
|
|
CompetitionId = model.CompetitionId;
|
|
TeamId = model.TeamId;
|
|
ResultPosition = model.ResultPosition;
|
|
}
|
|
|
|
public ResultViewModel GetViewModel => new()
|
|
{
|
|
Id = Id,
|
|
ResultName = ResultName,
|
|
CompetitionId = CompetitionId,
|
|
TeamId = TeamId,
|
|
ResultPosition = ResultPosition,
|
|
};
|
|
}
|
|
}
|