CourseWork_Bank/Bank/BankDatabaseImplement/Models/Operation.cs

63 lines
1.8 KiB
C#
Raw Normal View History

2024-04-28 19:31:02 +04:00
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
{
2024-04-28 19:31:02 +04:00
public class Operation : IOperationModel
{
2024-04-28 19:31:02 +04:00
[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;
}
}
}