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
|
|
|
|
|
{
|
2024-11-26 21:24:08 +04:00
|
|
|
|
public class VacationStorage : IVacationStorage
|
2024-11-12 22:10:44 +04:00
|
|
|
|
{
|
2024-12-01 17:14:10 +04:00
|
|
|
|
public List<VacationViewModel> 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.Vacations
|
|
|
|
|
.Select(v => new VacationViewModel
|
|
|
|
|
{
|
|
|
|
|
Id = v.Id,
|
|
|
|
|
StartData = v.StartData,
|
|
|
|
|
EndData = v.EndData,
|
|
|
|
|
Passed = v.Passed,
|
|
|
|
|
EmployeeId = v.EmployeesId,
|
2024-12-07 23:36:29 +04:00
|
|
|
|
EmployeeName = v.Employee != null ? $"{v.Employee.PhisicalPerson.Surname} {v.Employee.PhisicalPerson.Name} {v.Employee.PhisicalPerson.Patronymic} ({v.Employee.NameJob})" : "Не указано"
|
2024-12-01 17:14:10 +04:00
|
|
|
|
})
|
|
|
|
|
.ToList();
|
2024-11-12 22:10:44 +04:00
|
|
|
|
}
|
|
|
|
|
|
2024-11-26 21:24:08 +04:00
|
|
|
|
public List<VacationViewModel> GetFilteredList(VacationSearchModel model)
|
2024-11-12 22:10:44 +04:00
|
|
|
|
{
|
2024-12-01 17:14:10 +04:00
|
|
|
|
using var context = new EmployeeManagementDbContext();
|
|
|
|
|
|
|
|
|
|
if (model == null) return new List<VacationViewModel>();
|
|
|
|
|
|
|
|
|
|
return context.Vacations
|
|
|
|
|
.Where(v =>
|
|
|
|
|
(!model.StartData.HasValue || v.StartData >= model.StartData) &&
|
|
|
|
|
(!model.EndData.HasValue || v.EndData <= model.EndData))
|
|
|
|
|
.Select(v => new VacationViewModel
|
|
|
|
|
{
|
|
|
|
|
Id = v.Id,
|
|
|
|
|
StartData = v.StartData,
|
|
|
|
|
EndData = v.EndData,
|
|
|
|
|
Passed = v.Passed,
|
|
|
|
|
EmployeeId = v.EmployeesId,
|
2024-12-07 23:36:29 +04:00
|
|
|
|
EmployeeName = v.Employee != null ? $"{v.Employee.PhisicalPerson.Surname} {v.Employee.PhisicalPerson.Name} {v.Employee.PhisicalPerson.Patronymic} ({v.Employee.NameJob})" : "Не указано"
|
2024-12-01 17:14:10 +04:00
|
|
|
|
})
|
|
|
|
|
.ToList();
|
2024-11-12 22:10:44 +04:00
|
|
|
|
}
|
|
|
|
|
|
2024-12-01 17:14:10 +04:00
|
|
|
|
public VacationViewModel? 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.Vacations
|
|
|
|
|
.FirstOrDefault(v => v.Id == id);
|
|
|
|
|
|
|
|
|
|
return entity == null ? null : new VacationViewModel
|
|
|
|
|
{
|
|
|
|
|
Id = entity.Id,
|
|
|
|
|
StartData = entity.StartData,
|
|
|
|
|
EndData = entity.EndData,
|
|
|
|
|
Passed = entity.Passed,
|
|
|
|
|
EmployeeId = entity.EmployeesId,
|
2024-12-07 23:36:29 +04:00
|
|
|
|
EmployeeName = entity.Employee != null ? $"{entity.Employee.PhisicalPerson.Surname} {entity.Employee.PhisicalPerson.Name} {entity.Employee.PhisicalPerson.Patronymic} ({entity.Employee.NameJob})" : "Не указано"
|
2024-12-01 17:14:10 +04:00
|
|
|
|
};
|
2024-11-12 22:10:44 +04:00
|
|
|
|
}
|
|
|
|
|
|
2024-11-26 21:24:08 +04:00
|
|
|
|
public void Insert(VacationViewModel model)
|
2024-11-12 22:10:44 +04:00
|
|
|
|
{
|
2024-12-01 17:14:10 +04:00
|
|
|
|
using var context = new EmployeeManagementDbContext();
|
|
|
|
|
|
|
|
|
|
var newVacation = new Vacation
|
|
|
|
|
{
|
|
|
|
|
StartData = model.StartData,
|
|
|
|
|
EndData = model.EndData,
|
|
|
|
|
Passed = model.Passed,
|
|
|
|
|
EmployeesId = model.EmployeeId
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
context.Vacations.Add(newVacation);
|
|
|
|
|
context.SaveChanges();
|
2024-11-12 22:10:44 +04:00
|
|
|
|
}
|
|
|
|
|
|
2024-11-26 21:24:08 +04:00
|
|
|
|
public void Update(VacationViewModel model)
|
2024-11-12 22:10:44 +04:00
|
|
|
|
{
|
2024-12-01 17:14:10 +04:00
|
|
|
|
using var context = new EmployeeManagementDbContext();
|
|
|
|
|
|
|
|
|
|
var entity = context.Vacations.FirstOrDefault(v => v.Id == model.Id);
|
|
|
|
|
|
|
|
|
|
if (entity != null)
|
|
|
|
|
{
|
|
|
|
|
entity.StartData = model.StartData;
|
|
|
|
|
entity.EndData = model.EndData;
|
|
|
|
|
entity.Passed = model.Passed;
|
|
|
|
|
entity.EmployeesId = model.EmployeeId;
|
|
|
|
|
|
|
|
|
|
context.SaveChanges();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void Delete(int id)
|
|
|
|
|
{
|
|
|
|
|
using var context = new EmployeeManagementDbContext();
|
|
|
|
|
|
|
|
|
|
var entity = context.Vacations.FirstOrDefault(v => v.Id == id);
|
|
|
|
|
|
|
|
|
|
if (entity != null)
|
|
|
|
|
{
|
|
|
|
|
context.Vacations.Remove(entity);
|
|
|
|
|
context.SaveChanges();
|
|
|
|
|
}
|
2024-11-12 22:10:44 +04:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|