72 lines
1.8 KiB
C#
72 lines
1.8 KiB
C#
using RestaurantContracts.BindingModels;
|
|
using RestaurantContracts.ViewModels;
|
|
using RestaurantDataModels.Models;
|
|
using System;
|
|
using System.Collections.Generic;
|
|
using System.ComponentModel.DataAnnotations;
|
|
using System.ComponentModel.DataAnnotations.Schema;
|
|
using System.Linq;
|
|
using System.Text;
|
|
using System.Threading.Tasks;
|
|
|
|
namespace RestaurantDatabaseImplement.Models
|
|
{
|
|
public class Provider : IProviderModel
|
|
{
|
|
[Required]
|
|
public string Name { get; private set; } = string.Empty;
|
|
|
|
[Required]
|
|
public string Address { get; private set; } = string.Empty;
|
|
|
|
public int Id { get; private set; }
|
|
|
|
[ForeignKey("ProviderId")]
|
|
public virtual List<ComponentProvider> ComponentProviders { get; set; } = new();
|
|
public static Provider? Create(ProviderBindingModel model)
|
|
{
|
|
if (model == null)
|
|
{
|
|
return null;
|
|
}
|
|
return new Provider()
|
|
{
|
|
Id = model.Id,
|
|
Name = model.Name,
|
|
Address = model.Address
|
|
};
|
|
}
|
|
|
|
public static Provider Create(ProviderViewModel model)
|
|
{
|
|
if (model == null)
|
|
{
|
|
return null;
|
|
}
|
|
return new Provider()
|
|
{
|
|
Id = model.Id,
|
|
Name = model.Name,
|
|
Address = model.Address
|
|
};
|
|
}
|
|
|
|
public void Update(ProviderBindingModel model)
|
|
{
|
|
if (model == null)
|
|
{
|
|
return;
|
|
}
|
|
Name = model.Name;
|
|
Address = model.Address;
|
|
}
|
|
|
|
public ProviderViewModel GetViewModel => new()
|
|
{
|
|
Id = Id,
|
|
Name = Name,
|
|
Address = Address
|
|
};
|
|
}
|
|
}
|