2024-10-29 09:22:02 +04:00

59 lines
1.6 KiB
C#

using ClientsContracts.BindingModels;
using ClientsContracts.ViewModels;
using ClientsDataModels.Models;
using System.ComponentModel.DataAnnotations;
using System.Data;
namespace ClientsDatabaseImplement.Models
{
public class Client : IClientModel
{
public int Id { get; private set; }
[Required]
public string Name { get; set; }
public string? Reviews { get; set; } = null;
public float? Amount { get; set; } = null;
[Required]
public int StatusId { get; set; }
public virtual Status Status { get; set; } = new();
public static Client? Create(ClientBindingModel? model, ClientsDatabase context)
{
if (model == null)
{
return null;
}
return new Client()
{
Id = model.Id,
Name = model.Name,
Reviews = model.Reviews,
Amount = model.Amount,
StatusId = model.StatusId,
Status = context.Statuses.First(x => x.Id == model.StatusId),
};
}
public void Update(ClientBindingModel? model)
{
if (model == null)
{
return;
}
Name = model.Name;
Reviews = model.Reviews;
Amount = model.Amount;
}
public ClientViewModel GetViewModel => new()
{
Id = Id,
Name = Name,
Reviews = Reviews,
Amount = Amount,
StatusId = StatusId,
StatusName = Status.StatusName,
};
}
}