Case_accounting/CaseAccounting/CaseAccountingDataBaseImplement/Models/Deal.cs

75 lines
1.9 KiB
C#
Raw Normal View History

using CaseAccountingContracts.BindingModels;
using CaseAccountingContracts.ViewModels;
using CaseAccountingDataModels.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 CaseAccountingDataBaseImplement.Models
{
public class Deal : IDealModel
{
public int Id { get; set; }
[Required]
public string Subject { get; set; } = string.Empty;
[Required]
public string Responsibilities { get; set; } = string.Empty;
[Required]
public DateTime Date { get; set; }
[Required]
public int UserId { get; set; }
2023-04-07 23:33:56 +04:00
public virtual User User { get; set; } = new();
[ForeignKey("DealId")]
public virtual List<CaseDeal> CaseDeals { get; set; } = new();
[ForeignKey("DealId")]
public virtual List<DealContract> Contracts { get; set; } = new();
public static Deal? Create(DealBindingModel? model)
{
if (model == null)
{
return null;
}
return new Deal()
{
Id = model.Id,
Subject = model.Subject,
Responsibilities = model.Responsibilities,
Date = model.Date,
UserId = model.UserId,
};
}
public void Update(DealBindingModel? model)
{
if (model == null)
{
return;
}
Subject = model.Subject;
Responsibilities = model.Responsibilities;
Date = model.Date;
}
public DealViewModel GetViewModel => new()
{
Id = Id,
Subject = Subject,
Responsibilities = Responsibilities,
Date = Date,
UserId = UserId
};
}
}