SUBD_SportCompetitions/SportCompetitionsDatabaseImplement/Models/Record.cs

63 lines
1.5 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 Record : IRecordModel
{
public int Id { get; set; }
[Required]
public string RecordName { get; set; }
[Required]
public string RecordDecriptiption { get; set; }
[Required]
public int MemberId { get; set; }
[Required]
public DateTime RecordDate { get; set; }
[Required]
public int RecordValue { get; set; }
public static Record? Create(RecordBindingModel model)
{
if (model == null) return null;
return new Record()
{
Id = model.Id,
RecordName = model.RecordName,
RecordDecriptiption = model.RecordDecriptiption,
MemberId = model.MemberId,
RecordDate = model.RecordDate,
RecordValue = model.RecordValue
};
}
public void Update(RecordBindingModel model)
{
if (model == null) return;
Id = model.Id;
RecordName = model.RecordName;
RecordDecriptiption = model.RecordDecriptiption;
MemberId = model.MemberId;
RecordDate = model.RecordDate;
RecordValue = model.RecordValue;
}
public RecordViewModel GetViewModel => new()
{
Id = Id,
RecordName = RecordName,
RecordDecriptiption= RecordDecriptiption,
MemberId = MemberId,
RecordDate = RecordDate,
RecordValue = RecordValue
};
}
}