64 lines
1.8 KiB
C#
64 lines
1.8 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using System.Text;
|
|
using System.Threading.Tasks;
|
|
using LawFirmContracts;
|
|
using LawFirmContracts.BindingModels;
|
|
using LawFirmContracts.Models;
|
|
using LawFirmContracts.ViewModels;
|
|
using System.ComponentModel.DataAnnotations;
|
|
using System.ComponentModel.DataAnnotations.Schema;
|
|
using Azure;
|
|
using System.ComponentModel;
|
|
|
|
|
|
namespace LawFirmDatabase.Models
|
|
{
|
|
public class Case : ICaseModel
|
|
{
|
|
public int Id { get; private set; }
|
|
[Required]
|
|
public string Name { get; private set; } = string.Empty;
|
|
[NotMapped]
|
|
public DateTime DateCreated { get; private set; }
|
|
[Required]
|
|
public int CustomerId { get; private set; }
|
|
[ForeignKey("CaseId")]
|
|
public virtual List<Payment> Payments { get; set; } = new();
|
|
public virtual Customer Customer { get; set; } = new();
|
|
public static Case? Create(LawFirmDBContext context, ICaseModel? model)
|
|
{
|
|
if (model == null)
|
|
{
|
|
return null;
|
|
}
|
|
return new()
|
|
{
|
|
Id = model.Id,
|
|
DateCreated = model.DateCreated,
|
|
Customer = context.Customers.First(x => x.Id == model.CustomerId)
|
|
};
|
|
}
|
|
|
|
public void Update(LawFirmDBContext context, ICaseModel? model)
|
|
{
|
|
if (model == null)
|
|
{
|
|
return;
|
|
}
|
|
Id = model.Id;
|
|
DateCreated = model.DateCreated;
|
|
Customer = context.Customers.First(x => x.Id == model.CustomerId);
|
|
}
|
|
|
|
public CaseViewModel? GetViewModel() => new()
|
|
{
|
|
Id = Id,
|
|
Name = Name,
|
|
DateCreated = DateCreated,
|
|
CustomerId = CustomerId
|
|
};
|
|
}
|
|
}
|