using Microsoft.EntityFrameworkCore; using SchoolContracts.BindingModel; using SchoolContracts.BindingModels; using SchoolContracts.ViewModels; using SchoolDataModels.Models; 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 : ICircleExpenseModel { 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 }; } }