SUBD_SportCompetitions/SportCompetitionsDatabaseImplement/Models/Competition.cs

52 lines
1.4 KiB
C#

using SportCompetitionsContracts.BindingModels;
using SportCompetitionsContracts.ViewModels;
using SportCompetitionsDataModels.Models;
using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace SportCompetitionsDatabaseImplement.Models
{
public class Competition : ICompetitionModel
{
public int Id { get; set; }
[Required]
public string? CompetitionName { get; set; }
[Required]
public DateTime CompetitionDateHolding { get; set; }
[Required]
public string? CompetitionCity { get; set; }
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;
CompetitionName = model.CompetitionName;
CompetitionDateHolding = model.CompetitionDateHolding;
CompetitionCity = model.CompetitionCity;
}
public CompetitionViewModel GetViewModel => new()
{
Id = Id,
CompetitionName = CompetitionName,
CompetitionDateHolding = CompetitionDateHolding,
CompetitionCity = CompetitionCity,
};
}
}