LabWork6 : everything till storage implementation is done.
This commit is contained in:
parent
6a54bae14d
commit
1467c22510
129
DressAtelierBusinessLogic/BusinessLogic/EmployeeLogic.cs
Normal file
129
DressAtelierBusinessLogic/BusinessLogic/EmployeeLogic.cs
Normal file
@ -0,0 +1,129 @@
|
|||||||
|
using DressAtelierContracts.BindingModels;
|
||||||
|
using DressAtelierContracts.BusinessLogicContracts;
|
||||||
|
using DressAtelierContracts.SearchModels;
|
||||||
|
using DressAtelierContracts.StorageContracts;
|
||||||
|
using DressAtelierContracts.ViewModels;
|
||||||
|
using Microsoft.Extensions.Logging;
|
||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
|
namespace DressAtelierBusinessLogic.BusinessLogic
|
||||||
|
{
|
||||||
|
public class EmployeeLogic : IEmployeeLogic
|
||||||
|
{
|
||||||
|
private readonly ILogger _logger;
|
||||||
|
private readonly IEmployeeStorage _employeeStorage;
|
||||||
|
public EmployeeLogic(ILogger<EmployeeLogic> logger, IEmployeeStorage employeeStorage)
|
||||||
|
{
|
||||||
|
_logger = logger;
|
||||||
|
_employeeStorage = employeeStorage;
|
||||||
|
}
|
||||||
|
public bool Create(EmployeeBindingModel model)
|
||||||
|
{
|
||||||
|
CheckEmployee(model);
|
||||||
|
if(_employeeStorage.Insert(model) == null)
|
||||||
|
{
|
||||||
|
_logger.LogWarning("Insert operation failed");
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
public bool Update(EmployeeBindingModel model)
|
||||||
|
{
|
||||||
|
CheckEmployee(model);
|
||||||
|
if (_employeeStorage.Update(model) == null)
|
||||||
|
{
|
||||||
|
_logger.LogWarning("Update operation failed");
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
public bool Delete(EmployeeBindingModel model)
|
||||||
|
{
|
||||||
|
CheckEmployee(model,false);
|
||||||
|
_logger.LogInformation("Delete. ID:{ID}", model.ID);
|
||||||
|
if (_employeeStorage.Delete(model) == null)
|
||||||
|
{
|
||||||
|
_logger.LogWarning("Delete operation failed");
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
public EmployeeViewModel? ReadElement(EmployeeSearchModel model)
|
||||||
|
{
|
||||||
|
if (model == null)
|
||||||
|
{
|
||||||
|
throw new ArgumentNullException(nameof(model));
|
||||||
|
}
|
||||||
|
_logger.LogInformation("ReadElement. FullName:{FullName}.ID:{ ID}", model.FullName, model.ID);
|
||||||
|
var element = _employeeStorage.GetElement(model);
|
||||||
|
if (element == null)
|
||||||
|
{
|
||||||
|
_logger.LogWarning("ReadElement element not found");
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
_logger.LogInformation("ReadElement find. ID:{ID}", element.ID);
|
||||||
|
return element;
|
||||||
|
}
|
||||||
|
|
||||||
|
public List<EmployeeViewModel>? ReadList(EmployeeSearchModel? model)
|
||||||
|
{
|
||||||
|
_logger.LogInformation("ReadList. FullName:{FullName}. ID:{ ID}", model?.FullName, model?.ID);
|
||||||
|
|
||||||
|
var list = model == null ? _employeeStorage.GetFullList() : _employeeStorage.GetFilteredList(model);
|
||||||
|
|
||||||
|
if (list == null)
|
||||||
|
{
|
||||||
|
_logger.LogWarning("ReadList return null list");
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
_logger.LogInformation("ReadList. Count:{Count}", list.Count);
|
||||||
|
return list;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void CheckEmployee(EmployeeBindingModel model, bool withParams = true)
|
||||||
|
{
|
||||||
|
if (model == null)
|
||||||
|
{
|
||||||
|
throw new ArgumentNullException(nameof(model));
|
||||||
|
}
|
||||||
|
if (!withParams)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (string.IsNullOrEmpty(model.FullName))
|
||||||
|
{
|
||||||
|
throw new ArgumentNullException("Invalid fullname of employee", nameof(model.FullName));
|
||||||
|
}
|
||||||
|
if (string.IsNullOrEmpty(model.Occupation))
|
||||||
|
{
|
||||||
|
throw new ArgumentNullException("Invalid occupation of employee", nameof(model.Occupation));
|
||||||
|
}
|
||||||
|
if (string.IsNullOrEmpty(model.WorkExperience.ToString()))
|
||||||
|
{
|
||||||
|
throw new ArgumentNullException("Invalid email of employee", nameof(model.WorkExperience));
|
||||||
|
}
|
||||||
|
if (string.IsNullOrEmpty(model.Password))
|
||||||
|
{
|
||||||
|
throw new ArgumentNullException("Invalid password of employee", nameof(model.Password));
|
||||||
|
}
|
||||||
|
_logger.LogInformation("Employee. FullName:{ FullName}. WorkExperience:{ WorkExperience}. Occupation:{ Occupation}. ID: { ID} ", model.FullName, model.WorkExperience,model.Occupation, model.ID);
|
||||||
|
|
||||||
|
var element = _employeeStorage.GetElement(new EmployeeSearchModel
|
||||||
|
{
|
||||||
|
FullName = model.FullName
|
||||||
|
});
|
||||||
|
|
||||||
|
if (element != null && element.ID != model.ID)
|
||||||
|
{
|
||||||
|
throw new InvalidOperationException("Employee with such fullname already exists.");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
18
DressAtelierContracts/BindingModels/EmployeeBindingModel.cs
Normal file
18
DressAtelierContracts/BindingModels/EmployeeBindingModel.cs
Normal file
@ -0,0 +1,18 @@
|
|||||||
|
using DressAtelierDataModels.Models;
|
||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
|
namespace DressAtelierContracts.BindingModels
|
||||||
|
{
|
||||||
|
public class EmployeeBindingModel : IEmployeeModel
|
||||||
|
{
|
||||||
|
public int ID { get; set; }
|
||||||
|
public string FullName { get; set; } = string.Empty;
|
||||||
|
public string Password { get; set; } = string.Empty;
|
||||||
|
public int WorkExperience { get; set; }
|
||||||
|
public string Occupation { get; set; } = string.Empty;
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,12 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
|
namespace DressAtelierContracts.BusinessLogicContracts
|
||||||
|
{
|
||||||
|
internal interface IEmployeeLogic
|
||||||
|
{
|
||||||
|
}
|
||||||
|
}
|
15
DressAtelierContracts/SearchModels/EmployeeSearchModel.cs
Normal file
15
DressAtelierContracts/SearchModels/EmployeeSearchModel.cs
Normal file
@ -0,0 +1,15 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
|
namespace DressAtelierContracts.SearchModels
|
||||||
|
{
|
||||||
|
public class EmployeeSearchModel
|
||||||
|
{
|
||||||
|
public int? ID { get; set; }
|
||||||
|
public string? FullName { get; set; }
|
||||||
|
public string? Password { get; set; }
|
||||||
|
}
|
||||||
|
}
|
21
DressAtelierContracts/StorageContracts/IEmployeeStorage.cs
Normal file
21
DressAtelierContracts/StorageContracts/IEmployeeStorage.cs
Normal file
@ -0,0 +1,21 @@
|
|||||||
|
using DressAtelierContracts.BindingModels;
|
||||||
|
using DressAtelierContracts.SearchModels;
|
||||||
|
using DressAtelierContracts.ViewModels;
|
||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
|
namespace DressAtelierContracts.StorageContracts
|
||||||
|
{
|
||||||
|
public interface IEmployeeStorage
|
||||||
|
{
|
||||||
|
List<EmployeeViewModel> GetFullList();
|
||||||
|
List<EmployeeViewModel> GetFilteredList(EmployeeSearchModel model);
|
||||||
|
EmployeeViewModel? GetElement(EmployeeSearchModel model);
|
||||||
|
EmployeeViewModel? Insert(EmployeeBindingModel model);
|
||||||
|
EmployeeViewModel? Update(EmployeeBindingModel model);
|
||||||
|
EmployeeViewModel? Delete(EmployeeBindingModel model);
|
||||||
|
}
|
||||||
|
}
|
23
DressAtelierContracts/ViewModels/EmployeeViewModel.cs
Normal file
23
DressAtelierContracts/ViewModels/EmployeeViewModel.cs
Normal file
@ -0,0 +1,23 @@
|
|||||||
|
using DressAtelierDataModels.Models;
|
||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.ComponentModel;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
|
namespace DressAtelierContracts.ViewModels
|
||||||
|
{
|
||||||
|
public class EmployeeViewModel : IEmployeeModel
|
||||||
|
{
|
||||||
|
public int ID { get; set; }
|
||||||
|
[DisplayName("Employee's fullname")]
|
||||||
|
public string FullName { get; set; } = string.Empty;
|
||||||
|
[DisplayName("Password")]
|
||||||
|
public string Password { get; set; } = string.Empty;
|
||||||
|
[DisplayName("WorkExperience")]
|
||||||
|
public int WorkExperience { get; set; }
|
||||||
|
[DisplayName("Occupation")]
|
||||||
|
public string Occupation { get; set; } = string.Empty;
|
||||||
|
}
|
||||||
|
}
|
16
DressAtelierDataModels/Models/IEmployeeModel.cs
Normal file
16
DressAtelierDataModels/Models/IEmployeeModel.cs
Normal file
@ -0,0 +1,16 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
|
namespace DressAtelierDataModels.Models
|
||||||
|
{
|
||||||
|
public interface IEmployeeModel
|
||||||
|
{
|
||||||
|
string FullName { get; set; }
|
||||||
|
string Password { get; set; }
|
||||||
|
int WorkExperience { get; set; }
|
||||||
|
string Occupation { get; set; }
|
||||||
|
}
|
||||||
|
}
|
Loading…
x
Reference in New Issue
Block a user