2023-04-02 16:04:50 +04:00
|
|
|
|
using CarServiceContracts.BindingModels;
|
|
|
|
|
using CarServiceContracts.Models;
|
|
|
|
|
using CarServiceContracts.ViewModels;
|
|
|
|
|
using System.ComponentModel.DataAnnotations;
|
|
|
|
|
using System.ComponentModel.DataAnnotations.Schema;
|
|
|
|
|
|
|
|
|
|
namespace CarServiceDatabase.Models
|
|
|
|
|
{
|
|
|
|
|
public class Work : IWorkModel
|
|
|
|
|
{
|
|
|
|
|
public int Id { get; private set; }
|
|
|
|
|
[Required]
|
|
|
|
|
public string Name { get; private set; } = string.Empty;
|
|
|
|
|
[Required, Column(TypeName = "decimal (10,2)")]
|
|
|
|
|
public decimal Price { get; private set; }
|
|
|
|
|
[Required, Column(TypeName = "decimal (3,1)")]
|
|
|
|
|
public decimal Duration { get; private set; }
|
|
|
|
|
[Required]
|
|
|
|
|
public int WorkerId { get; private set; }
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Работы в заявке
|
|
|
|
|
/// </summary>
|
|
|
|
|
[ForeignKey("WorkId")]
|
|
|
|
|
public virtual List<WorkInRequest> WorksInRequest { get; set; } = new();
|
2023-04-04 22:42:28 +04:00
|
|
|
|
public virtual Worker Worker { get; set; } = new();
|
2023-04-05 21:03:41 +04:00
|
|
|
|
public static Work? Create(CarServiceDbContext context, WorkBindingModel? model)
|
2023-04-02 16:04:50 +04:00
|
|
|
|
{
|
|
|
|
|
if (model == null)
|
|
|
|
|
{
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
return new()
|
|
|
|
|
{
|
|
|
|
|
Id = model.Id,
|
|
|
|
|
Name = model.Name,
|
|
|
|
|
Price = model.Price,
|
|
|
|
|
Duration = model.Duration,
|
2023-04-05 21:03:41 +04:00
|
|
|
|
Worker = context.Workers.First(x => x.Id == model.WorkerId)
|
2023-04-02 16:04:50 +04:00
|
|
|
|
};
|
|
|
|
|
}
|
2023-04-05 21:03:41 +04:00
|
|
|
|
public void Update(CarServiceDbContext context, WorkBindingModel? model)
|
2023-04-02 16:04:50 +04:00
|
|
|
|
{
|
|
|
|
|
if (model == null)
|
|
|
|
|
{
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
Id = model.Id;
|
|
|
|
|
Name = model.Name;
|
|
|
|
|
Price = model.Price;
|
|
|
|
|
Duration = model.Duration;
|
2023-04-05 21:03:41 +04:00
|
|
|
|
Worker = context.Workers.First(x => x.Id == model.WorkerId);
|
2023-04-02 16:04:50 +04:00
|
|
|
|
}
|
|
|
|
|
public WorkViewModel GetViewModel => new()
|
|
|
|
|
{
|
|
|
|
|
Id = Id,
|
|
|
|
|
Name = Name,
|
|
|
|
|
Price = Price,
|
|
|
|
|
Duration = Duration,
|
2023-04-05 21:03:41 +04:00
|
|
|
|
WorkerId = WorkerId,
|
|
|
|
|
WorkerName = Worker.Name + " " + Worker.Surname
|
2023-04-02 16:04:50 +04:00
|
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
}
|