diff --git a/CarCenterDatabaseImplement/Models/Account.cs b/CarCenterDatabaseImplement/Models/Account.cs new file mode 100644 index 0000000..db5aa12 --- /dev/null +++ b/CarCenterDatabaseImplement/Models/Account.cs @@ -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(); + + public static implicit operator AccountViewModel(Account? model) + { + if (model == null) + { + throw new ArgumentNullException("Возникла ошибка при попытки получить View-модель из null-объекта", nameof(model)); + } + var res = model.CastWithCommonProperties(); + res.ClientByCar = model.ClientByCar; + res.Client = model.ClientByCar?.Client; + res.Car = model.ClientByCar?.Car; + return res; + } + } +} diff --git a/CarCenterDatabaseImplement/Models/ClientByCar.cs b/CarCenterDatabaseImplement/Models/ClientByCar.cs new file mode 100644 index 0000000..073a08c --- /dev/null +++ b/CarCenterDatabaseImplement/Models/ClientByCar.cs @@ -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? Accounts { get; private set; } + } +}