чиппи чиппи чаппа чаппа

This commit is contained in:
aleksandr chegodaev 2024-04-30 19:42:01 +04:00
parent 0989b27c5f
commit 1bde67b265
2 changed files with 56 additions and 0 deletions

View File

@ -0,0 +1,40 @@
using CarCenterContracts.BindingModels;
using CarCenterContracts.Extensions;
using CarCenterContracts.ViewModels;
using CarCenterDataModels;
using System.ComponentModel.DataAnnotations;
namespace CarCenterDatabaseImplement.Models
{
public class Account : IAccountModel
{
[Required]
public int ClientByCarId { get; private set; }
[Required]
public DateOnly DateOfAccount { get; private set; }
[Required]
public double Price { get; private set; }
public int Id { get; private set; }
[Required]
public ClientByCar? ClientByCar { get; private set; }
public static Account Create(AccountBindingModel model) => model.CastWithCommonProperties<Account, AccountBindingModel>();
public static implicit operator AccountViewModel(Account? model)
{
if (model == null)
{
throw new ArgumentNullException("Возникла ошибка при попытки получить View-модель из null-объекта", nameof(model));
}
var res = model.CastWithCommonProperties<AccountViewModel, Account>();
res.ClientByCar = model.ClientByCar;
res.Client = model.ClientByCar?.Client;
res.Car = model.ClientByCar?.Car;
return res;
}
}
}

View File

@ -0,0 +1,16 @@
using System.ComponentModel.DataAnnotations;
using CarCenterDataModels.ProxyModels;
namespace CarCenterDatabaseImplement.Models
{
public class ClientByCar : ClientByCarModel
{
[Required]
public Client? Client { get; private set; }
[Required]
public Car? Car { get; private set; }
[Required]
public List<Account>? Accounts { get; private set; }
}
}