CourseWork_KPO/CandidateReviewDatabaseImplement/Models/Criterion.cs

72 lines
2.0 KiB
C#
Raw Permalink Normal View History

2024-11-04 22:26:40 +04:00
using CandidateReviewContracts.BindingModels;
using CandidateReviewContracts.ViewModels;
using CandidateReviewDataModels.Enums;
using CandidateReviewDataModels.Models;
using System.ComponentModel.DataAnnotations;
using System.ComponentModel.DataAnnotations.Schema;
namespace CandidateReviewDatabaseImplement.Models
{
public class Criterion : ICriterionModel
{
[Required]
public string Name { get; set; } = string.Empty;
[Required]
public CriterionTypeEnum Type { get; set; }
public string? Description { get; set; }
[Required]
public int Weight { get; set; }
public int Id { get; set; }
[ForeignKey("CriterionId")]
public virtual List<AssessmentCriterion> AssessmentCriterions { get; set; } = new();
public static Criterion? Create(CriterionBindingModel model)
{
if (model == null)
{
return null;
}
return new Criterion()
{
Id = model.Id,
Name = model.Name,
Type = model.Type,
Description = model.Description,
Weight = model.Weight
};
}
public static Criterion Create(CriterionViewModel model)
{
return new Criterion
{
Id = model.Id,
Name = model.Name,
Type = model.Type,
Description = model.Description,
Weight = model.Weight
};
}
public void Update(CriterionBindingModel model)
{
if (model == null)
{
return;
}
Name = model.Name;
Type = model.Type;
Description = model.Description;
Weight = model.Weight;
}
public CriterionViewModel GetViewModel => new()
{
Id = Id,
Name = Name,
Type = Type,
Description = Description,
Weight = Weight
};
}
}