2024-11-12 22:10:44 +04:00
|
|
|
|
using EmployeeManagmentContracts.SearchModels;
|
|
|
|
|
using EmployeeManagmentContracts.StoragesContracts;
|
|
|
|
|
using EmployeeManagmentContracts.ViewModels;
|
2024-12-01 17:14:10 +04:00
|
|
|
|
using EmployeeManagmentDataBaseImplement.Models;
|
2024-11-12 22:10:44 +04:00
|
|
|
|
using System;
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using System.Linq;
|
|
|
|
|
|
|
|
|
|
namespace EmployeeManagmentDataBaseImplement.Implements
|
|
|
|
|
{
|
|
|
|
|
public class SalaryStorage : ISalaryStorage
|
|
|
|
|
{
|
2024-12-01 17:14:10 +04:00
|
|
|
|
public List<SalaryViewModel> GetFullList()
|
2024-11-12 22:10:44 +04:00
|
|
|
|
{
|
2024-12-01 17:14:10 +04:00
|
|
|
|
using var context = new EmployeeManagementDbContext();
|
2024-11-12 22:10:44 +04:00
|
|
|
|
|
2024-12-01 17:14:10 +04:00
|
|
|
|
return context.Salaries
|
|
|
|
|
.Select(s => new SalaryViewModel
|
|
|
|
|
{
|
|
|
|
|
Id = s.Id,
|
|
|
|
|
CountHours = s.CountHours,
|
|
|
|
|
PriceHour = s.PriceHour,
|
|
|
|
|
Premium = s.Premium,
|
|
|
|
|
Date = s.Data,
|
|
|
|
|
Passed = s.Passed,
|
|
|
|
|
EmployeeId = s.EmployeesId,
|
|
|
|
|
EmployeeName = s.Employee != null ? $"{s.Employee.PhisicalPerson.Surname} {s.Employee.PhisicalPerson.Name}" : "Не указано"
|
|
|
|
|
})
|
|
|
|
|
.ToList();
|
2024-11-12 22:10:44 +04:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public List<SalaryViewModel> GetFilteredList(SalarySearchModel model)
|
|
|
|
|
{
|
2024-12-01 17:14:10 +04:00
|
|
|
|
using var context = new EmployeeManagementDbContext();
|
|
|
|
|
|
|
|
|
|
if (model == null) return new List<SalaryViewModel>();
|
|
|
|
|
|
|
|
|
|
return context.Salaries
|
|
|
|
|
.Where(s =>
|
|
|
|
|
(!model.Date.HasValue || s.Data >= model.Date))
|
|
|
|
|
.Select(s => new SalaryViewModel
|
|
|
|
|
{
|
|
|
|
|
Id = s.Id,
|
|
|
|
|
CountHours = s.CountHours,
|
|
|
|
|
PriceHour = s.PriceHour,
|
|
|
|
|
Premium = s.Premium,
|
|
|
|
|
Date = s.Data,
|
|
|
|
|
Passed = s.Passed,
|
|
|
|
|
EmployeeId = s.EmployeesId,
|
|
|
|
|
EmployeeName = s.Employee != null ? $"{s.Employee.PhisicalPerson.Surname} {s.Employee.PhisicalPerson.Name}" : "Не указано"
|
|
|
|
|
})
|
|
|
|
|
.ToList();
|
2024-11-12 22:10:44 +04:00
|
|
|
|
}
|
|
|
|
|
|
2024-12-01 17:14:10 +04:00
|
|
|
|
public SalaryViewModel? GetElement(int id)
|
2024-11-12 22:10:44 +04:00
|
|
|
|
{
|
2024-12-01 17:14:10 +04:00
|
|
|
|
using var context = new EmployeeManagementDbContext();
|
|
|
|
|
|
|
|
|
|
var entity = context.Salaries
|
|
|
|
|
.FirstOrDefault(s => s.Id == id);
|
|
|
|
|
|
|
|
|
|
return entity == null ? null : new SalaryViewModel
|
|
|
|
|
{
|
|
|
|
|
Id = entity.Id,
|
|
|
|
|
CountHours = entity.CountHours,
|
|
|
|
|
PriceHour = entity.PriceHour,
|
|
|
|
|
Premium = entity.Premium,
|
|
|
|
|
Date = entity.Data,
|
|
|
|
|
Passed = entity.Passed,
|
|
|
|
|
EmployeeId = entity.EmployeesId,
|
|
|
|
|
EmployeeName = entity.Employee != null ? $"{entity.Employee.PhisicalPerson.Surname} {entity.Employee.PhisicalPerson.Name}" : "Не указано"
|
|
|
|
|
};
|
2024-11-12 22:10:44 +04:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void Insert(SalaryViewModel model)
|
|
|
|
|
{
|
2024-12-01 17:14:10 +04:00
|
|
|
|
using var context = new EmployeeManagementDbContext();
|
|
|
|
|
|
|
|
|
|
var newSalary = new Salary
|
|
|
|
|
{
|
|
|
|
|
CountHours = model.CountHours,
|
|
|
|
|
PriceHour = model.PriceHour,
|
|
|
|
|
Premium = model.Premium,
|
|
|
|
|
Data = model.Date,
|
|
|
|
|
Passed = model.Passed,
|
|
|
|
|
EmployeesId = model.EmployeeId
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
context.Salaries.Add(newSalary);
|
|
|
|
|
context.SaveChanges();
|
2024-11-12 22:10:44 +04:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void Update(SalaryViewModel model)
|
|
|
|
|
{
|
2024-12-01 17:14:10 +04:00
|
|
|
|
using var context = new EmployeeManagementDbContext();
|
|
|
|
|
|
|
|
|
|
var entity = context.Salaries.FirstOrDefault(s => s.Id == model.Id);
|
|
|
|
|
|
|
|
|
|
if (entity != null)
|
|
|
|
|
{
|
|
|
|
|
entity.CountHours = model.CountHours;
|
|
|
|
|
entity.PriceHour = model.PriceHour;
|
|
|
|
|
entity.Premium = model.Premium;
|
|
|
|
|
entity.Data = model.Date;
|
|
|
|
|
entity.Passed = model.Passed;
|
|
|
|
|
entity.EmployeesId = model.EmployeeId;
|
|
|
|
|
|
|
|
|
|
context.SaveChanges();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void Delete(int id)
|
|
|
|
|
{
|
|
|
|
|
using var context = new EmployeeManagementDbContext();
|
|
|
|
|
|
|
|
|
|
var entity = context.Salaries.FirstOrDefault(s => s.Id == id);
|
|
|
|
|
|
|
|
|
|
if (entity != null)
|
|
|
|
|
{
|
|
|
|
|
context.Salaries.Remove(entity);
|
|
|
|
|
context.SaveChanges();
|
|
|
|
|
}
|
2024-11-12 22:10:44 +04:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|