63 lines
1.8 KiB
C#
63 lines
1.8 KiB
C#
using BankContracts.BindingModels;
|
|
using BankContracts.SearchModels;
|
|
using BankContracts.ViewModels;
|
|
using BankDatabaseImplement.Implements;
|
|
using BankDataModels;
|
|
using BankDataModels.ProxyModels;
|
|
using System.ComponentModel;
|
|
using System.ComponentModel.DataAnnotations;
|
|
|
|
namespace BankDatabaseImplement.Models
|
|
{
|
|
public class Operation : IOperationModel
|
|
{
|
|
[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<OperationByPurchase> Purchases { get; private set; } = new();
|
|
|
|
public static Operation Create(OperationBindingModel model)
|
|
{
|
|
if (model == null)
|
|
{
|
|
return null;
|
|
}
|
|
return new Operation()
|
|
{
|
|
EmployeeId = model.EmployeeId,
|
|
Model = model.Model,
|
|
Price = model.Price,
|
|
Mark = model.Mark,
|
|
Id = model.Id,
|
|
};
|
|
}
|
|
|
|
public OperationViewModel 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(OperationBindingModel model)
|
|
{
|
|
Price = model.Price;
|
|
}
|
|
}
|
|
}
|