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 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; } } }