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; }
|
|
|
|
|
public int EmployeeId { get; private set; }
|
|
|
|
|
public int CircleId { get; private set; }
|
2023-04-06 22:52:23 +04:00
|
|
|
|
[ForeignKey("ExpenseId")]
|
|
|
|
|
public virtual List<CircleExpense> CircleExpenses { get; set; } = new();
|
2023-04-09 00:40:04 +04:00
|
|
|
|
[ForeignKey("ExpenseId")]
|
|
|
|
|
public virtual Employee Employee { get; set; } = new();
|
|
|
|
|
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,
|
|
|
|
|
Count = model.Count,
|
|
|
|
|
Employee = context.Employees.First(x => x.Id == model.EmployeeId)
|
2023-04-07 23:28:12 +04:00
|
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
public void Update(ExpenseBindingModel model)
|
|
|
|
|
{
|
|
|
|
|
if (model == null)
|
|
|
|
|
{
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
ExpenseName = model.ExpenseName;
|
|
|
|
|
Sum = model.Sum;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public ExpenseViewModel GetViewModel => new()
|
|
|
|
|
{
|
|
|
|
|
Id = Id,
|
|
|
|
|
ExpenseName = ExpenseName,
|
|
|
|
|
Sum = Sum
|
|
|
|
|
};
|
2023-04-06 22:52:23 +04:00
|
|
|
|
}
|
|
|
|
|
}
|