74 lines
2.4 KiB
C#
74 lines
2.4 KiB
C#
|
using System;
|
|||
|
using System.Collections.Generic;
|
|||
|
using System.Linq;
|
|||
|
using System.Text;
|
|||
|
using System.Threading.Tasks;
|
|||
|
|
|||
|
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);
|
|||
|
}
|
|||
|
}
|
|||
|
}
|