2023-04-07 23:28:12 +04:00
|
|
|
|
using SchoolContracts.BindingModel;
|
|
|
|
|
using SchoolContracts.BindingModels;
|
|
|
|
|
using SchoolContracts.ViewModels;
|
|
|
|
|
using SchoolDataModels.Models;
|
2023-04-06 22:52:23 +04:00
|
|
|
|
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 SchoolDatabaseImplement.Models
|
|
|
|
|
{
|
|
|
|
|
public class Expense : IExpenseModel
|
|
|
|
|
{
|
2023-04-07 00:30:18 +04:00
|
|
|
|
public int Id { get; private set; }
|
2023-04-07 23:28:12 +04:00
|
|
|
|
public string ExpenseName { get; private set; } = string.Empty;
|
2023-04-06 22:52:23 +04:00
|
|
|
|
[Required]
|
2023-04-07 00:30:18 +04:00
|
|
|
|
public double Sum { get; private set; }
|
2023-04-09 00:40:04 +04:00
|
|
|
|
[Required]
|
|
|
|
|
public int Count { get; private set; }
|
2023-04-06 22:52:23 +04:00
|
|
|
|
[ForeignKey("ExpenseId")]
|
|
|
|
|
public virtual List<CircleExpense> CircleExpenses { get; set; } = new();
|
2023-04-09 02:44:56 +04:00
|
|
|
|
|
2023-04-09 00:40:04 +04:00
|
|
|
|
public static Expense? Create(SchoolDatabase context, ExpenseBindingModel model)
|
2023-04-07 23:28:12 +04:00
|
|
|
|
{
|
|
|
|
|
if (model == null)
|
|
|
|
|
{
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
return new()
|
|
|
|
|
{
|
|
|
|
|
Id = model.Id,
|
|
|
|
|
ExpenseName = model.ExpenseName,
|
2023-04-09 00:40:04 +04:00
|
|
|
|
Sum = model.Sum,
|
2023-04-09 02:44:56 +04:00
|
|
|
|
Count = model.Count
|
2023-04-07 23:28:12 +04:00
|
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
public void Update(ExpenseBindingModel model)
|
|
|
|
|
{
|
|
|
|
|
if (model == null)
|
|
|
|
|
{
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
ExpenseName = model.ExpenseName;
|
|
|
|
|
Sum = model.Sum;
|
2023-04-09 02:44:56 +04:00
|
|
|
|
Count = model.Count;
|
2023-04-07 23:28:12 +04:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public ExpenseViewModel GetViewModel => new()
|
|
|
|
|
{
|
|
|
|
|
Id = Id,
|
|
|
|
|
ExpenseName = ExpenseName,
|
2023-04-09 02:44:56 +04:00
|
|
|
|
Sum = Sum,
|
|
|
|
|
Count = Count
|
2023-04-07 23:28:12 +04:00
|
|
|
|
};
|
2023-04-06 22:52:23 +04:00
|
|
|
|
}
|
|
|
|
|
}
|