diff --git a/EmployeeManagmentBusinessLogic/BusinessLogic/SalaryLogic.cs b/EmployeeManagmentBusinessLogic/BusinessLogic/SalaryLogic.cs index c9d3a3f..e6dfaf1 100644 --- a/EmployeeManagmentBusinessLogic/BusinessLogic/SalaryLogic.cs +++ b/EmployeeManagmentBusinessLogic/BusinessLogic/SalaryLogic.cs @@ -1,16 +1,16 @@ -using EmployeeManagmentContracts.BindingModels; -using EmployeeManagmentContracts.BusinessLogicContracts; +using EmployeeManagmentContracts.BusinessLogicContracts; using EmployeeManagmentContracts.SearchModels; -using EmployeeManagmentContracts.StoragesContracts; using EmployeeManagmentContracts.ViewModels; -using EmployeeManagmentDataBaseImplement.Implements; +using EmployeeManagmentContracts.StoragesContracts; using Microsoft.Extensions.Logging; +using System; +using System.Collections.Generic; namespace EmployeeManagmentBusinessLogic.BusinessLogic { public class SalaryLogic : ISalaryLogic { - private readonly ILogger _logger; + private readonly ILogger _logger; private readonly ISalaryStorage _salaryStorage; public SalaryLogic(ILogger logger, ISalaryStorage salaryStorage) @@ -19,34 +19,51 @@ namespace EmployeeManagmentBusinessLogic.BusinessLogic _salaryStorage = salaryStorage; } + public List GetFullList() + { + return _salaryStorage.GetFullList(); + } + + public List GetFilteredList(SalarySearchModel model) + { + return _salaryStorage.GetFilteredList(model); + } + + public SalaryViewModel? GetElement(int id) + { + return _salaryStorage.GetElement(id); + } + + public void Insert(SalaryViewModel model) + { + if (model.EmployeeId == null) + { + throw new ArgumentException("Сотрудник обязательно должен быть указан."); + } + + _salaryStorage.Insert(model); + } + + public void Update(SalaryViewModel model) + { + var element = _salaryStorage.GetElement(model.Id); + if (element == null) + { + throw new ArgumentException("Зарплата не найдена."); + } + + _salaryStorage.Update(model); + } + public void Delete(int id) { - throw new NotImplementedException(); - } + var element = _salaryStorage.GetElement(id); + if (element == null) + { + throw new ArgumentException("Зарплата не найдена."); + } - public PhisicalPersonViewModel? GetElement(int id) - { - throw new NotImplementedException(); - } - - public List GetFilteredList(PhisicalPersonSearchModel model) - { - throw new NotImplementedException(); - } - - public List GetFullList() - { - throw new NotImplementedException(); - } - - public void Insert(PhisicalPersonViewModel model) - { - throw new NotImplementedException(); - } - - public void Update(PhisicalPersonViewModel model) - { - throw new NotImplementedException(); + _salaryStorage.Delete(id); } } } diff --git a/EmployeeManagmentBusinessLogic/BusinessLogic/VacationLogic.cs b/EmployeeManagmentBusinessLogic/BusinessLogic/VacationLogic.cs index 589f194..d5a2022 100644 --- a/EmployeeManagmentBusinessLogic/BusinessLogic/VacationLogic.cs +++ b/EmployeeManagmentBusinessLogic/BusinessLogic/VacationLogic.cs @@ -1,16 +1,16 @@ -using EmployeeManagmentContracts.BindingModels; -using EmployeeManagmentContracts.BusinessLogicContracts; +using EmployeeManagmentContracts.BusinessLogicContracts; using EmployeeManagmentContracts.SearchModels; -using EmployeeManagmentContracts.StoragesContracts; using EmployeeManagmentContracts.ViewModels; -using EmployeeManagmentDataBaseImplement.Implements; +using EmployeeManagmentContracts.StoragesContracts; using Microsoft.Extensions.Logging; +using System; +using System.Collections.Generic; namespace EmployeeManagmentBusinessLogic.BusinessLogic { public class VacationLogic : IVacationLogic { - private readonly ILogger _logger; + private readonly ILogger _logger; private readonly IVacationStorage _vacationStorage; public VacationLogic(ILogger logger, IVacationStorage vacationStorage) @@ -19,34 +19,51 @@ namespace EmployeeManagmentBusinessLogic.BusinessLogic _vacationStorage = vacationStorage; } + public List GetFullList() + { + return _vacationStorage.GetFullList(); + } + + public List GetFilteredList(VacationSearchModel model) + { + return _vacationStorage.GetFilteredList(model); + } + + public VacationViewModel? GetElement(int id) + { + return _vacationStorage.GetElement(id); + } + + public void Insert(VacationViewModel model) + { + if (model.EmployeeId == null) + { + throw new ArgumentException("Сотрудник обязательно должен быть указан."); + } + + _vacationStorage.Insert(model); + } + + public void Update(VacationViewModel model) + { + var element = _vacationStorage.GetElement(model.Id); + if (element == null) + { + throw new ArgumentException("Отпуск не найден."); + } + + _vacationStorage.Update(model); + } + public void Delete(int id) { - throw new NotImplementedException(); - } + var element = _vacationStorage.GetElement(id); + if (element == null) + { + throw new ArgumentException("Отпуск не найден."); + } - public PhisicalPersonViewModel? GetElement(int id) - { - throw new NotImplementedException(); - } - - public List GetFilteredList(EmployeeSearchModel model) - { - throw new NotImplementedException(); - } - - public List GetFullList() - { - throw new NotImplementedException(); - } - - public void Insert(PhisicalPersonViewModel model) - { - throw new NotImplementedException(); - } - - public void Update(PhisicalPersonViewModel model) - { - throw new NotImplementedException(); + _vacationStorage.Delete(id); } } } diff --git a/EmployeeManagmentContracts/BusinessLogicContracts/ISalaryLogic.cs b/EmployeeManagmentContracts/BusinessLogicContracts/ISalaryLogic.cs index 8501144..ea2207a 100644 --- a/EmployeeManagmentContracts/BusinessLogicContracts/ISalaryLogic.cs +++ b/EmployeeManagmentContracts/BusinessLogicContracts/ISalaryLogic.cs @@ -11,11 +11,11 @@ namespace EmployeeManagmentContracts.BusinessLogicContracts { public interface ISalaryLogic { - List GetFullList(); - List GetFilteredList(PhisicalPersonSearchModel model); - PhisicalPersonViewModel? GetElement(int id); - void Insert(PhisicalPersonViewModel model); - void Update(PhisicalPersonViewModel model); + List GetFullList(); + List GetFilteredList(SalarySearchModel model); + SalaryViewModel? GetElement(int id); + void Insert(SalaryViewModel model); + void Update(SalaryViewModel model); void Delete(int id); } diff --git a/EmployeeManagmentContracts/BusinessLogicContracts/IVacationLogic.cs b/EmployeeManagmentContracts/BusinessLogicContracts/IVacationLogic.cs index 2c2570e..80ad286 100644 --- a/EmployeeManagmentContracts/BusinessLogicContracts/IVacationLogic.cs +++ b/EmployeeManagmentContracts/BusinessLogicContracts/IVacationLogic.cs @@ -11,11 +11,11 @@ namespace EmployeeManagmentContracts.BusinessLogicContracts { public interface IVacationLogic { - List GetFullList(); - List GetFilteredList(EmployeeSearchModel model); - PhisicalPersonViewModel? GetElement(int id); - void Insert(PhisicalPersonViewModel model); - void Update(PhisicalPersonViewModel model); + List GetFullList(); + List GetFilteredList(VacationSearchModel model); + VacationViewModel? GetElement(int id); + void Insert(VacationViewModel model); + void Update(VacationViewModel model); void Delete(int id); } } diff --git a/EmployeeManagmentContracts/ViewModels/SalaryViewModel.cs b/EmployeeManagmentContracts/ViewModels/SalaryViewModel.cs index 1aa84dc..97de7b4 100644 --- a/EmployeeManagmentContracts/ViewModels/SalaryViewModel.cs +++ b/EmployeeManagmentContracts/ViewModels/SalaryViewModel.cs @@ -14,6 +14,8 @@ namespace EmployeeManagmentContracts.ViewModels public float? Premium { get; set; } public DateTime? Date { get; set; } public bool Passed { get; set; } - public string EmployeeName { get; set; } = string.Empty; + + public int? EmployeeId { get; set; } + public string? EmployeeName { get; set; } = string.Empty; } } diff --git a/EmployeeManagmentContracts/ViewModels/VacationViewModel.cs b/EmployeeManagmentContracts/ViewModels/VacationViewModel.cs index f89588f..a40b950 100644 --- a/EmployeeManagmentContracts/ViewModels/VacationViewModel.cs +++ b/EmployeeManagmentContracts/ViewModels/VacationViewModel.cs @@ -12,6 +12,7 @@ namespace EmployeeManagmentContracts.ViewModels public DateTime StartData { get; set; } public DateTime EndData { get; set; } public bool Passed { get; set; } - public string EmployeeName { get; set; } = string.Empty; + public int? EmployeeId { get; set; } + public string? EmployeeName { get; set; } = string.Empty; } } diff --git a/EmployeeManagmentDataBaseImplement/Implements/SalaryStorage.cs b/EmployeeManagmentDataBaseImplement/Implements/SalaryStorage.cs index 0856077..8f674d1 100644 --- a/EmployeeManagmentDataBaseImplement/Implements/SalaryStorage.cs +++ b/EmployeeManagmentDataBaseImplement/Implements/SalaryStorage.cs @@ -1,44 +1,125 @@ using EmployeeManagmentContracts.SearchModels; using EmployeeManagmentContracts.StoragesContracts; using EmployeeManagmentContracts.ViewModels; +using EmployeeManagmentDataBaseImplement.Models; using System; using System.Collections.Generic; using System.Linq; -using System.Text; -using System.Threading.Tasks; namespace EmployeeManagmentDataBaseImplement.Implements { public class SalaryStorage : ISalaryStorage { - public void Delete(int id) + public List GetFullList() { - throw new NotImplementedException(); - } + using var context = new EmployeeManagementDbContext(); - public SalaryViewModel? GetElement(int id) - { - throw new NotImplementedException(); + 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(); } public List GetFilteredList(SalarySearchModel model) { - throw new NotImplementedException(); + using var context = new EmployeeManagementDbContext(); + + if (model == null) return new List(); + + 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(); } - public List GetFullList() + public SalaryViewModel? GetElement(int id) { - throw new NotImplementedException(); + 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}" : "Не указано" + }; } public void Insert(SalaryViewModel model) { - throw new NotImplementedException(); + 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(); } public void Update(SalaryViewModel model) { - throw new NotImplementedException(); + 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(); + } } } } diff --git a/EmployeeManagmentDataBaseImplement/Implements/VacationStorage.cs b/EmployeeManagmentDataBaseImplement/Implements/VacationStorage.cs index 0873663..22f9d9d 100644 --- a/EmployeeManagmentDataBaseImplement/Implements/VacationStorage.cs +++ b/EmployeeManagmentDataBaseImplement/Implements/VacationStorage.cs @@ -1,44 +1,116 @@ using EmployeeManagmentContracts.SearchModels; using EmployeeManagmentContracts.StoragesContracts; using EmployeeManagmentContracts.ViewModels; +using EmployeeManagmentDataBaseImplement.Models; using System; using System.Collections.Generic; using System.Linq; -using System.Text; -using System.Threading.Tasks; namespace EmployeeManagmentDataBaseImplement.Implements { public class VacationStorage : IVacationStorage { - public void Delete(int id) + public List GetFullList() { - throw new NotImplementedException(); - } + using var context = new EmployeeManagementDbContext(); - public VacationViewModel? GetElement(int id) - { - throw new NotImplementedException(); + return context.Vacations + .Select(v => new VacationViewModel + { + Id = v.Id, + StartData = v.StartData, + EndData = v.EndData, + Passed = v.Passed, + EmployeeId = v.EmployeesId, + EmployeeName = v.Employee != null ? $"{v.Employee.PhisicalPerson.Surname} {v.Employee.PhisicalPerson.Name}" : "Не указано" + }) + .ToList(); } public List GetFilteredList(VacationSearchModel model) { - throw new NotImplementedException(); + using var context = new EmployeeManagementDbContext(); + + if (model == null) return new List(); + + 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, + EmployeeName = v.Employee != null ? $"{v.Employee.PhisicalPerson.Surname} {v.Employee.PhisicalPerson.Name}" : "Не указано" + }) + .ToList(); } - public List GetFullList() + public VacationViewModel? GetElement(int id) { - throw new NotImplementedException(); + 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, + EmployeeName = entity.Employee != null ? $"{entity.Employee.PhisicalPerson.Surname} {entity.Employee.PhisicalPerson.Name}" : "Не указано" + }; } public void Insert(VacationViewModel model) { - throw new NotImplementedException(); + 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(); } public void Update(VacationViewModel model) { - throw new NotImplementedException(); + 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(); + } } } } diff --git a/EmployeeManagmentView/Employee/Salary/AddSalaryWindow.xaml b/EmployeeManagmentView/Employee/Salary/AddSalaryWindow.xaml index 980b0e1..df78d81 100644 --- a/EmployeeManagmentView/Employee/Salary/AddSalaryWindow.xaml +++ b/EmployeeManagmentView/Employee/Salary/AddSalaryWindow.xaml @@ -1,12 +1,74 @@  + Title="Добавление зарплаты" + Height="500" Width="600" + ResizeMode="NoResize" + WindowStartupLocation="CenterScreen" + Background="#0D2D4F"> + - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +