2024-11-12 21:25:53 +04:00
|
|
|
|
using EmployeeManagmentContracts.BindingModels;
|
|
|
|
|
using EmployeeManagmentContracts.BusinessLogicContracts;
|
|
|
|
|
using EmployeeManagmentContracts.SearchModels;
|
|
|
|
|
using EmployeeManagmentContracts.StoragesContracts;
|
|
|
|
|
using EmployeeManagmentContracts.ViewModels;
|
2024-11-12 13:07:37 +04:00
|
|
|
|
|
|
|
|
|
namespace EmployeeManagmentBusinessLogic.BusinessLogic
|
|
|
|
|
{
|
|
|
|
|
public class SalaryLogic : ISalaryLogic
|
|
|
|
|
{
|
|
|
|
|
private readonly ISalaryStorage _salaryStorage;
|
|
|
|
|
|
|
|
|
|
public SalaryLogic(ISalaryStorage salaryStorage)
|
|
|
|
|
{
|
|
|
|
|
_salaryStorage = salaryStorage;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public List<SalaryViewModel> GetSalaries(SalarySearchModel model)
|
|
|
|
|
{
|
|
|
|
|
var salaries = model == null ? _salaryStorage.GetFullList() : _salaryStorage.GetFilteredList(model);
|
|
|
|
|
return salaries.Select(s => new SalaryViewModel
|
|
|
|
|
{
|
|
|
|
|
Id = s.Id,
|
|
|
|
|
CountHours = s.CountHours,
|
|
|
|
|
PriceHour = s.PriceHour,
|
|
|
|
|
Premium = s.Premium,
|
|
|
|
|
Date = s.Date,
|
|
|
|
|
Passed = s.Passed,
|
|
|
|
|
EmployeeName = s.Employee.NameJob
|
|
|
|
|
}).ToList();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void CreateOrUpdate(SalaryBindingModel model)
|
|
|
|
|
{
|
|
|
|
|
if (model.Id.HasValue)
|
|
|
|
|
{
|
|
|
|
|
var existingSalary = _salaryStorage.GetElement(model.Id.Value);
|
|
|
|
|
if (existingSalary == null)
|
|
|
|
|
throw new Exception("Зарплата не найдена");
|
|
|
|
|
|
|
|
|
|
existingSalary.CountHours = model.CountHours;
|
|
|
|
|
existingSalary.PriceHour = model.PriceHour;
|
|
|
|
|
existingSalary.Premium = model.Premium;
|
|
|
|
|
existingSalary.Date = model.Date;
|
|
|
|
|
existingSalary.Passed = model.Passed;
|
|
|
|
|
existingSalary.EmployeeId = model.EmployeeId;
|
|
|
|
|
|
|
|
|
|
_salaryStorage.Update(existingSalary);
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
var newSalary = new Salary
|
|
|
|
|
{
|
|
|
|
|
CountHours = model.CountHours,
|
|
|
|
|
PriceHour = model.PriceHour,
|
|
|
|
|
Premium = model.Premium,
|
|
|
|
|
Date = model.Date,
|
|
|
|
|
Passed = model.Passed,
|
|
|
|
|
EmployeeId = model.EmployeeId
|
|
|
|
|
};
|
|
|
|
|
_salaryStorage.Insert(newSalary);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void Delete(int id)
|
|
|
|
|
{
|
|
|
|
|
var salary = _salaryStorage.GetElement(id);
|
|
|
|
|
if (salary == null)
|
|
|
|
|
throw new Exception("Зарплата не найдена");
|
|
|
|
|
_salaryStorage.Delete(id);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|