LabSubd/Subd/DataBase/Company.cs
2023-05-05 20:47:09 +03:00

62 lines
1.5 KiB
C#

using Contracts.BindingModels;
using Contracts.ViewModels;
using DataModels.Models;
using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations.Schema;
namespace DataBase;
/// <summary>
/// Таблица компаний-заказчиков
/// </summary>
public partial class Company : ICompany
{
/// <summary>
/// Айди компании
/// </summary>
public int Id { get; set; }
/// <summary>
/// Наимнование компании
/// </summary>
public string Title { get; set; } = null!;
/// <summary>
/// Статус компании
/// </summary>
public int? StatusId { get; set; }
public virtual Status? Status { get; set; }
public virtual ICollection<Voyage> Voyages { get; set; } = new List<Voyage>();
[NotMapped]
public string? StatusTitle { get; set; } = string.Empty;
public static Company Create(LogisticContext context, CompanyBM model)
{
return new Company()
{
Id = model.Id,
Title = model.Title,
StatusId = model.StatusId,
StatusTitle=model.StatusTitle
};
}
public void Update(CompanyBM model)
{
Title = model.Title;
StatusTitle = model.StatusTitle;
StatusId = model.StatusId;
}
public CompanyVM GetViewModel => new()
{
Id = Id,
Title = Title,
StatusId = StatusId,
StatusTitle = Status?.Title
};
}