Добавление логики и контрактов
This commit is contained in:
parent
a2631c83cb
commit
e2c838da47
@ -1,19 +1,14 @@
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using EmployeeManagmentContracts.BindingModels;
|
||||
using EmployeeManagmentContracts.BusinessLogicContracts;
|
||||
using EmployeeManagmentContracts.BusinessLogicContracts;
|
||||
using EmployeeManagmentContracts.SearchModels;
|
||||
using EmployeeManagmentContracts.StoragesContracts;
|
||||
using EmployeeManagmentContracts.ViewModels;
|
||||
using EmployeeManagmentDataBaseImplement;
|
||||
using EmployeeManagmentDataBaseImplement.Models;
|
||||
using Microsoft.Extensions.Logging;
|
||||
|
||||
namespace EmployeeManagmentBusinessLogic.BusinessLogic
|
||||
{
|
||||
public class EmployeeLogic : IEmployeeLogic
|
||||
{
|
||||
private readonly ILogger _logger;
|
||||
private readonly ILogger<EmployeeLogic> _logger;
|
||||
private readonly IEmployeeStorage _employeeStorage;
|
||||
|
||||
public EmployeeLogic(ILogger<EmployeeLogic> logger, IEmployeeStorage employeeStorage)
|
||||
@ -22,34 +17,51 @@ namespace EmployeeManagmentBusinessLogic.BusinessLogic
|
||||
_employeeStorage = employeeStorage;
|
||||
}
|
||||
|
||||
public void Delete(int id)
|
||||
public List<EmployeeViewModel> GetFullList()
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
public EmployeeViewModel? GetElement(int id)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
return _employeeStorage.GetFullList();
|
||||
}
|
||||
|
||||
public List<EmployeeViewModel> GetFilteredList(EmployeeSearchModel model)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
return _employeeStorage.GetFilteredList(model);
|
||||
}
|
||||
|
||||
public List<EmployeeViewModel> GetFullList()
|
||||
public EmployeeViewModel? GetElement(int id)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
return _employeeStorage.GetElement(id);
|
||||
}
|
||||
|
||||
public void Insert(EmployeeViewModel model)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
if (string.IsNullOrWhiteSpace(model.NameJob))
|
||||
{
|
||||
throw new ArgumentException("Название должности обязательно для заполнения.");
|
||||
}
|
||||
|
||||
_employeeStorage.Insert(model);
|
||||
}
|
||||
|
||||
public void Update(EmployeeViewModel model)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
var element = _employeeStorage.GetElement(model.Id);
|
||||
if (element == null)
|
||||
{
|
||||
throw new ArgumentException("Сотрудник не найден.");
|
||||
}
|
||||
|
||||
_employeeStorage.Update(model);
|
||||
}
|
||||
|
||||
public void Delete(int id)
|
||||
{
|
||||
var element = _employeeStorage.GetElement(id);
|
||||
if (element == null)
|
||||
{
|
||||
throw new ArgumentException("Сотрудник не найден.");
|
||||
}
|
||||
|
||||
_employeeStorage.Delete(id);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -14,7 +14,7 @@ namespace EmployeeManagmentContracts.ViewModels
|
||||
public DateTime? EndJob { get; set; }
|
||||
public string? PartTimeJob { get; set; }
|
||||
public float Bid { get; set; }
|
||||
public int PhysicalPersonsId { get; set; }
|
||||
public int? PhysicalPersonsId { get; set; }
|
||||
public string? PhysicalPersonName { get; set; }
|
||||
}
|
||||
|
||||
|
@ -7,34 +7,124 @@ namespace EmployeeManagmentDataBaseImplement.Implements
|
||||
{
|
||||
public class EmployeeStorage : IEmployeeStorage
|
||||
{
|
||||
public void Delete(int id)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
public EmployeeViewModel? GetElement(int id)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
public List<EmployeeViewModel> GetFilteredList(EmployeeSearchModel model)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
// Получить полный список сотрудников
|
||||
public List<EmployeeViewModel> GetFullList()
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
using var context = new EmployeeManagementDbContext();
|
||||
|
||||
return context.Employees
|
||||
.Select(e => new EmployeeViewModel
|
||||
{
|
||||
Id = e.Id,
|
||||
NameJob = e.NameJob,
|
||||
StartJob = e.StartJob,
|
||||
EndJob = e.EndJob,
|
||||
PartTimeJob = e.PartTimeJob,
|
||||
Bid = e.Bid,
|
||||
PhysicalPersonsId = e.PhisicalPersonsId,
|
||||
PhysicalPersonName = $"{e.PhisicalPerson.Surname} {e.PhisicalPerson.Name}"
|
||||
})
|
||||
.ToList();
|
||||
}
|
||||
|
||||
// Получить отфильтрованный список сотрудников
|
||||
public List<EmployeeViewModel> GetFilteredList(EmployeeSearchModel model)
|
||||
{
|
||||
using var context = new EmployeeManagementDbContext();
|
||||
|
||||
if (model == null) return new List<EmployeeViewModel>();
|
||||
|
||||
return context.Employees
|
||||
.Where(e =>
|
||||
(string.IsNullOrEmpty(model.NameJob) || e.NameJob.Contains(model.NameJob)) &&
|
||||
(!model.StartDateFrom.HasValue || e.StartJob >= model.StartDateFrom) &&
|
||||
(!model.StartDateTo.HasValue || e.EndJob <= model.StartDateTo))
|
||||
.Select(e => new EmployeeViewModel
|
||||
{
|
||||
Id = e.Id,
|
||||
NameJob = e.NameJob,
|
||||
StartJob = e.StartJob,
|
||||
EndJob = e.EndJob,
|
||||
PartTimeJob = e.PartTimeJob,
|
||||
Bid = e.Bid,
|
||||
PhysicalPersonsId = e.PhisicalPersonsId,
|
||||
PhysicalPersonName = $"{e.PhisicalPerson.Surname} {e.PhisicalPerson.Name}"
|
||||
})
|
||||
.ToList();
|
||||
}
|
||||
|
||||
// Получить сотрудника по ID
|
||||
public EmployeeViewModel? GetElement(int id)
|
||||
{
|
||||
using var context = new EmployeeManagementDbContext();
|
||||
|
||||
var entity = context.Employees
|
||||
.FirstOrDefault(e => e.Id == id);
|
||||
|
||||
return entity == null ? null : new EmployeeViewModel
|
||||
{
|
||||
Id = entity.Id,
|
||||
NameJob = entity.NameJob,
|
||||
StartJob = entity.StartJob,
|
||||
EndJob = entity.EndJob,
|
||||
PartTimeJob = entity.PartTimeJob,
|
||||
Bid = entity.Bid,
|
||||
PhysicalPersonsId = entity.PhisicalPersonsId,
|
||||
PhysicalPersonName = $"{entity.PhisicalPerson.Surname} {entity.PhisicalPerson.Name}"
|
||||
};
|
||||
}
|
||||
|
||||
// Добавить нового сотрудника
|
||||
public void Insert(EmployeeViewModel model)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
using var context = new EmployeeManagementDbContext();
|
||||
|
||||
var newEmployee = new Employee
|
||||
{
|
||||
NameJob = model.NameJob,
|
||||
StartJob = model.StartJob,
|
||||
EndJob = model.EndJob,
|
||||
PartTimeJob = model.PartTimeJob,
|
||||
Bid = model.Bid,
|
||||
PhisicalPersonsId = model.PhysicalPersonsId
|
||||
};
|
||||
|
||||
context.Employees.Add(newEmployee);
|
||||
context.SaveChanges();
|
||||
}
|
||||
|
||||
// Обновить сотрудника
|
||||
public void Update(EmployeeViewModel model)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
using var context = new EmployeeManagementDbContext();
|
||||
|
||||
var entity = context.Employees.FirstOrDefault(e => e.Id == model.Id);
|
||||
|
||||
if (entity != null)
|
||||
{
|
||||
entity.NameJob = model.NameJob;
|
||||
entity.StartJob = model.StartJob;
|
||||
entity.EndJob = model.EndJob;
|
||||
entity.PartTimeJob = model.PartTimeJob;
|
||||
entity.Bid = model.Bid;
|
||||
entity.PhisicalPersonsId = model.PhysicalPersonsId;
|
||||
|
||||
context.SaveChanges();
|
||||
}
|
||||
}
|
||||
|
||||
// Удалить сотрудника
|
||||
public void Delete(int id)
|
||||
{
|
||||
using var context = new EmployeeManagementDbContext();
|
||||
|
||||
var entity = context.Employees.FirstOrDefault(e => e.Id == id);
|
||||
|
||||
if (entity != null)
|
||||
{
|
||||
context.Employees.Remove(entity);
|
||||
context.SaveChanges();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user