61 lines
1.7 KiB
C#
61 lines
1.7 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using System.ComponentModel.DataAnnotations.Schema;
|
|
using System.ComponentModel.DataAnnotations;
|
|
using System.Linq;
|
|
using System.Text;
|
|
using System.Threading.Tasks;
|
|
using ZooDataModels.Models;
|
|
using ZooContracts.BindingModels;
|
|
using ZooContracts.ViewModels;
|
|
|
|
namespace ZooDatabaseImplements.Models
|
|
{
|
|
public class Cost : ICostModel
|
|
{
|
|
public int Id { get; private set; }
|
|
public string CostName { get; private set; } = string.Empty;
|
|
[Required]
|
|
public double Sum { get; private set; }
|
|
[Required]
|
|
public int Count { get; private set; }
|
|
public int EmployeeId { get; private set; }
|
|
public int RouteId { get; private set; }
|
|
[ForeignKey("CostId")]
|
|
public virtual List<RouteCost> RouteCosts { get; set; } = new();
|
|
[ForeignKey("CostId")]
|
|
public virtual Employee Employee { get; set; } = new();
|
|
public static Cost? Create(ZooDatabase context, CostBindingModel model)
|
|
{
|
|
if (model == null)
|
|
{
|
|
return null;
|
|
}
|
|
return new()
|
|
{
|
|
Id = model.Id,
|
|
CostName = model.CostName,
|
|
Sum = model.Sum,
|
|
Count = model.Count,
|
|
Employee = context.Employees.First(x => x.Id == model.EmployeeId)
|
|
};
|
|
}
|
|
public void Update(CostBindingModel model)
|
|
{
|
|
if (model == null)
|
|
{
|
|
return;
|
|
}
|
|
CostName = model.CostName;
|
|
Sum = model.Sum;
|
|
}
|
|
|
|
public CostViewModel GetViewModel => new()
|
|
{
|
|
Id = Id,
|
|
CostName = CostName,
|
|
Sum = Sum
|
|
};
|
|
}
|
|
}
|