ISEbd-22_CourseWork_University/University/UniversityDatabaseImplement/Models/Class.cs
2024-05-26 19:47:37 +04:00

62 lines
1.6 KiB
C#

using UniversityContracts.BindingModels;
using UniversityContracts.SearchModels;
using UniversityContracts.ViewModels;
using UniversityDatabaseImplement.Implements;
using UniversityDataModels;
using System.ComponentModel;
using System.ComponentModel.DataAnnotations;
namespace UniversityDatabaseImplement.Models
{
public class Class : IClassModel
{
[Required]
public int EmployeeId { get; private set; }
[Required]
public string Name { get; private set; } = string.Empty;
[Required]
public double Price { get; private set; }
[Required]
public string Time { get; private set; } = string.Empty;
public int Id { get; private set; }
[Required]
public Employee? Employee { get; private set; }
[Required]
public List<ClassByPurchase> Purchases { get; private set; } = new();
public static Class Create(ClassBindingModel model)
{
if (model == null)
{
return null;
}
return new Class()
{
EmployeeId = model.EmployeeId,
Name = model.Name,
Price = model.Price,
Time = model.Time,
Id = model.Id,
};
}
public ClassViewModel GetViewModel => new()
{
EmployeeLogin = Employee?.Login??string.Empty,
EmployeeId = EmployeeId,
Name = Name,
Price = Price,
Time = Time,
Id = Id,
Purchases = Purchases.Select(x=>x.Purchase?.GetViewModel2).ToList(),
};
public void Update(ClassBindingModel model)
{
Price = model.Price;
}
}
}