63 lines
1.6 KiB
C#
63 lines
1.6 KiB
C#
using UniversityContracts.BindingModels;
|
|
using UniversityContracts.SearchModels;
|
|
using UniversityContracts.ViewModels;
|
|
using UniversityDatabaseImplement.Implements;
|
|
using UniversityDataModels;
|
|
using UniversityDataModels.ProxyModels;
|
|
using System.ComponentModel;
|
|
using System.ComponentModel.DataAnnotations;
|
|
|
|
namespace UniversityDatabaseImplement.Models
|
|
{
|
|
public class Class : IClassModel
|
|
{
|
|
[Required]
|
|
public int EmployeeId { get; private set; }
|
|
[Required]
|
|
public string Model { get; private set; } = string.Empty;
|
|
[Required]
|
|
public double Price { get; private set; }
|
|
[Required]
|
|
public string Mark { 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,
|
|
Model = model.Model,
|
|
Price = model.Price,
|
|
Mark = model.Mark,
|
|
Id = model.Id,
|
|
};
|
|
}
|
|
|
|
public ClassViewModel GetViewModel => new()
|
|
{
|
|
EmployeePhoneNumber = Employee?.PhoneNumber??string.Empty,
|
|
EmployeeId = EmployeeId,
|
|
Model = Model,
|
|
Price = Price,
|
|
Mark = Mark,
|
|
Id = Id,
|
|
Purchases = Purchases.Select(x=>x.Purchase?.GetViewModel2).ToList(),
|
|
};
|
|
|
|
public void Update(ClassBindingModel model)
|
|
{
|
|
Price = model.Price;
|
|
}
|
|
}
|
|
}
|