58 lines
1.7 KiB
C#
58 lines
1.7 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 Competition : ICompetitionModel
|
|
{
|
|
[BsonId]
|
|
[BsonElement("_id")]
|
|
public int Id { get; set; }
|
|
|
|
[BsonRequired]
|
|
public string CompetitionName { get; set; } = string.Empty;
|
|
|
|
[BsonRequired]
|
|
public DateTime CompetitionDateHolding { get; set; }
|
|
[BsonRequired]
|
|
|
|
public string CompetitionCity { get; set; } = string.Empty;
|
|
|
|
public static Competition? Create(CompetitionBindingModel model)
|
|
{
|
|
if (model == null) return null;
|
|
return new Competition()
|
|
{
|
|
Id = model.Id,
|
|
CompetitionName = model.CompetitionName,
|
|
CompetitionDateHolding = model.CompetitionDateHolding,
|
|
CompetitionCity = model.CompetitionCity,
|
|
};
|
|
}
|
|
|
|
public void Update(CompetitionBindingModel model)
|
|
{
|
|
if (model == null) return;
|
|
Id = model.Id;
|
|
CompetitionName = model.CompetitionName;
|
|
CompetitionDateHolding = model.CompetitionDateHolding;
|
|
CompetitionCity = model.CompetitionCity;
|
|
}
|
|
|
|
public CompetitionViewModel GetViewModel => new()
|
|
{
|
|
Id = Id,
|
|
CompetitionName = CompetitionName,
|
|
CompetitionDateHolding = CompetitionDateHolding,
|
|
CompetitionCity = CompetitionCity,
|
|
};
|
|
}
|
|
}
|