59 lines
1.6 KiB
C#
59 lines
1.6 KiB
C#
|
using STOContracts.BindingModels;
|
|||
|
using STOContracts.ViewModels;
|
|||
|
using STODatabaseImplement;
|
|||
|
using STODataModels;
|
|||
|
using System;
|
|||
|
using System.Collections.Generic;
|
|||
|
using System.ComponentModel.DataAnnotations;
|
|||
|
using System.Linq;
|
|||
|
using System.Text;
|
|||
|
using System.Threading.Tasks;
|
|||
|
|
|||
|
namespace DatabaseImplement
|
|||
|
{
|
|||
|
public class Service : IServiceModel
|
|||
|
{
|
|||
|
public int Id { get; private set; }
|
|||
|
[Required]
|
|||
|
public string Name {get; private set;} = string.Empty;
|
|||
|
|
|||
|
[Required]
|
|||
|
public int CarId { get; private set; }
|
|||
|
public virtual Car Car { get; set; } = new();
|
|||
|
|
|||
|
public int ClientId { get; private set; }
|
|||
|
public virtual Client Client { get; set; } = new();
|
|||
|
|
|||
|
public static Service? Create(STODatabase context, ServiceBindingModel model)
|
|||
|
{
|
|||
|
if (model == null)
|
|||
|
{
|
|||
|
return null;
|
|||
|
}
|
|||
|
return new Service()
|
|||
|
{
|
|||
|
CarId = model.CarId,
|
|||
|
Car = context.Cars.First(x => x.Id == model.CarId),
|
|||
|
ClientId = model.ClientId,
|
|||
|
Client = context.Clients.First(x => x.Id == model.ClientId),
|
|||
|
Id = model.Id,
|
|||
|
Name = model.Name
|
|||
|
};
|
|||
|
}
|
|||
|
public void Update(ServiceBindingModel model)
|
|||
|
{
|
|||
|
if (model == null)
|
|||
|
{
|
|||
|
return;
|
|||
|
}
|
|||
|
Name = model.Name;
|
|||
|
}
|
|||
|
public ServiceViewModel GetViewModel => new()
|
|||
|
{
|
|||
|
Id = Id,
|
|||
|
Name = Name,
|
|||
|
CarId = CarId
|
|||
|
};
|
|||
|
}
|
|||
|
}
|