Исполнитель создал Contracts
This commit is contained in:
parent
4f5fec22bf
commit
448a1e9ff1
@ -6,4 +6,12 @@
|
||||
<Nullable>enable</Nullable>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="Microsoft.Extensions.Logging.Abstractions" Version="8.0.1" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\Contracts\Contracts.csproj" />
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
||||
|
110
Course/BusinessLogic/DetailLogic.cs
Normal file
110
Course/BusinessLogic/DetailLogic.cs
Normal file
@ -0,0 +1,110 @@
|
||||
using Contracts.BindingModels;
|
||||
using Contracts.BusinessLogicsContracts;
|
||||
using Contracts.SearchModels;
|
||||
using Contracts.StoragesContracts;
|
||||
using Contracts.ViewModels;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using System.Xml.Linq;
|
||||
|
||||
namespace BusinessLogic
|
||||
{
|
||||
public class DetailLogic : IDetailLogic
|
||||
{
|
||||
private readonly ILogger _logger;
|
||||
private readonly IDetailStorage _detailStorage;
|
||||
public DetailLogic(ILogger<DetailLogic> logger, IDetailStorage detailStorage)
|
||||
{
|
||||
_logger = logger;
|
||||
_detailStorage = detailStorage;
|
||||
}
|
||||
public List<DetailViewModel>? ReadList(DetailSearchModel? model)
|
||||
{
|
||||
_logger.LogInformation("ReadList. DetailName:{name}. Id:{Id}", model.Name, model.Id);
|
||||
var list = model == null ? _detailStorage.GetFullList() : _detailStorage.GetFilteredList(model);
|
||||
if (list == null)
|
||||
{
|
||||
_logger.LogWarning("ReadList return null list");
|
||||
return null;
|
||||
}
|
||||
_logger.LogWarning("ReadList. Count:{Count}", list.Count);
|
||||
return list;
|
||||
}
|
||||
public DetailViewModel? ReadElement(DetailSearchModel? model)
|
||||
{
|
||||
if (model == null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(model));
|
||||
}
|
||||
_logger.LogInformation("ReadElement. DetailName:{Name}. Id:{Id}", model.Name, model.Id);
|
||||
var elem = _detailStorage.GetElement(model);
|
||||
if (elem == null)
|
||||
{
|
||||
_logger.LogWarning("ReadElement element not found");
|
||||
return null;
|
||||
}
|
||||
_logger.LogInformation("ReadElement find. Id:{Id}", elem.Id);
|
||||
return elem;
|
||||
}
|
||||
|
||||
|
||||
private void CheckModel(DetailBindingModel? model, bool withParams = true)
|
||||
{
|
||||
if (model == null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(model));
|
||||
}
|
||||
if (!withParams)
|
||||
{
|
||||
return;
|
||||
}
|
||||
if (string.IsNullOrEmpty(model.Name))
|
||||
{
|
||||
throw new ArgumentNullException("Нет названия детали", nameof(model.Name));
|
||||
}
|
||||
if (model.Cost <= 0)
|
||||
{
|
||||
throw new ArgumentNullException("Цена детали должна быть больше 0", nameof(model.Cost));
|
||||
}
|
||||
_logger.LogInformation("Detail. DetailName:{Name}. Cost:{Cost}. Id:{Id}", model.Name, model.Cost, model.Id);
|
||||
var elem = _detailStorage.GetElement(new DetailSearchModel
|
||||
{
|
||||
Name = model.Name
|
||||
});
|
||||
if (elem != null && elem.Id != model.Id)
|
||||
{
|
||||
throw new InvalidOperationException("Деталь с таким названием уже существует");
|
||||
}
|
||||
}
|
||||
public bool Create(DetailBindingModel? model)
|
||||
{
|
||||
CheckModel(model);
|
||||
if (_detailStorage.Insert(model!) == null)
|
||||
{
|
||||
_logger.LogWarning("Insert error");
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
public bool Update(DetailBindingModel? model)
|
||||
{
|
||||
CheckModel(model);
|
||||
if (_detailStorage.Update(model!) == null)
|
||||
{
|
||||
_logger.LogWarning("Update error");
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
public bool Delete(DetailBindingModel? model)
|
||||
{
|
||||
CheckModel(model, false);
|
||||
_logger.LogInformation("Delete Id:{Id}", model!.Id);
|
||||
if (_detailStorage.Delete(model!) == null)
|
||||
{
|
||||
_logger.LogWarning("Delete error");
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
14
Course/Contracts/BindingModels/ImplementerBindingModel.cs
Normal file
14
Course/Contracts/BindingModels/ImplementerBindingModel.cs
Normal file
@ -0,0 +1,14 @@
|
||||
|
||||
using DataModels.Models;
|
||||
|
||||
namespace Contracts.BindingModels
|
||||
{
|
||||
public class ImplementerBindingModel : IImplementerModel
|
||||
{
|
||||
public int Id { get; set; }
|
||||
public string Email { get; set; } = string.Empty;
|
||||
public string Name { get; set; } = string.Empty;
|
||||
public string Login { get; set; } = string.Empty;
|
||||
public string Password { get; set; } = string.Empty;
|
||||
}
|
||||
}
|
15
Course/Contracts/BusinessLogicsContracts/IDetailLogic.cs
Normal file
15
Course/Contracts/BusinessLogicsContracts/IDetailLogic.cs
Normal file
@ -0,0 +1,15 @@
|
||||
using Contracts.BindingModels;
|
||||
using Contracts.SearchModels;
|
||||
using Contracts.ViewModels;
|
||||
|
||||
namespace Contracts.BusinessLogicsContracts
|
||||
{
|
||||
public interface IDetailLogic
|
||||
{
|
||||
List<DetailViewModel>? ReadList(DetailSearchModel? model);
|
||||
DetailViewModel? ReadElement(DetailSearchModel? model);
|
||||
bool Create(DetailBindingModel? model);
|
||||
bool Update(DetailBindingModel? model);
|
||||
bool Delete(DetailBindingModel? model);
|
||||
}
|
||||
}
|
@ -0,0 +1,15 @@
|
||||
using Contracts.BindingModels;
|
||||
using Contracts.SearchModels;
|
||||
using Contracts.ViewModels;
|
||||
|
||||
namespace Contracts.BusinessLogicsContracts
|
||||
{
|
||||
public interface IImplementerLogic
|
||||
{
|
||||
List<ImplementerViewModel>? ReadList(ImplementerSearchModel? model);
|
||||
ImplementerViewModel? ReadElement(ImplementerSearchModel? model);
|
||||
bool Create(ImplementerBindingModel? model);
|
||||
bool Update(ImplementerViewModel? model);
|
||||
bool Delete(ImplementerViewModel? model);
|
||||
}
|
||||
}
|
15
Course/Contracts/BusinessLogicsContracts/IProductLogic.cs
Normal file
15
Course/Contracts/BusinessLogicsContracts/IProductLogic.cs
Normal file
@ -0,0 +1,15 @@
|
||||
using Contracts.BindingModels;
|
||||
using Contracts.SearchModels;
|
||||
using Contracts.ViewModels;
|
||||
|
||||
namespace Contracts.BusinessLogicsContracts
|
||||
{
|
||||
public interface IProductLogic
|
||||
{
|
||||
List<ProductViewModel>? ReadList(ProductSearchModel? model);
|
||||
ProductViewModel? ReadElement(ProductSearchModel? model);
|
||||
bool Create(ProductBindingModel? model);
|
||||
bool Update(ProductBindingModel? model);
|
||||
bool Delete(ProductBindingModel? model);
|
||||
}
|
||||
}
|
15
Course/Contracts/BusinessLogicsContracts/IProductionLogic.cs
Normal file
15
Course/Contracts/BusinessLogicsContracts/IProductionLogic.cs
Normal file
@ -0,0 +1,15 @@
|
||||
using Contracts.BindingModels;
|
||||
using Contracts.SearchModels;
|
||||
using Contracts.ViewModels;
|
||||
|
||||
namespace Contracts.BusinessLogicsContracts
|
||||
{
|
||||
public interface IProductionLogic
|
||||
{
|
||||
List<ProductionViewModel>? ReadList(ProductionSearchModel? model);
|
||||
ProductionViewModel? ReadElement(ProductionSearchModel? model);
|
||||
bool Create(ProductionBindingModel? model);
|
||||
bool Update(ProductionViewModel? model);
|
||||
bool Delete(ProductionViewModel? model);
|
||||
}
|
||||
}
|
@ -6,13 +6,6 @@
|
||||
<Nullable>enable</Nullable>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<Folder Include="BusinessLogicsContracts\" />
|
||||
<Folder Include="SearchModels\" />
|
||||
<Folder Include="StoragesContracts\" />
|
||||
<Folder Include="ViewModels\" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\DataModels\DataModels.csproj" />
|
||||
</ItemGroup>
|
||||
|
15
Course/Contracts/SearchModels/DetailSearchModel.cs
Normal file
15
Course/Contracts/SearchModels/DetailSearchModel.cs
Normal file
@ -0,0 +1,15 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace Contracts.SearchModels
|
||||
{
|
||||
public class DetailSearchModel
|
||||
{
|
||||
public int? Id { get; set; }
|
||||
public string? Name { get; set; }
|
||||
public int? UserId { get; set; }
|
||||
}
|
||||
}
|
14
Course/Contracts/SearchModels/ImplementerSearchModel.cs
Normal file
14
Course/Contracts/SearchModels/ImplementerSearchModel.cs
Normal file
@ -0,0 +1,14 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace Contracts.SearchModels
|
||||
{
|
||||
public class ImplementerSearchModel
|
||||
{
|
||||
public int? Id { get; set; }
|
||||
public string? Login { get; set; }
|
||||
}
|
||||
}
|
15
Course/Contracts/SearchModels/ProductSearchModel.cs
Normal file
15
Course/Contracts/SearchModels/ProductSearchModel.cs
Normal file
@ -0,0 +1,15 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace Contracts.SearchModels
|
||||
{
|
||||
public class ProductSearchModel
|
||||
{
|
||||
public int? Id { get; set; }
|
||||
public string? Name { get; set; }
|
||||
public int? UserId { get; set; }
|
||||
}
|
||||
}
|
15
Course/Contracts/SearchModels/ProductionSearchModel.cs
Normal file
15
Course/Contracts/SearchModels/ProductionSearchModel.cs
Normal file
@ -0,0 +1,15 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace Contracts.SearchModels
|
||||
{
|
||||
public class ProductionSearchModel
|
||||
{
|
||||
public int? Id { get; set; }
|
||||
public string? Name { get; set; }
|
||||
public int? UserId { get; set; }
|
||||
}
|
||||
}
|
16
Course/Contracts/StoragesContracts/IDetailStorage.cs
Normal file
16
Course/Contracts/StoragesContracts/IDetailStorage.cs
Normal file
@ -0,0 +1,16 @@
|
||||
using Contracts.BindingModels;
|
||||
using Contracts.SearchModels;
|
||||
using Contracts.ViewModels;
|
||||
|
||||
namespace Contracts.StoragesContracts
|
||||
{
|
||||
public interface IDetailStorage
|
||||
{
|
||||
List<DetailViewModel> GetFullList();
|
||||
List<DetailViewModel> GetFilteredList(DetailSearchModel model);
|
||||
DetailViewModel? GetElement(DetailSearchModel model);
|
||||
DetailViewModel? Insert(DetailBindingModel model);
|
||||
DetailViewModel? Update(DetailBindingModel model);
|
||||
DetailViewModel? Delete(DetailBindingModel model);
|
||||
}
|
||||
}
|
17
Course/Contracts/StoragesContracts/IImplementerStorage.cs
Normal file
17
Course/Contracts/StoragesContracts/IImplementerStorage.cs
Normal file
@ -0,0 +1,17 @@
|
||||
using Contracts.BindingModels;
|
||||
using Contracts.SearchModels;
|
||||
using Contracts.ViewModels;
|
||||
|
||||
namespace Contracts.StoragesContracts
|
||||
{
|
||||
public interface IImplementerStorage
|
||||
{
|
||||
List<ImplementerViewModel> GetFullList();
|
||||
List<ImplementerViewModel> GetFilteredList(ImplementerSearchModel model);
|
||||
ImplementerViewModel? GetElement(ImplementerSearchModel model);
|
||||
ImplementerViewModel? Insert(ImplementerBindingModel model);
|
||||
ImplementerViewModel? Update(ImplementerBindingModel model);
|
||||
ImplementerViewModel? Delete(ImplementerBindingModel model);
|
||||
}
|
||||
}
|
||||
|
16
Course/Contracts/StoragesContracts/IProductStorage.cs
Normal file
16
Course/Contracts/StoragesContracts/IProductStorage.cs
Normal file
@ -0,0 +1,16 @@
|
||||
using Contracts.BindingModels;
|
||||
using Contracts.SearchModels;
|
||||
using Contracts.ViewModels;
|
||||
|
||||
namespace Contracts.StoragesContracts
|
||||
{
|
||||
public interface IProductStorage
|
||||
{
|
||||
List<ProductViewModel> GetFullList();
|
||||
List<ProductViewModel> GetFilteredList(ProductSearchModel model);
|
||||
ProductViewModel? GetElement(ProductSearchModel model);
|
||||
ProductViewModel? Insert(ProductBindingModel model);
|
||||
ProductViewModel? Update(ProductBindingModel model);
|
||||
ProductViewModel? Delete(ProductBindingModel model);
|
||||
}
|
||||
}
|
17
Course/Contracts/StoragesContracts/IProductionStorage.cs
Normal file
17
Course/Contracts/StoragesContracts/IProductionStorage.cs
Normal file
@ -0,0 +1,17 @@
|
||||
using Contracts.BindingModels;
|
||||
using Contracts.SearchModels;
|
||||
using Contracts.ViewModels;
|
||||
|
||||
namespace Contracts.StoragesContracts
|
||||
{
|
||||
public interface IProductionStorage
|
||||
{
|
||||
List<ProductionViewModel> GetFullList();
|
||||
List<ProductionViewModel> GetFilteredList(ProductionSearchModel model);
|
||||
ProductionViewModel? GetElement(ProductionSearchModel model);
|
||||
ProductionViewModel? Insert(ProductionBindingModel model);
|
||||
ProductionViewModel? Update(ProductionBindingModel model);
|
||||
ProductionViewModel? Delete(ProductionBindingModel model);
|
||||
}
|
||||
}
|
||||
|
21
Course/Contracts/ViewModels/DetailViewModel.cs
Normal file
21
Course/Contracts/ViewModels/DetailViewModel.cs
Normal file
@ -0,0 +1,21 @@
|
||||
using DataModels.Models;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.ComponentModel;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace Contracts.ViewModels
|
||||
{
|
||||
public class DetailViewModel : IDetailModel
|
||||
{
|
||||
public int Id { get; set; }
|
||||
[DisplayName("Название детали")]
|
||||
public string Name { get; set; } = string.Empty;
|
||||
[DisplayName("Цена детали")]
|
||||
public double Cost { get; set; }
|
||||
public int UserId { get; set; }
|
||||
|
||||
}
|
||||
}
|
23
Course/Contracts/ViewModels/ImplementerViewModel.cs
Normal file
23
Course/Contracts/ViewModels/ImplementerViewModel.cs
Normal file
@ -0,0 +1,23 @@
|
||||
using DataModels.Models;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.ComponentModel;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace Contracts.ViewModels
|
||||
{
|
||||
public class ImplementerViewModel : IImplementerModel
|
||||
{
|
||||
public int Id { get; set; }
|
||||
[DisplayName("Имя исполнителя")]
|
||||
public string Name { get; set; } = string.Empty;
|
||||
[DisplayName("Почта")]
|
||||
public string Email { get; set; } = string.Empty;
|
||||
[DisplayName("Логин")]
|
||||
public string Login { get; set; } = string.Empty;
|
||||
[DisplayName("Пароль")]
|
||||
public string Password { get; set; } = string.Empty;
|
||||
}
|
||||
}
|
20
Course/Contracts/ViewModels/ProductViewModel.cs
Normal file
20
Course/Contracts/ViewModels/ProductViewModel.cs
Normal file
@ -0,0 +1,20 @@
|
||||
using DataModels.Models;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.ComponentModel;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace Contracts.ViewModels
|
||||
{
|
||||
public class ProductViewModel : IProductModel
|
||||
{
|
||||
public int Id { get; set; }
|
||||
[DisplayName("Название изделия")]
|
||||
public string Name { get; set; } = string.Empty;
|
||||
[DisplayName("Цена изделия")]
|
||||
public double Cost { get; set; }
|
||||
public int UserId { get; set; }
|
||||
}
|
||||
}
|
20
Course/Contracts/ViewModels/ProductionViewModel.cs
Normal file
20
Course/Contracts/ViewModels/ProductionViewModel.cs
Normal file
@ -0,0 +1,20 @@
|
||||
using DataModels.Models;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.ComponentModel;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace Contracts.ViewModels
|
||||
{
|
||||
public class ProductionViewModel : IProductionModel
|
||||
{
|
||||
public int Id { get; set; }
|
||||
[DisplayName("Название производства")]
|
||||
public string Name { get; set; } = string.Empty;
|
||||
[DisplayName("Цена производства")]
|
||||
public double Cost { get; set; }
|
||||
public int UserId { get; set; }
|
||||
}
|
||||
}
|
@ -1,4 +1,4 @@
|
||||
namespace DataModels.Models
|
||||
namespace DataModels
|
||||
{
|
||||
public interface IUserModel
|
||||
{
|
6
Course/DataModels/Models/IImplementerModel.cs
Normal file
6
Course/DataModels/Models/IImplementerModel.cs
Normal file
@ -0,0 +1,6 @@
|
||||
namespace DataModels.Models
|
||||
{
|
||||
public interface IImplementerModel : IUserModel
|
||||
{
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user