ISEbd-21_Tukaeva_A_A_School/School/SchoolDatabaseImplements/Models/CircleExpense.cs

47 lines
1.1 KiB
C#
Raw Normal View History

using Microsoft.EntityFrameworkCore;
using SchoolContracts.BindingModel;
using SchoolContracts.BindingModels;
using SchoolContracts.ViewModels;
using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace SchoolDatabaseImplement.Models
{
public class CircleExpense
{
public int Id { get; set; }
[Required]
public int ExpenseId { get; set; }
[Required]
public int CircleId { get; set; }
public virtual Expense Expense { get; set; } = new();
public virtual Circle Circle { get; set; } = new();
public static CircleExpense? Create(SchoolDatabase context, CircleExpenseBindingModel model)
{
if (model == null)
{
return null;
}
return new()
{
Id = model.Id,
Circle = context.Circles.First(x => x.Id == model.CircleId),
Expense = context.Expenses.First(x => x.Id == model.ExpenseId)
};
}
public void Update(CircleExpenseBindingModel model)
{
Id = model.Id;
}
public CircleExpenseViewModel GetViewModel => new()
{
Id = Id
};
}
}