Compare commits
1 Commits
LabWork07_
...
LabWork08_
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
1052f66f35 |
@@ -3,6 +3,7 @@ using FurnitureAssemblyContracts.Exceptions;
|
||||
using FurnitureAssemblyContracts.Extentions;
|
||||
using FurnitureAssemblyContracts.Infrastructure;
|
||||
using FurnitureAssemblyContracts.Resources;
|
||||
using Microsoft.AspNetCore.Mvc.Internal;
|
||||
using Microsoft.Extensions.Localization;
|
||||
|
||||
namespace FurnitureAssemblyContracts.DataModels;
|
||||
@@ -15,6 +16,8 @@ internal class ComponentDataModel(string id, string name, ComponentType type, st
|
||||
public string? PrevPrevName { get; private set; } = prevPrevName;
|
||||
public ComponentType Type { get; private set; } = type;
|
||||
|
||||
public ComponentDataModel() : this(string.Empty, string.Empty, ComponentType.None) { }
|
||||
|
||||
public void Validate(IStringLocalizer<Messages> localizer)
|
||||
{
|
||||
if (Id.IsEmpty())
|
||||
|
||||
@@ -12,6 +12,8 @@ internal class FurnitureComponentDataModel(string furnitureId, string componentI
|
||||
public string ComponentId { get; private set; } = componentId;
|
||||
public int Count { get; private set; } = count;
|
||||
|
||||
public FurnitureComponentDataModel() : this(string.Empty, string.Empty, 0) { }
|
||||
|
||||
public void Validate(IStringLocalizer<Messages> localizer)
|
||||
{
|
||||
if (FurnitureId.IsEmpty())
|
||||
|
||||
@@ -13,6 +13,8 @@ internal class FurnitureDataModel(string id, string name, int weight, List<Furni
|
||||
public int Weight { get; private set; } = weight;
|
||||
public List<FurnitureComponentDataModel> Components { get; private set; } = components;
|
||||
|
||||
public FurnitureDataModel() : this(string.Empty, string.Empty, 0, new List<FurnitureComponentDataModel>()) { }
|
||||
|
||||
public void Validate(IStringLocalizer<Messages> localizer)
|
||||
{
|
||||
if (Id.IsEmpty())
|
||||
|
||||
@@ -33,6 +33,8 @@ internal class ManifacturingFurnitureDataModel : IValidation
|
||||
_furniture = furniture;
|
||||
}
|
||||
|
||||
public ManifacturingFurnitureDataModel() : this(string.Empty, string.Empty, 0, string.Empty) { }
|
||||
|
||||
public void Validate(IStringLocalizer<Messages> localizer)
|
||||
{
|
||||
if (Id.IsEmpty())
|
||||
|
||||
@@ -2,18 +2,22 @@
|
||||
using FurnitureAssemblyContracts.Exceptions;
|
||||
using FurnitureAssemblyContracts.Extentions;
|
||||
using FurnitureAssemblyContracts.Infrastructure;
|
||||
using FurnitureAssemblyContracts.Mapper;
|
||||
using FurnitureAssemblyContracts.Resources;
|
||||
using Microsoft.Extensions.Localization;
|
||||
|
||||
namespace FurnitureAssemblyContracts.DataModels;
|
||||
|
||||
internal class PostDataModel(string postid, string postName, PostType postType, double salary) : IValidation
|
||||
{
|
||||
{
|
||||
[AlternativeName("PostId")]
|
||||
public string Id { get; private set; } = postid;
|
||||
public string PostName { get; private set; } = postName;
|
||||
public PostType PostType { get; private set; } = postType;
|
||||
public double Salary { get; private set; } = salary;
|
||||
|
||||
public PostDataModel() : this(string.Empty, string.Empty, PostType.None, 0) { }
|
||||
|
||||
public void Validate(IStringLocalizer<Messages> localizer)
|
||||
{
|
||||
if (Id.IsEmpty())
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
using FurnitureAssemblyContracts.Exceptions;
|
||||
using FurnitureAssemblyContracts.Extentions;
|
||||
using FurnitureAssemblyContracts.Infrastructure;
|
||||
using FurnitureAssemblyContracts.Mapper;
|
||||
using FurnitureAssemblyContracts.Resources;
|
||||
using Microsoft.Extensions.Localization;
|
||||
|
||||
@@ -8,9 +9,10 @@ namespace FurnitureAssemblyContracts.DataModels;
|
||||
|
||||
internal class SalaryDataModel(string workerId, DateTime salaryDate, double workerSalary) : IValidation
|
||||
{
|
||||
private readonly WorkerDataModel? _worker;
|
||||
private WorkerDataModel? _worker;
|
||||
public string WorkerId { get; private set; } = workerId;
|
||||
public DateTime SalaryDate { get; private set; } = salaryDate.ToUniversalTime();
|
||||
[AlternativeName("WorkerSalary")]
|
||||
public double Salary { get; private set; } = workerSalary;
|
||||
public string WorkerFIO => _worker?.FIO ?? string.Empty;
|
||||
|
||||
@@ -19,6 +21,8 @@ internal class SalaryDataModel(string workerId, DateTime salaryDate, double work
|
||||
_worker = worker;
|
||||
}
|
||||
|
||||
public SalaryDataModel() : this(string.Empty, DateTime.UtcNow, 0) { }
|
||||
|
||||
public void Validate(IStringLocalizer<Messages> localizer)
|
||||
{
|
||||
if (WorkerId.IsEmpty())
|
||||
|
||||
@@ -7,12 +7,13 @@ using Newtonsoft.Json.Linq;
|
||||
using Newtonsoft.Json;
|
||||
using FurnitureAssemblyContracts.Resources;
|
||||
using Microsoft.Extensions.Localization;
|
||||
using FurnitureAssemblyContracts.Mapper;
|
||||
|
||||
namespace FurnitureAssemblyContracts.DataModels;
|
||||
|
||||
internal class WorkerDataModel(string id, string fio, string postId, DateTime birthDate, DateTime employmentDate, bool isDeleted, PostConfiguration configuration) : IValidation
|
||||
{
|
||||
private readonly PostDataModel? _post;
|
||||
private PostDataModel? _post;
|
||||
|
||||
public string Id { get; private set; } = id;
|
||||
|
||||
@@ -25,8 +26,11 @@ internal class WorkerDataModel(string id, string fio, string postId, DateTime bi
|
||||
public DateTime EmploymentDate { get; private set; } = employmentDate.ToUniversalTime();
|
||||
|
||||
public bool IsDeleted { get; private set; } = isDeleted;
|
||||
|
||||
|
||||
public string PostName => _post?.PostName ?? string.Empty;
|
||||
|
||||
[AlternativeName("ConfigurationJson")]
|
||||
[PostProcessing(MappingCallMethodName = "ParseJson")]
|
||||
public PostConfiguration ConfigurationModel { get; private set; } = configuration;
|
||||
|
||||
|
||||
@@ -35,19 +39,8 @@ internal class WorkerDataModel(string id, string fio, string postId, DateTime bi
|
||||
_post = post;
|
||||
}
|
||||
|
||||
public WorkerDataModel(string id, string fio, string postId, DateTime birthDate, DateTime employmentDate, string configurationJson) : this(id, fio, postId, birthDate, employmentDate, false, (PostConfiguration)null)
|
||||
{
|
||||
var obj = JToken.Parse(configurationJson);
|
||||
if (obj is not null)
|
||||
{
|
||||
ConfigurationModel = obj.Value<string>("Type") switch
|
||||
{
|
||||
nameof(BuilderPostConfiguration) => JsonConvert.DeserializeObject<BuilderPostConfiguration>(configurationJson)!,
|
||||
nameof(ChiefPostConfiguration) => JsonConvert.DeserializeObject<ChiefPostConfiguration>(configurationJson)!,
|
||||
_ => JsonConvert.DeserializeObject<PostConfiguration>(configurationJson)!,
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
public WorkerDataModel() : this(string.Empty, string.Empty, string.Empty, DateTime.UtcNow, DateTime.UtcNow, false, null) {}
|
||||
|
||||
public void Validate(IStringLocalizer<Messages> localizer)
|
||||
{
|
||||
@@ -76,4 +69,19 @@ internal class WorkerDataModel(string id, string fio, string postId, DateTime bi
|
||||
if (ConfigurationModel!.Rate <= 0)
|
||||
throw new ValidationException(string.Format(localizer["ValidationExceptionMessageLessOrEqualZero"], "Rate"));
|
||||
}
|
||||
|
||||
private PostConfiguration? ParseJson(string configurationJson)
|
||||
{
|
||||
var obj = JToken.Parse(configurationJson);
|
||||
if (obj is not null)
|
||||
{
|
||||
return obj.Value<string>("Type") switch
|
||||
{
|
||||
nameof(BuilderPostConfiguration) => JsonConvert.DeserializeObject<BuilderPostConfiguration>(configurationJson)!,
|
||||
nameof(ChiefPostConfiguration) => JsonConvert.DeserializeObject<ChiefPostConfiguration>(configurationJson)!,
|
||||
_ => JsonConvert.DeserializeObject<PostConfiguration>(configurationJson)!,
|
||||
};
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,7 @@
|
||||
namespace FurnitureAssemblyContracts.Mapper;
|
||||
|
||||
[AttributeUsage(AttributeTargets.Property, AllowMultiple = true)]
|
||||
class AlternativeNameAttribute(string alternativeName) : Attribute
|
||||
{
|
||||
public string AlternativeName { get; set; } = alternativeName;
|
||||
}
|
||||
@@ -0,0 +1,242 @@
|
||||
using System.Collections;
|
||||
using System.Reflection;
|
||||
|
||||
namespace FurnitureAssemblyContracts.Mapper;
|
||||
|
||||
internal class CustomMapper
|
||||
{
|
||||
public static To MapObject<To>(object obj, To newObject)
|
||||
{
|
||||
ArgumentNullException.ThrowIfNull(obj);
|
||||
ArgumentNullException.ThrowIfNull(newObject);
|
||||
var typeFrom = obj.GetType();
|
||||
var typeTo = newObject.GetType();
|
||||
var propertiesFrom = typeFrom.GetProperties().Where(x => x.CanRead).ToArray();
|
||||
foreach (var property in typeTo.GetProperties().Where(x => x.CanWrite))
|
||||
{
|
||||
if (property.GetCustomAttribute<IgnoreAttribute>() != null)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
var propertyFrom = TryGetPropertyFrom(property, propertiesFrom);
|
||||
if (propertyFrom is null)
|
||||
{
|
||||
FindAndMapDefaultValue(property, newObject);
|
||||
continue;
|
||||
}
|
||||
|
||||
var fromValue = propertyFrom.GetValue(obj);
|
||||
var postProcessingAttribute = property.GetCustomAttribute<PostProcessingAttribute>();
|
||||
if (postProcessingAttribute is not null)
|
||||
{
|
||||
var value = PostProcessing(fromValue, postProcessingAttribute, newObject);
|
||||
if (value is not null)
|
||||
{
|
||||
property.SetValue(newObject, value);
|
||||
}
|
||||
continue;
|
||||
}
|
||||
|
||||
if (propertyFrom.PropertyType.IsGenericType && propertyFrom.PropertyType.Name.StartsWith("List") && fromValue is not null)
|
||||
{
|
||||
fromValue = MapListOfObjects(property, fromValue);
|
||||
}
|
||||
|
||||
if (fromValue is not null)
|
||||
{
|
||||
if (property.PropertyType.IsEnum && fromValue != null)
|
||||
{
|
||||
try
|
||||
{
|
||||
var enumValue = Enum.Parse(property.PropertyType, fromValue.ToString()!);
|
||||
property.SetValue(newObject, enumValue);
|
||||
}
|
||||
catch
|
||||
{
|
||||
continue;
|
||||
}
|
||||
}
|
||||
else if (propertyFrom.PropertyType.IsEnum && fromValue != null)
|
||||
{
|
||||
property.SetValue(newObject, fromValue.ToString());
|
||||
}
|
||||
else {
|
||||
property.SetValue(newObject, fromValue);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
var fieldsTo = typeTo.GetFields(BindingFlags.Instance | BindingFlags.NonPublic | BindingFlags.Public);
|
||||
var fieldsFrom = typeFrom.GetFields(BindingFlags.Instance | BindingFlags.NonPublic | BindingFlags.Public);
|
||||
|
||||
foreach (var field in fieldsTo)
|
||||
{
|
||||
if (field.Name.Contains("k__BackingField"))
|
||||
continue;
|
||||
|
||||
if (field.GetCustomAttribute<IgnoreAttribute>() != null)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
var sourceField = fieldsFrom.FirstOrDefault(f => f.Name == field.Name);
|
||||
object? fromValue = null;
|
||||
|
||||
if (sourceField is not null)
|
||||
{
|
||||
fromValue = sourceField.GetValue(obj);
|
||||
}
|
||||
else
|
||||
{
|
||||
var propertyName = field.Name.TrimStart('_');
|
||||
var sourceProperty = typeFrom.GetProperty(propertyName, BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic);
|
||||
if (sourceProperty is not null && sourceProperty.CanRead)
|
||||
{
|
||||
fromValue = sourceProperty.GetValue(obj);
|
||||
}
|
||||
}
|
||||
|
||||
if (fromValue is null)
|
||||
continue;
|
||||
|
||||
if (field.FieldType.IsClass && field.FieldType != typeof(string))
|
||||
{
|
||||
try
|
||||
{
|
||||
var nested = Activator.CreateInstance(field.FieldType)!;
|
||||
var mapped = MapObject(fromValue, nested);
|
||||
RemoveReadOnly(field);
|
||||
field.SetValue(newObject, mapped);
|
||||
continue;
|
||||
}
|
||||
catch
|
||||
{
|
||||
continue;
|
||||
}
|
||||
}
|
||||
|
||||
RemoveReadOnly(field);
|
||||
field.SetValue(newObject, fromValue);
|
||||
}
|
||||
|
||||
var classPostProcessing = typeTo.GetCustomAttribute<PostProcessingAttribute>();
|
||||
if (classPostProcessing is not null && classPostProcessing.MappingCallMethodName is not null)
|
||||
{
|
||||
var methodInfo = typeTo.GetMethod(classPostProcessing.MappingCallMethodName, BindingFlags.NonPublic | BindingFlags.Instance);
|
||||
methodInfo?.Invoke(newObject, []);
|
||||
}
|
||||
|
||||
return newObject;
|
||||
}
|
||||
|
||||
public static To MapObject<To>(object obj) => MapObject(obj, Activator.CreateInstance<To>()!);
|
||||
|
||||
public static To? MapObjectWithNull<To>(object? obj) => obj is null ? default : MapObject(obj, Activator.CreateInstance<To>());
|
||||
|
||||
private static PropertyInfo? TryGetPropertyFrom(PropertyInfo propertyTo, PropertyInfo[] propertiesFrom)
|
||||
{
|
||||
var customAttribute = propertyTo.GetCustomAttributes<AlternativeNameAttribute>()?
|
||||
.ToArray()
|
||||
.FirstOrDefault(x => propertiesFrom.Any(y => y.Name == x.AlternativeName));
|
||||
if (customAttribute is not null)
|
||||
{
|
||||
return propertiesFrom.FirstOrDefault(x => x.Name == customAttribute.AlternativeName);
|
||||
}
|
||||
return propertiesFrom.FirstOrDefault(x => x.Name == propertyTo.Name);
|
||||
}
|
||||
|
||||
private static object? PostProcessing<T>(object? value, PostProcessingAttribute postProcessingAttribute, T newObject)
|
||||
{
|
||||
if (value is null || newObject is null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
if (!string.IsNullOrEmpty(postProcessingAttribute.MappingCallMethodName))
|
||||
{
|
||||
var methodInfo = newObject.GetType().GetMethod(postProcessingAttribute.MappingCallMethodName, BindingFlags.NonPublic | BindingFlags.Instance);
|
||||
if (methodInfo is not null)
|
||||
{
|
||||
return methodInfo.Invoke(newObject, [value]);
|
||||
}
|
||||
}
|
||||
else if (postProcessingAttribute.ActionType != PostProcessingType.None)
|
||||
{
|
||||
switch (postProcessingAttribute.ActionType)
|
||||
{
|
||||
case PostProcessingType.ToUniversalTime:
|
||||
return ToUniversalTime(value);
|
||||
case PostProcessingType.ToLocalTime:
|
||||
return ToLocalTime(value);
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
private static object? ToLocalTime(object? obj)
|
||||
{
|
||||
if (obj is DateTime date)
|
||||
return date.ToLocalTime();
|
||||
return obj;
|
||||
}
|
||||
|
||||
private static object? ToUniversalTime(object? obj)
|
||||
{
|
||||
if (obj is DateTime date)
|
||||
return date.ToUniversalTime();
|
||||
return obj;
|
||||
}
|
||||
|
||||
private static void FindAndMapDefaultValue<T>(PropertyInfo property, T newObject)
|
||||
{
|
||||
var defaultValueAttribute = property.GetCustomAttribute<DefaultValueAttribute>();
|
||||
if (defaultValueAttribute is null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
if (defaultValueAttribute.DefaultValue is not null)
|
||||
{
|
||||
property.SetValue(newObject, defaultValueAttribute.DefaultValue);
|
||||
return;
|
||||
}
|
||||
|
||||
var value = defaultValueAttribute.FuncName switch
|
||||
{
|
||||
DefaultValueFuncType.UtcNow => DateTime.UtcNow,
|
||||
DefaultValueFuncType.NewGuid => Guid.NewGuid(),
|
||||
_ => (object?)null
|
||||
};
|
||||
if (value is not null)
|
||||
{
|
||||
property.SetValue(newObject, value);
|
||||
}
|
||||
}
|
||||
|
||||
private static object? MapListOfObjects(PropertyInfo propertyTo, object list)
|
||||
{
|
||||
var listResult = Activator.CreateInstance(propertyTo.PropertyType);
|
||||
foreach (var elem in (IEnumerable)list)
|
||||
{
|
||||
var newElem = MapObject(elem, Activator.CreateInstance(propertyTo.PropertyType.GenericTypeArguments[0])!);
|
||||
if (newElem is not null)
|
||||
{
|
||||
propertyTo.PropertyType.GetMethod("Add")!.Invoke(listResult, [newElem]);
|
||||
}
|
||||
}
|
||||
|
||||
return listResult;
|
||||
}
|
||||
|
||||
private static void RemoveReadOnly(FieldInfo field)
|
||||
{
|
||||
if (!field.IsInitOnly)
|
||||
return;
|
||||
|
||||
var attr = typeof(FieldInfo).GetField("m_fieldAttributes", BindingFlags.Instance | BindingFlags.NonPublic);
|
||||
if (attr != null)
|
||||
{
|
||||
var current = (FieldAttributes)attr.GetValue(field)!;
|
||||
attr.SetValue(field, current & ~FieldAttributes.InitOnly);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,8 @@
|
||||
namespace FurnitureAssemblyContracts.Mapper;
|
||||
|
||||
[AttributeUsage(AttributeTargets.Property)]
|
||||
class DefaultValueAttribute : Attribute
|
||||
{
|
||||
public object? DefaultValue { get; set; }
|
||||
public DefaultValueFuncType FuncName { get; set; } = DefaultValueFuncType.None;
|
||||
}
|
||||
@@ -0,0 +1,8 @@
|
||||
namespace FurnitureAssemblyContracts.Mapper;
|
||||
|
||||
public enum DefaultValueFuncType
|
||||
{
|
||||
None = 0,
|
||||
UtcNow = 1,
|
||||
NewGuid = 2
|
||||
}
|
||||
@@ -0,0 +1,6 @@
|
||||
namespace FurnitureAssemblyContracts.Mapper;
|
||||
|
||||
[AttributeUsage(AttributeTargets.Property)]
|
||||
internal class IgnoreAttribute : Attribute
|
||||
{
|
||||
}
|
||||
@@ -0,0 +1,8 @@
|
||||
namespace FurnitureAssemblyContracts.Mapper;
|
||||
|
||||
[AttributeUsage(AttributeTargets.Property)]
|
||||
class PostProcessingAttribute : Attribute
|
||||
{
|
||||
public string? MappingCallMethodName { get; set; }
|
||||
public PostProcessingType ActionType { get; set; } = PostProcessingType.None;
|
||||
}
|
||||
@@ -0,0 +1,10 @@
|
||||
namespace FurnitureAssemblyContracts.Mapper;
|
||||
|
||||
enum PostProcessingType
|
||||
{
|
||||
None = -1,
|
||||
|
||||
ToUniversalTime = 1,
|
||||
|
||||
ToLocalTime = 2
|
||||
}
|
||||
@@ -1,4 +1,8 @@
|
||||
namespace FurnitureAssemblyContracts.ViewModels;
|
||||
using FurnitureAssemblyContracts.Infrastructure.PostConfigurations;
|
||||
using FurnitureAssemblyContracts.Mapper;
|
||||
using System.Text.Json;
|
||||
|
||||
namespace FurnitureAssemblyContracts.ViewModels;
|
||||
|
||||
public class WorkerViewModel
|
||||
{
|
||||
@@ -9,5 +13,12 @@ public class WorkerViewModel
|
||||
public bool IsDeleted { get; set; }
|
||||
public DateTime BirthDate { get; set; }
|
||||
public DateTime EmploymentDate { get; set; }
|
||||
|
||||
[AlternativeName("ConfigurationModel")]
|
||||
[PostProcessing(MappingCallMethodName = "ParseConfiguration")]
|
||||
public required string Configuration { get; set; }
|
||||
public string ParseConfiguration(PostConfiguration model) => JsonSerializer.Serialize(model, new JsonSerializerOptions()
|
||||
{
|
||||
PropertyNameCaseInsensitive = true
|
||||
});
|
||||
}
|
||||
|
||||
@@ -7,7 +7,6 @@
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="AutoMapper" Version="14.0.0" />
|
||||
<PackageReference Include="Microsoft.EntityFrameworkCore" Version="9.0.2" />
|
||||
<PackageReference Include="Microsoft.EntityFrameworkCore.Tools" Version="9.0.2">
|
||||
<PrivateAssets>all</PrivateAssets>
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
using AutoMapper;
|
||||
using FurnitureAssemblyContracts.DataModels;
|
||||
using FurnitureAssemblyContracts.DataModels;
|
||||
using FurnitureAssemblyContracts.Exceptions;
|
||||
using FurnitureAssemblyContracts.Mapper;
|
||||
using FurnitureAssemblyContracts.Resources;
|
||||
using FurnitureAssemblyContracts.StoragesContracts;
|
||||
using FurnitureAssemblyDatebase.Models;
|
||||
@@ -13,17 +13,11 @@ namespace FurnitureAssemblyDatebase.Implementations;
|
||||
internal class ComponentStorageContract : IComponentStorageContract
|
||||
{
|
||||
private readonly FurnitureAssemblyDbContext _dbContext;
|
||||
private readonly Mapper _mapper;
|
||||
private readonly IStringLocalizer<Messages> _localizer;
|
||||
|
||||
public ComponentStorageContract(FurnitureAssemblyDbContext dbContext, IStringLocalizer<Messages> localizer)
|
||||
{
|
||||
_dbContext = dbContext;
|
||||
var config = new MapperConfiguration(cfg =>
|
||||
{
|
||||
cfg.AddMaps(typeof(Component));
|
||||
});
|
||||
_mapper = new Mapper(config);
|
||||
_localizer = localizer;
|
||||
}
|
||||
|
||||
@@ -31,7 +25,7 @@ internal class ComponentStorageContract : IComponentStorageContract
|
||||
{
|
||||
try
|
||||
{
|
||||
return [.. _dbContext.Components.Select(x => _mapper.Map<ComponentDataModel>(x))];
|
||||
return [.. _dbContext.Components.Select(x => CustomMapper.MapObject<ComponentDataModel>(x))];
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
@@ -44,7 +38,7 @@ internal class ComponentStorageContract : IComponentStorageContract
|
||||
{
|
||||
try
|
||||
{
|
||||
return [.. await _dbContext.Components.Select(x => _mapper.Map<ComponentDataModel>(x)).ToListAsync(ct)];
|
||||
return [.. await _dbContext.Components.Select(x => CustomMapper.MapObject<ComponentDataModel>(x)).ToListAsync(ct)];
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
@@ -57,7 +51,7 @@ internal class ComponentStorageContract : IComponentStorageContract
|
||||
{
|
||||
try
|
||||
{
|
||||
return _mapper.Map<ComponentDataModel>(GetComponentById(id));
|
||||
return CustomMapper.MapObjectWithNull<ComponentDataModel>(GetComponentById(id));
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
@@ -70,7 +64,7 @@ internal class ComponentStorageContract : IComponentStorageContract
|
||||
{
|
||||
try
|
||||
{
|
||||
return _mapper.Map<ComponentDataModel>(_dbContext.Components.FirstOrDefault(x => x.Name == name));
|
||||
return CustomMapper.MapObjectWithNull<ComponentDataModel>(_dbContext.Components.FirstOrDefault(x => x.Name == name));
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
@@ -83,7 +77,7 @@ internal class ComponentStorageContract : IComponentStorageContract
|
||||
{
|
||||
try
|
||||
{
|
||||
return _mapper.Map<ComponentDataModel>(_dbContext.Components.FirstOrDefault(x =>
|
||||
return CustomMapper.MapObjectWithNull<ComponentDataModel>(_dbContext.Components.FirstOrDefault(x =>
|
||||
x.PrevName == name || x.PrevPrevName == name));
|
||||
}
|
||||
catch (Exception ex)
|
||||
@@ -97,7 +91,7 @@ internal class ComponentStorageContract : IComponentStorageContract
|
||||
{
|
||||
try
|
||||
{
|
||||
_dbContext.Components.Add(_mapper.Map<Component>(manufacturerDataModel));
|
||||
_dbContext.Components.Add(CustomMapper.MapObject<Component>(manufacturerDataModel));
|
||||
_dbContext.SaveChanges();
|
||||
}
|
||||
catch (InvalidOperationException ex) when (ex.TargetSite?.Name == "ThrowIdentityConflict")
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
using AutoMapper;
|
||||
using FurnitureAssemblyContracts.DataModels;
|
||||
using FurnitureAssemblyContracts.DataModels;
|
||||
using FurnitureAssemblyContracts.Exceptions;
|
||||
using FurnitureAssemblyContracts.Mapper;
|
||||
using FurnitureAssemblyContracts.Resources;
|
||||
using FurnitureAssemblyContracts.StoragesContracts;
|
||||
using FurnitureAssemblyDatebase.Models;
|
||||
@@ -13,20 +13,11 @@ namespace FurnitureAssemblyDatebase;
|
||||
internal class FurnitureStorageContract : IFurnitureStorageContract
|
||||
{
|
||||
private readonly FurnitureAssemblyDbContext _dbContext;
|
||||
private readonly Mapper _mapper;
|
||||
private readonly IStringLocalizer<Messages> _localizer;
|
||||
|
||||
public FurnitureStorageContract(FurnitureAssemblyDbContext dbContext, IStringLocalizer<Messages> localizer)
|
||||
{
|
||||
_dbContext = dbContext;
|
||||
var config = new MapperConfiguration(cfg =>
|
||||
{
|
||||
cfg.CreateMap<Furniture, FurnitureDataModel>();
|
||||
cfg.CreateMap<FurnitureDataModel, Furniture>();
|
||||
cfg.CreateMap<FurnitureComponent, FurnitureComponentDataModel>();
|
||||
cfg.CreateMap<FurnitureComponentDataModel, FurnitureComponent>();
|
||||
});
|
||||
_mapper = new Mapper(config);
|
||||
_localizer = localizer;
|
||||
}
|
||||
|
||||
@@ -34,7 +25,7 @@ internal class FurnitureStorageContract : IFurnitureStorageContract
|
||||
{
|
||||
try
|
||||
{
|
||||
return [.. _dbContext.Furnitures.Select(x => _mapper.Map<FurnitureDataModel>(x))];
|
||||
return [.. _dbContext.Furnitures.Select(x => CustomMapper.MapObject<FurnitureDataModel>(x))];
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
@@ -47,7 +38,7 @@ internal class FurnitureStorageContract : IFurnitureStorageContract
|
||||
{
|
||||
try
|
||||
{
|
||||
return _mapper.Map<FurnitureDataModel>(GetFurnitureById(id));
|
||||
return CustomMapper.MapObjectWithNull<FurnitureDataModel>(GetFurnitureById(id));
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
@@ -60,7 +51,7 @@ internal class FurnitureStorageContract : IFurnitureStorageContract
|
||||
{
|
||||
try
|
||||
{
|
||||
return _mapper.Map<FurnitureDataModel>(_dbContext.Furnitures.FirstOrDefault(x => x.Name == name));
|
||||
return CustomMapper.MapObjectWithNull<FurnitureDataModel>(_dbContext.Furnitures.FirstOrDefault(x => x.Name == name));
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
@@ -73,7 +64,7 @@ internal class FurnitureStorageContract : IFurnitureStorageContract
|
||||
{
|
||||
try
|
||||
{
|
||||
_dbContext.Furnitures.Add(_mapper.Map<Furniture>(furnitureDataModel));
|
||||
_dbContext.Furnitures.Add(CustomMapper.MapObject<Furniture>(furnitureDataModel));
|
||||
_dbContext.SaveChanges();
|
||||
}
|
||||
catch (InvalidOperationException ex) when (ex.TargetSite?.Name == "ThrowIdentityConflict")
|
||||
@@ -98,7 +89,7 @@ internal class FurnitureStorageContract : IFurnitureStorageContract
|
||||
try
|
||||
{
|
||||
var element = GetFurnitureById(furnitureDataModel.Id) ?? throw new ElementNotFoundException(furnitureDataModel.Id, _localizer);
|
||||
_dbContext.Furnitures.Update(_mapper.Map(furnitureDataModel, element));
|
||||
_dbContext.Furnitures.Update(CustomMapper.MapObject(furnitureDataModel, element));
|
||||
_dbContext.SaveChanges();
|
||||
}
|
||||
catch (ElementNotFoundException)
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
using AutoMapper;
|
||||
using FurnitureAssemblyContracts.DataModels;
|
||||
using FurnitureAssemblyContracts.DataModels;
|
||||
using FurnitureAssemblyContracts.Exceptions;
|
||||
using FurnitureAssemblyContracts.Mapper;
|
||||
using FurnitureAssemblyContracts.Resources;
|
||||
using FurnitureAssemblyContracts.StoragesContracts;
|
||||
using FurnitureAssemblyDatebase.Models;
|
||||
@@ -13,20 +13,11 @@ namespace FurnitureAssemblyDatebase.Implementations;
|
||||
internal class ManifacturingStorageContract : IManifacturingStorageContract
|
||||
{
|
||||
private readonly FurnitureAssemblyDbContext _dbContext;
|
||||
private readonly Mapper _mapper;
|
||||
private readonly IStringLocalizer<Messages> _localizer;
|
||||
|
||||
public ManifacturingStorageContract(FurnitureAssemblyDbContext dbContext, IStringLocalizer<Messages> localizer)
|
||||
{
|
||||
_dbContext = dbContext;
|
||||
var config = new MapperConfiguration(cfg =>
|
||||
{
|
||||
cfg.CreateMap<Worker, WorkerDataModel>();
|
||||
cfg.CreateMap<Furniture, FurnitureDataModel>();
|
||||
cfg.CreateMap<ManifacturingFurniture, ManifacturingFurnitureDataModel>();
|
||||
cfg.CreateMap<ManifacturingFurnitureDataModel, ManifacturingFurniture>();
|
||||
});
|
||||
_mapper = new Mapper(config);
|
||||
_localizer = localizer;
|
||||
}
|
||||
|
||||
@@ -47,7 +38,7 @@ internal class ManifacturingStorageContract : IManifacturingStorageContract
|
||||
{
|
||||
query = query.Where(x => x.FurnitureId == furnitureId);
|
||||
}
|
||||
return [.. query.Select(x => _mapper.Map<ManifacturingFurnitureDataModel>(x))];
|
||||
return [.. query.Select(x => CustomMapper.MapObject<ManifacturingFurnitureDataModel>(x))];
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
@@ -61,7 +52,7 @@ internal class ManifacturingStorageContract : IManifacturingStorageContract
|
||||
try
|
||||
{
|
||||
return [.. await _dbContext.Manufacturing.Include(x => x.Worker).Include(x => x.Furniture).Where(x => x.ProductuionDate >= startDate && x.ProductuionDate < endDate)
|
||||
.Select(x => _mapper.Map<ManifacturingFurnitureDataModel>(x)).ToListAsync(ct)];
|
||||
.Select(x => CustomMapper.MapObject<ManifacturingFurnitureDataModel>(x)).ToListAsync(ct)];
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
@@ -74,7 +65,7 @@ internal class ManifacturingStorageContract : IManifacturingStorageContract
|
||||
{
|
||||
try
|
||||
{
|
||||
return _mapper.Map<ManifacturingFurnitureDataModel>(GetManifacturingById(id));
|
||||
return CustomMapper.MapObjectWithNull<ManifacturingFurnitureDataModel>(GetManifacturingById(id));
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
@@ -87,7 +78,7 @@ internal class ManifacturingStorageContract : IManifacturingStorageContract
|
||||
{
|
||||
try
|
||||
{
|
||||
_dbContext.Manufacturing.Add(_mapper.Map<ManifacturingFurniture>(manifacturingFurnitureDataModel));
|
||||
_dbContext.Manufacturing.Add(CustomMapper.MapObject<ManifacturingFurniture>(manifacturingFurnitureDataModel));
|
||||
_dbContext.SaveChanges();
|
||||
}
|
||||
catch (Exception ex)
|
||||
@@ -102,7 +93,7 @@ internal class ManifacturingStorageContract : IManifacturingStorageContract
|
||||
try
|
||||
{
|
||||
var element = GetManifacturingById(manifacturingFurnitureDataModel.Id) ?? throw new ElementNotFoundException(manifacturingFurnitureDataModel.Id, _localizer);
|
||||
_dbContext.Manufacturing.Update(_mapper.Map(manifacturingFurnitureDataModel, element));
|
||||
_dbContext.Manufacturing.Update(CustomMapper.MapObject(manifacturingFurnitureDataModel, element));
|
||||
_dbContext.SaveChanges();
|
||||
}
|
||||
catch (ElementNotFoundException)
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
using AutoMapper;
|
||||
using FurnitureAssemblyContracts.DataModels;
|
||||
using FurnitureAssemblyContracts.DataModels;
|
||||
using FurnitureAssemblyContracts.Exceptions;
|
||||
using FurnitureAssemblyContracts.Mapper;
|
||||
using FurnitureAssemblyContracts.Resources;
|
||||
using FurnitureAssemblyContracts.StoragesContracts;
|
||||
using FurnitureAssemblyDatebase.Models;
|
||||
@@ -14,24 +14,11 @@ namespace FurnitureAssemblyDatebase.Implementations;
|
||||
internal class PostStorageContract : IPostStorageContract
|
||||
{
|
||||
private readonly FurnitureAssemblyDbContext _dbContext;
|
||||
private readonly Mapper _mapper;
|
||||
private readonly IStringLocalizer<Messages> _localizer;
|
||||
|
||||
public PostStorageContract(FurnitureAssemblyDbContext dbContext, IStringLocalizer<Messages> localizer)
|
||||
{
|
||||
_dbContext = dbContext;
|
||||
var config = new MapperConfiguration(cfg =>
|
||||
{
|
||||
cfg.CreateMap<Post, PostDataModel>()
|
||||
.ForMember(x => x.Id, x => x.MapFrom(src =>
|
||||
src.PostId));
|
||||
cfg.CreateMap<PostDataModel, Post>()
|
||||
.ForMember(x => x.Id, x => x.Ignore())
|
||||
.ForMember(x => x.PostId, x => x.MapFrom(src => src.Id))
|
||||
.ForMember(x => x.IsActual, x => x.MapFrom(src => true))
|
||||
.ForMember(x => x.ChangeDate, x => x.MapFrom(src => DateTime.UtcNow));
|
||||
});
|
||||
_mapper = new Mapper(config);
|
||||
_localizer = localizer;
|
||||
}
|
||||
|
||||
@@ -39,7 +26,7 @@ internal class PostStorageContract : IPostStorageContract
|
||||
{
|
||||
try
|
||||
{
|
||||
return [.._dbContext.Posts.Select(x => _mapper.Map<PostDataModel>(x))];
|
||||
return [.._dbContext.Posts.Select(x => CustomMapper.MapObject<PostDataModel>(x))];
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
@@ -52,7 +39,7 @@ internal class PostStorageContract : IPostStorageContract
|
||||
{
|
||||
try
|
||||
{
|
||||
return _mapper.Map<PostDataModel>(_dbContext.Posts.FirstOrDefault(x => x.PostId == id && x.IsActual));
|
||||
return CustomMapper.MapObjectWithNull<PostDataModel>(_dbContext.Posts.FirstOrDefault(x => x.PostId == id && x.IsActual));
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
@@ -65,7 +52,7 @@ internal class PostStorageContract : IPostStorageContract
|
||||
{
|
||||
try
|
||||
{
|
||||
return _mapper.Map<PostDataModel>(_dbContext.Posts.FirstOrDefault(x => x.PostName == name && x.IsActual));
|
||||
return CustomMapper.MapObjectWithNull<PostDataModel>(_dbContext.Posts.FirstOrDefault(x => x.PostName == name && x.IsActual));
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
@@ -78,7 +65,7 @@ internal class PostStorageContract : IPostStorageContract
|
||||
{
|
||||
try
|
||||
{
|
||||
return [.. _dbContext.Posts.Where(x => x.PostId == postId).Select(x => _mapper.Map<PostDataModel>(x))];
|
||||
return [.. _dbContext.Posts.Where(x => x.PostId == postId).Select(x => CustomMapper.MapObjectWithNull<PostDataModel>(x))];
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
@@ -91,7 +78,7 @@ internal class PostStorageContract : IPostStorageContract
|
||||
{
|
||||
try
|
||||
{
|
||||
_dbContext.Posts.Add(_mapper.Map<Post>(postDataModel));
|
||||
_dbContext.Posts.Add(CustomMapper.MapObject<Post>(postDataModel));
|
||||
_dbContext.SaveChanges();
|
||||
}
|
||||
catch (DbUpdateException ex) when (ex.InnerException is PostgresException { ConstraintName: "IX_Posts_PostName_IsActual" })
|
||||
@@ -126,7 +113,7 @@ internal class PostStorageContract : IPostStorageContract
|
||||
}
|
||||
element.IsActual = false;
|
||||
_dbContext.SaveChanges();
|
||||
var newElement = _mapper.Map<Post>(postDataModel);
|
||||
var newElement = CustomMapper.MapObject<Post>(postDataModel);
|
||||
_dbContext.Posts.Add(newElement);
|
||||
_dbContext.SaveChanges();
|
||||
transaction.Commit();
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
using AutoMapper;
|
||||
using FurnitureAssemblyContracts.DataModels;
|
||||
using FurnitureAssemblyContracts.DataModels;
|
||||
using FurnitureAssemblyContracts.Exceptions;
|
||||
using FurnitureAssemblyContracts.Mapper;
|
||||
using FurnitureAssemblyContracts.Resources;
|
||||
using FurnitureAssemblyContracts.StoragesContracts;
|
||||
using FurnitureAssemblyDatebase.Models;
|
||||
@@ -12,20 +12,11 @@ namespace FurnitureAssemblyDatebase.Implementations;
|
||||
internal class SalaryStorageContract : ISalaryStorageContract
|
||||
{
|
||||
private readonly FurnitureAssemblyDbContext _dbContext;
|
||||
private readonly Mapper _mapper;
|
||||
private readonly IStringLocalizer<Messages> _localizer;
|
||||
|
||||
public SalaryStorageContract(FurnitureAssemblyDbContext dbContext, IStringLocalizer<Messages> localizer)
|
||||
{
|
||||
_dbContext = dbContext;
|
||||
var config = new MapperConfiguration(cfg =>
|
||||
{
|
||||
cfg.CreateMap<Worker, WorkerDataModel>();
|
||||
cfg.CreateMap<Salary, SalaryDataModel>();
|
||||
cfg.CreateMap<SalaryDataModel, Salary>()
|
||||
.ForMember(dest => dest.WorkerSalary, opt => opt.MapFrom(src => src.Salary));
|
||||
});
|
||||
_mapper = new Mapper(config);
|
||||
_localizer = localizer;
|
||||
}
|
||||
public List<SalaryDataModel> GetList(DateTime startDate, DateTime endDate, string? workerId = null)
|
||||
@@ -37,7 +28,7 @@ internal class SalaryStorageContract : ISalaryStorageContract
|
||||
{
|
||||
query = query.Where(x => x.WorkerId == workerId);
|
||||
}
|
||||
return [.. query.Select(x => _mapper.Map<SalaryDataModel>(x))];
|
||||
return [.. query.Select(x => CustomMapper.MapObject<SalaryDataModel>(x))];
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
@@ -50,7 +41,7 @@ internal class SalaryStorageContract : ISalaryStorageContract
|
||||
{
|
||||
try
|
||||
{
|
||||
return [.. await _dbContext.Salaries.Include(x => x.Worker).Where(x => x.SalaryDate >= startDate && x.SalaryDate <= endDate).Select(x => _mapper.Map<SalaryDataModel>(x)).ToListAsync(ct)];
|
||||
return [.. await _dbContext.Salaries.Include(x => x.Worker).Where(x => x.SalaryDate >= startDate && x.SalaryDate <= endDate).Select(x => CustomMapper.MapObject<SalaryDataModel>(x)).ToListAsync(ct)];
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
@@ -63,7 +54,7 @@ internal class SalaryStorageContract : ISalaryStorageContract
|
||||
{
|
||||
try
|
||||
{
|
||||
_dbContext.Salaries.Add(_mapper.Map<Salary>(salaryDataModel));
|
||||
_dbContext.Salaries.Add(CustomMapper.MapObject<Salary>(salaryDataModel));
|
||||
_dbContext.SaveChanges();
|
||||
}
|
||||
catch (Exception ex)
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
using AutoMapper;
|
||||
using FurnitureAssemblyContracts.DataModels;
|
||||
using FurnitureAssemblyContracts.DataModels;
|
||||
using FurnitureAssemblyContracts.Exceptions;
|
||||
using FurnitureAssemblyContracts.Mapper;
|
||||
using FurnitureAssemblyContracts.Resources;
|
||||
using FurnitureAssemblyContracts.StoragesContracts;
|
||||
using FurnitureAssemblyDatebase.Models;
|
||||
@@ -13,22 +13,11 @@ namespace FurnitureAssemblyDatebase.Implementations;
|
||||
internal class WorkerStorageContract : IWorkerStorageContract
|
||||
{
|
||||
private readonly FurnitureAssemblyDbContext _dbContext;
|
||||
private readonly Mapper _mapper;
|
||||
private readonly IStringLocalizer<Messages> _localizer;
|
||||
|
||||
public WorkerStorageContract(FurnitureAssemblyDbContext dbContext, IStringLocalizer<Messages> localizer)
|
||||
{
|
||||
_dbContext = dbContext;
|
||||
var config = new MapperConfiguration(cfg =>
|
||||
{
|
||||
cfg.CreateMap<Post, PostDataModel>()
|
||||
.ForMember(x => x.Id, x => x.MapFrom(src => src.PostId));
|
||||
cfg.CreateMap<Worker, WorkerDataModel>();
|
||||
cfg.CreateMap<WorkerDataModel, Worker>()
|
||||
.ForMember(x => x.Configuration, x => x.MapFrom(src => src.ConfigurationModel));
|
||||
|
||||
});
|
||||
_mapper = new Mapper(config);
|
||||
_localizer = localizer;
|
||||
}
|
||||
|
||||
@@ -53,7 +42,7 @@ internal class WorkerStorageContract : IWorkerStorageContract
|
||||
{
|
||||
query = query.Where(x => x.EmploymentDate >= fromEmploymentDate && x.EmploymentDate <= toEmploymentDate);
|
||||
}
|
||||
return [.. JoinPost(query).Select(x => _mapper.Map<WorkerDataModel>(x))];
|
||||
return [.. JoinPost(query).Select(x => CustomMapper.MapObject<WorkerDataModel>(x))];
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
@@ -66,7 +55,7 @@ internal class WorkerStorageContract : IWorkerStorageContract
|
||||
{
|
||||
try
|
||||
{
|
||||
return _mapper.Map<WorkerDataModel>(GetWorkerById(id));
|
||||
return CustomMapper.MapObjectWithNull<WorkerDataModel>(GetWorkerById(id));
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
@@ -79,7 +68,7 @@ internal class WorkerStorageContract : IWorkerStorageContract
|
||||
{
|
||||
try
|
||||
{
|
||||
return _mapper.Map<WorkerDataModel>(AddPost(_dbContext.Workers.FirstOrDefault(x => x.FIO == fio && !x.IsDeleted)));
|
||||
return CustomMapper.MapObjectWithNull<WorkerDataModel>(AddPost(_dbContext.Workers.FirstOrDefault(x => x.FIO == fio && !x.IsDeleted)));
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
@@ -92,7 +81,7 @@ internal class WorkerStorageContract : IWorkerStorageContract
|
||||
{
|
||||
try
|
||||
{
|
||||
_dbContext.Workers.Add(_mapper.Map<Worker>(workerDataModel));
|
||||
_dbContext.Workers.Add(CustomMapper.MapObject<Worker>(workerDataModel));
|
||||
_dbContext.SaveChanges();
|
||||
}
|
||||
catch (InvalidOperationException ex) when (ex.TargetSite?.Name == "ThrowIdentityConflict")
|
||||
@@ -117,7 +106,7 @@ internal class WorkerStorageContract : IWorkerStorageContract
|
||||
try
|
||||
{
|
||||
var element = GetWorkerById(workerDataModel.Id) ?? throw new ElementNotFoundException(workerDataModel.Id, _localizer);
|
||||
_dbContext.Workers.Update(_mapper.Map(workerDataModel, element));
|
||||
_dbContext.Workers.Update(CustomMapper.MapObject(workerDataModel, element));
|
||||
_dbContext.SaveChanges();
|
||||
}
|
||||
catch (ElementNotFoundException)
|
||||
|
||||
@@ -1,11 +1,8 @@
|
||||
using AutoMapper;
|
||||
using FurnitureAssemblyContracts.DataModels;
|
||||
using FurnitureAssemblyContracts.Enums;
|
||||
using FurnitureAssemblyContracts.Enums;
|
||||
using System.ComponentModel.DataAnnotations.Schema;
|
||||
|
||||
namespace FurnitureAssemblyDatebase.Models;
|
||||
|
||||
[AutoMap(typeof(ComponentDataModel), ReverseMap = true)]
|
||||
internal class Component
|
||||
{
|
||||
public required string Id { get; set; }
|
||||
|
||||
@@ -1,14 +1,19 @@
|
||||
using FurnitureAssemblyContracts.Enums;
|
||||
using FurnitureAssemblyContracts.Mapper;
|
||||
|
||||
namespace FurnitureAssemblyDatebase.Models;
|
||||
|
||||
internal class Post
|
||||
{
|
||||
[Ignore]
|
||||
public string Id { get; set; } = Guid.NewGuid().ToString();
|
||||
[AlternativeName("Id")]
|
||||
public required string PostId { get; set; }
|
||||
public required string PostName { get; set; }
|
||||
public PostType PostType { get; set; }
|
||||
public double Salary { get; set; }
|
||||
[DefaultValue(DefaultValue = true)]
|
||||
public bool IsActual { get; set; }
|
||||
[DefaultValue(FuncName = DefaultValueFuncType.UtcNow)]
|
||||
public DateTime ChangeDate { get; set; }
|
||||
}
|
||||
|
||||
@@ -1,9 +1,12 @@
|
||||
namespace FurnitureAssemblyDatebase.Models;
|
||||
using FurnitureAssemblyContracts.Mapper;
|
||||
|
||||
namespace FurnitureAssemblyDatebase.Models;
|
||||
|
||||
internal class Salary
|
||||
{
|
||||
public string Id { get; set; } = Guid.NewGuid().ToString();
|
||||
public required string WorkerId { get; set; }
|
||||
[AlternativeName("Salary")]
|
||||
public double WorkerSalary { get; set; }
|
||||
public DateTime SalaryDate { get; set; }
|
||||
public Worker? Worker { get; set; }
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
using FurnitureAssemblyContracts.Enums;
|
||||
using FurnitureAssemblyContracts.Infrastructure.PostConfigurations;
|
||||
using FurnitureAssemblyContracts.Mapper;
|
||||
using System.ComponentModel.DataAnnotations.Schema;
|
||||
|
||||
namespace FurnitureAssemblyDatebase.Models;
|
||||
@@ -9,9 +10,12 @@ internal class Worker
|
||||
public required string Id { get; set; }
|
||||
public required string FIO { get; set; }
|
||||
public required string PostId { get; set; }
|
||||
[PostProcessing(ActionType = PostProcessingType.ToUniversalTime)]
|
||||
public DateTime BirthDate { get; set; }
|
||||
[PostProcessing(ActionType = PostProcessingType.ToUniversalTime)]
|
||||
public DateTime EmploymentDate { get; set; }
|
||||
public bool IsDeleted { get; set; }
|
||||
[PostProcessing(ActionType = PostProcessingType.ToUniversalTime)]
|
||||
public DateTime ChangeDate { get; set; }
|
||||
[ForeignKey("WorkerId")]
|
||||
public List<Salary>? Salaries { get; set; }
|
||||
@@ -24,7 +28,8 @@ internal class Worker
|
||||
Post = post;
|
||||
return this;
|
||||
}
|
||||
[PostProcessing(ActionType = PostProcessingType.ToUniversalTime)]
|
||||
public DateTime? DateOfDelete { get; set; }
|
||||
[AlternativeName("ConfigurationModel")]
|
||||
public required PostConfiguration Configuration { get; set; }
|
||||
|
||||
}
|
||||
|
||||
@@ -1,12 +1,10 @@
|
||||
using AutoMapper;
|
||||
using DocumentFormat.OpenXml.Office2010.Excel;
|
||||
using FurnitureAssemblyBusinessLogic.Implementations;
|
||||
using FurnitureAssemblyContracts.AdapterContracts;
|
||||
using FurnitureAssemblyContracts.AdapterContracts;
|
||||
using FurnitureAssemblyContracts.AdapterContracts.OperationResponses;
|
||||
using FurnitureAssemblyContracts.BindingModels;
|
||||
using FurnitureAssemblyContracts.BusinessLogicsContracts;
|
||||
using FurnitureAssemblyContracts.DataModels;
|
||||
using FurnitureAssemblyContracts.Exceptions;
|
||||
using FurnitureAssemblyContracts.Mapper;
|
||||
using FurnitureAssemblyContracts.Resources;
|
||||
using FurnitureAssemblyContracts.ViewModels;
|
||||
using Microsoft.Extensions.Localization;
|
||||
@@ -17,19 +15,12 @@ internal class ComponentAdapter : IComponentAdapter
|
||||
{
|
||||
private readonly IComponentBusinessLogicContract _componentBusinessLogicContract;
|
||||
private readonly ILogger<ComponentAdapter> _logger;
|
||||
private readonly IMapper _mapper;
|
||||
private readonly IStringLocalizer<Messages> _localizer;
|
||||
|
||||
public ComponentAdapter(IComponentBusinessLogicContract componentBusinessLogicContract, ILogger<ComponentAdapter> logger, IStringLocalizer<Messages> localizer)
|
||||
{
|
||||
_componentBusinessLogicContract = componentBusinessLogicContract;
|
||||
_logger = logger;
|
||||
var config = new MapperConfiguration(cfg =>
|
||||
{
|
||||
cfg.CreateMap<ComponentBindingModel, ComponentDataModel>();
|
||||
cfg.CreateMap<ComponentDataModel, ComponentViewModel>();
|
||||
});
|
||||
_mapper = new Mapper(config);
|
||||
_localizer = localizer;
|
||||
}
|
||||
|
||||
@@ -37,7 +28,7 @@ internal class ComponentAdapter : IComponentAdapter
|
||||
{
|
||||
try
|
||||
{
|
||||
return ComponentOperationResponse.OK([.. _componentBusinessLogicContract.GetAllComponents().Select(x => _mapper.Map<ComponentViewModel>(x))]);
|
||||
return ComponentOperationResponse.OK([.. _componentBusinessLogicContract.GetAllComponents().Select(x => CustomMapper.MapObject<ComponentViewModel>(x))]);
|
||||
}
|
||||
catch (StorageException ex)
|
||||
{
|
||||
@@ -55,7 +46,7 @@ internal class ComponentAdapter : IComponentAdapter
|
||||
{
|
||||
try
|
||||
{
|
||||
return ComponentOperationResponse.OK(_mapper.Map<ComponentViewModel>(_componentBusinessLogicContract.GetComponentByData(data)));
|
||||
return ComponentOperationResponse.OK(CustomMapper.MapObject<ComponentViewModel>(_componentBusinessLogicContract.GetComponentByData(data)));
|
||||
}
|
||||
catch (ArgumentNullException ex)
|
||||
{
|
||||
@@ -83,7 +74,7 @@ internal class ComponentAdapter : IComponentAdapter
|
||||
{
|
||||
try
|
||||
{
|
||||
_componentBusinessLogicContract.InsertComponent(_mapper.Map<ComponentDataModel>(componentDataModel));
|
||||
_componentBusinessLogicContract.InsertComponent(CustomMapper.MapObject<ComponentDataModel>(componentDataModel));
|
||||
return ComponentOperationResponse.NoContent();
|
||||
}
|
||||
catch (ArgumentNullException ex)
|
||||
@@ -117,7 +108,7 @@ internal class ComponentAdapter : IComponentAdapter
|
||||
{
|
||||
try
|
||||
{
|
||||
_componentBusinessLogicContract.UpdateComponent(_mapper.Map<ComponentDataModel>(componentDataModel));
|
||||
_componentBusinessLogicContract.UpdateComponent(CustomMapper.MapObject<ComponentDataModel>(componentDataModel));
|
||||
return ComponentOperationResponse.NoContent();
|
||||
}
|
||||
catch (ArgumentNullException ex)
|
||||
|
||||
@@ -1,11 +1,10 @@
|
||||
using AutoMapper;
|
||||
using DocumentFormat.OpenXml.Office2010.Excel;
|
||||
using FurnitureAssemblyContracts.AdapterContracts;
|
||||
using FurnitureAssemblyContracts.AdapterContracts;
|
||||
using FurnitureAssemblyContracts.AdapterContracts.OperationResponses;
|
||||
using FurnitureAssemblyContracts.BindingModels;
|
||||
using FurnitureAssemblyContracts.BusinessLogicsContracts;
|
||||
using FurnitureAssemblyContracts.DataModels;
|
||||
using FurnitureAssemblyContracts.Exceptions;
|
||||
using FurnitureAssemblyContracts.Mapper;
|
||||
using FurnitureAssemblyContracts.Resources;
|
||||
using FurnitureAssemblyContracts.ViewModels;
|
||||
using Microsoft.Extensions.Localization;
|
||||
@@ -16,21 +15,12 @@ internal class FurnitureAdapter : IFurnitureAdapter
|
||||
{
|
||||
private readonly IFurnitureBusinessLogicContract _furnitureBusinessLogicContract;
|
||||
private readonly ILogger<FurnitureAdapter> _logger;
|
||||
private readonly IMapper _mapper;
|
||||
private readonly IStringLocalizer<Messages> _localizer;
|
||||
|
||||
public FurnitureAdapter(IFurnitureBusinessLogicContract furnitureBusinessLogicContract, ILogger<FurnitureAdapter> logger, IStringLocalizer<Messages> localizer)
|
||||
{
|
||||
_furnitureBusinessLogicContract = furnitureBusinessLogicContract;
|
||||
_logger = logger;
|
||||
var config = new MapperConfiguration(cfg =>
|
||||
{
|
||||
cfg.CreateMap<FurnitureBindingModel, FurnitureDataModel>();
|
||||
cfg.CreateMap<FurnitureDataModel, FurnitureViewModel>();
|
||||
cfg.CreateMap<FurnitureComponentBindingModel, FurnitureComponentDataModel>();
|
||||
cfg.CreateMap<FurnitureComponentDataModel, FurnitureComponentViewModel>();
|
||||
});
|
||||
_mapper = new Mapper(config);
|
||||
_localizer = localizer;
|
||||
}
|
||||
|
||||
@@ -39,7 +29,7 @@ internal class FurnitureAdapter : IFurnitureAdapter
|
||||
try
|
||||
{
|
||||
Console.WriteLine(_furnitureBusinessLogicContract.GetAllFurnitures());
|
||||
return FurnitureOperationResponse.OK([.. _furnitureBusinessLogicContract.GetAllFurnitures().Select(x => _mapper.Map<FurnitureViewModel>(x))]);
|
||||
return FurnitureOperationResponse.OK([.. _furnitureBusinessLogicContract.GetAllFurnitures().Select(x => CustomMapper.MapObject<FurnitureViewModel>(x))]);
|
||||
}
|
||||
catch (StorageException ex)
|
||||
{
|
||||
@@ -57,7 +47,7 @@ internal class FurnitureAdapter : IFurnitureAdapter
|
||||
{
|
||||
try
|
||||
{
|
||||
return FurnitureOperationResponse.OK(_mapper.Map<FurnitureViewModel>(_furnitureBusinessLogicContract.GetFurnitureByData(data)));
|
||||
return FurnitureOperationResponse.OK(CustomMapper.MapObject<FurnitureViewModel>(_furnitureBusinessLogicContract.GetFurnitureByData(data)));
|
||||
}
|
||||
catch (ArgumentNullException ex)
|
||||
{
|
||||
@@ -85,7 +75,7 @@ internal class FurnitureAdapter : IFurnitureAdapter
|
||||
{
|
||||
try
|
||||
{
|
||||
_furnitureBusinessLogicContract.InsertFurniture(_mapper.Map<FurnitureDataModel>(furnitureDataModel));
|
||||
_furnitureBusinessLogicContract.InsertFurniture(CustomMapper.MapObject<FurnitureDataModel>(furnitureDataModel));
|
||||
return FurnitureOperationResponse.NoContent();
|
||||
}
|
||||
catch (ArgumentNullException ex)
|
||||
@@ -119,7 +109,7 @@ internal class FurnitureAdapter : IFurnitureAdapter
|
||||
{
|
||||
try
|
||||
{
|
||||
_furnitureBusinessLogicContract.UpdateFurniture(_mapper.Map<FurnitureDataModel>(furnitureDataModel));
|
||||
_furnitureBusinessLogicContract.UpdateFurniture(CustomMapper.MapObject<FurnitureDataModel>(furnitureDataModel));
|
||||
return FurnitureOperationResponse.NoContent();
|
||||
}
|
||||
catch (ArgumentNullException ex)
|
||||
|
||||
@@ -1,10 +1,10 @@
|
||||
using AutoMapper;
|
||||
using FurnitureAssemblyContracts.AdapterContracts;
|
||||
using FurnitureAssemblyContracts.AdapterContracts;
|
||||
using FurnitureAssemblyContracts.AdapterContracts.OperationResponses;
|
||||
using FurnitureAssemblyContracts.BindingModels;
|
||||
using FurnitureAssemblyContracts.BusinessLogicsContracts;
|
||||
using FurnitureAssemblyContracts.DataModels;
|
||||
using FurnitureAssemblyContracts.Exceptions;
|
||||
using FurnitureAssemblyContracts.Mapper;
|
||||
using FurnitureAssemblyContracts.Resources;
|
||||
using FurnitureAssemblyContracts.ViewModels;
|
||||
using Microsoft.Extensions.Localization;
|
||||
@@ -17,20 +17,12 @@ internal class ManifacturingFurnitureAdapter : IManifacturingFurnitureAdapter
|
||||
|
||||
private readonly ILogger _logger;
|
||||
|
||||
private readonly Mapper _mapper;
|
||||
|
||||
private readonly IStringLocalizer<Messages> _localizer;
|
||||
|
||||
public ManifacturingFurnitureAdapter(IManifacturingBusinessLogicContract mfBusinessLogicContract, ILogger<ManifacturingFurnitureAdapter> logger, IStringLocalizer<Messages> localizer)
|
||||
{
|
||||
_manifacturingBusinessLogicContract = mfBusinessLogicContract;
|
||||
_logger = logger;
|
||||
var config = new MapperConfiguration(cfg =>
|
||||
{
|
||||
cfg.CreateMap<ManifacturingFurnitureBindingModel, ManifacturingFurnitureDataModel>();
|
||||
cfg.CreateMap<ManifacturingFurnitureDataModel, ManifacturingFurnitureViewModel>();
|
||||
});
|
||||
_mapper = new Mapper(config);
|
||||
_localizer = localizer;
|
||||
}
|
||||
|
||||
@@ -38,7 +30,7 @@ internal class ManifacturingFurnitureAdapter : IManifacturingFurnitureAdapter
|
||||
{
|
||||
try
|
||||
{
|
||||
return ManifacturingFurnitureOperationResponse.OK([.. _manifacturingBusinessLogicContract.GetManifacturingByPeriod(fromDate.ToUniversalTime(), toDate.ToUniversalTime()).Select(x => _mapper.Map<ManifacturingFurnitureViewModel>(x))]);
|
||||
return ManifacturingFurnitureOperationResponse.OK([.. _manifacturingBusinessLogicContract.GetManifacturingByPeriod(fromDate.ToUniversalTime(), toDate.ToUniversalTime()).Select(x => CustomMapper.MapObject<ManifacturingFurnitureViewModel>(x))]);
|
||||
}
|
||||
catch (IncorrectDatesException ex)
|
||||
{
|
||||
@@ -61,7 +53,7 @@ internal class ManifacturingFurnitureAdapter : IManifacturingFurnitureAdapter
|
||||
{
|
||||
try
|
||||
{
|
||||
return ManifacturingFurnitureOperationResponse.OK([.. _manifacturingBusinessLogicContract.GetAllManifacturingByWorkerByPeriod(id, fromDate.ToUniversalTime(), toDate.ToUniversalTime()).Select(x => _mapper.Map<ManifacturingFurnitureViewModel>(x))]);
|
||||
return ManifacturingFurnitureOperationResponse.OK([.. _manifacturingBusinessLogicContract.GetAllManifacturingByWorkerByPeriod(id, fromDate.ToUniversalTime(), toDate.ToUniversalTime()).Select(x => CustomMapper.MapObject<ManifacturingFurnitureViewModel>(x))]);
|
||||
}
|
||||
catch (IncorrectDatesException ex)
|
||||
{
|
||||
@@ -89,7 +81,7 @@ internal class ManifacturingFurnitureAdapter : IManifacturingFurnitureAdapter
|
||||
{
|
||||
try
|
||||
{
|
||||
return ManifacturingFurnitureOperationResponse.OK([.. _manifacturingBusinessLogicContract.GetAllManifacturingByFurnitureByPeriod(id, fromDate.ToUniversalTime(), toDate.ToUniversalTime()).Select(x => _mapper.Map<ManifacturingFurnitureViewModel>(x))]);
|
||||
return ManifacturingFurnitureOperationResponse.OK([.. _manifacturingBusinessLogicContract.GetAllManifacturingByFurnitureByPeriod(id, fromDate.ToUniversalTime(), toDate.ToUniversalTime()).Select(x => CustomMapper.MapObject<ManifacturingFurnitureViewModel>(x))]);
|
||||
}
|
||||
catch (IncorrectDatesException ex)
|
||||
{
|
||||
@@ -117,7 +109,7 @@ internal class ManifacturingFurnitureAdapter : IManifacturingFurnitureAdapter
|
||||
{
|
||||
try
|
||||
{
|
||||
return ManifacturingFurnitureOperationResponse.OK(_mapper.Map<ManifacturingFurnitureViewModel>(_manifacturingBusinessLogicContract.GetManifacturingByData(id)));
|
||||
return ManifacturingFurnitureOperationResponse.OK(CustomMapper.MapObject<ManifacturingFurnitureViewModel>(_manifacturingBusinessLogicContract.GetManifacturingByData(id)));
|
||||
}
|
||||
catch (ArgumentNullException ex)
|
||||
{
|
||||
@@ -150,8 +142,8 @@ internal class ManifacturingFurnitureAdapter : IManifacturingFurnitureAdapter
|
||||
{
|
||||
try
|
||||
{
|
||||
var data = _mapper.Map<ManifacturingFurnitureDataModel>(model);
|
||||
_manifacturingBusinessLogicContract.InsertFurniture(_mapper.Map<ManifacturingFurnitureDataModel>(model));
|
||||
var data = CustomMapper.MapObject<ManifacturingFurnitureDataModel>(model);
|
||||
_manifacturingBusinessLogicContract.InsertFurniture(CustomMapper.MapObject<ManifacturingFurnitureDataModel>(model));
|
||||
return ManifacturingFurnitureOperationResponse.NoContent();
|
||||
}
|
||||
catch (ArgumentNullException ex)
|
||||
@@ -180,7 +172,7 @@ internal class ManifacturingFurnitureAdapter : IManifacturingFurnitureAdapter
|
||||
{
|
||||
try
|
||||
{
|
||||
_manifacturingBusinessLogicContract.UpdateFurniture(_mapper.Map<ManifacturingFurnitureDataModel>(model));
|
||||
_manifacturingBusinessLogicContract.UpdateFurniture(CustomMapper.MapObject<ManifacturingFurnitureDataModel>(model));
|
||||
return ManifacturingFurnitureOperationResponse.NoContent();
|
||||
}
|
||||
catch (ArgumentNullException ex)
|
||||
|
||||
@@ -1,10 +1,10 @@
|
||||
using AutoMapper;
|
||||
using FurnitureAssemblyContracts.AdapterContracts;
|
||||
using FurnitureAssemblyContracts.AdapterContracts;
|
||||
using FurnitureAssemblyContracts.AdapterContracts.OperationResponses;
|
||||
using FurnitureAssemblyContracts.BindingModels;
|
||||
using FurnitureAssemblyContracts.BusinessLogicsContracts;
|
||||
using FurnitureAssemblyContracts.DataModels;
|
||||
using FurnitureAssemblyContracts.Exceptions;
|
||||
using FurnitureAssemblyContracts.Mapper;
|
||||
using FurnitureAssemblyContracts.Resources;
|
||||
using FurnitureAssemblyContracts.ViewModels;
|
||||
using Microsoft.Extensions.Localization;
|
||||
@@ -17,20 +17,12 @@ internal class PostAdapter : IPostAdapter
|
||||
|
||||
private readonly ILogger _logger;
|
||||
|
||||
private readonly Mapper _mapper;
|
||||
|
||||
private readonly IStringLocalizer<Messages> _localizer;
|
||||
|
||||
public PostAdapter(IPostBusinessLogicContract postBusinessLogicContract, ILogger<PostAdapter> logger, IStringLocalizer<Messages> localizer)
|
||||
{
|
||||
_postBusinessLogicContract = postBusinessLogicContract;
|
||||
_logger = logger;
|
||||
var config = new MapperConfiguration(cfg =>
|
||||
{
|
||||
cfg.CreateMap<PostBindingModel, PostDataModel>();
|
||||
cfg.CreateMap<PostDataModel, PostViewModel>();
|
||||
});
|
||||
_mapper = new Mapper(config);
|
||||
_localizer = localizer;
|
||||
}
|
||||
|
||||
@@ -38,7 +30,7 @@ internal class PostAdapter : IPostAdapter
|
||||
{
|
||||
try
|
||||
{
|
||||
return PostOperationResponse.OK([.. _postBusinessLogicContract.GetAllPosts().Select(x => _mapper.Map<PostViewModel>(x))]);
|
||||
return PostOperationResponse.OK([.. _postBusinessLogicContract.GetAllPosts().Select(x => CustomMapper.MapObject<PostViewModel>(x))]);
|
||||
}
|
||||
catch (StorageException ex)
|
||||
{
|
||||
@@ -56,7 +48,7 @@ internal class PostAdapter : IPostAdapter
|
||||
{
|
||||
try
|
||||
{
|
||||
return PostOperationResponse.OK([.. _postBusinessLogicContract.GetAllDataOfPost(id).Select(x => _mapper.Map<PostViewModel>(x))]);
|
||||
return PostOperationResponse.OK([.. _postBusinessLogicContract.GetAllDataOfPost(id).Select(x => CustomMapper.MapObject<PostViewModel>(x))]);
|
||||
}
|
||||
catch (ArgumentNullException ex)
|
||||
{
|
||||
@@ -84,7 +76,7 @@ internal class PostAdapter : IPostAdapter
|
||||
{
|
||||
try
|
||||
{
|
||||
return PostOperationResponse.OK(_mapper.Map<PostViewModel>(_postBusinessLogicContract.GetPostByData(data)));
|
||||
return PostOperationResponse.OK(CustomMapper.MapObject<PostViewModel>(_postBusinessLogicContract.GetPostByData(data)));
|
||||
}
|
||||
catch (ArgumentNullException ex)
|
||||
{
|
||||
@@ -117,7 +109,7 @@ internal class PostAdapter : IPostAdapter
|
||||
{
|
||||
try
|
||||
{
|
||||
_postBusinessLogicContract.InsertPost(_mapper.Map<PostDataModel>(postModel));
|
||||
_postBusinessLogicContract.InsertPost(CustomMapper.MapObject<PostDataModel>(postModel));
|
||||
return PostOperationResponse.NoContent();
|
||||
}
|
||||
catch (ArgumentNullException ex)
|
||||
@@ -151,7 +143,7 @@ internal class PostAdapter : IPostAdapter
|
||||
{
|
||||
try
|
||||
{
|
||||
_postBusinessLogicContract.UpdatePost(_mapper.Map<PostDataModel>(postModel));
|
||||
_postBusinessLogicContract.UpdatePost(CustomMapper.MapObject<PostDataModel>(postModel));
|
||||
return PostOperationResponse.NoContent();
|
||||
}
|
||||
catch (ArgumentNullException ex)
|
||||
|
||||
@@ -1,9 +1,9 @@
|
||||
using AutoMapper;
|
||||
using FurnitureAssemblyContracts.AdapterContracts;
|
||||
using FurnitureAssemblyContracts.AdapterContracts;
|
||||
using FurnitureAssemblyContracts.AdapterContracts.OperationResponses;
|
||||
using FurnitureAssemblyContracts.BusinessLogicsContracts;
|
||||
using FurnitureAssemblyContracts.DataModels;
|
||||
using FurnitureAssemblyContracts.Exceptions;
|
||||
using FurnitureAssemblyContracts.Mapper;
|
||||
using FurnitureAssemblyContracts.Resources;
|
||||
using FurnitureAssemblyContracts.ViewModels;
|
||||
using Microsoft.Extensions.Localization;
|
||||
@@ -14,20 +14,12 @@ internal class ReportAdapter : IReportAdapter
|
||||
{
|
||||
private readonly IReportContract _reportContract;
|
||||
private readonly ILogger _logger;
|
||||
private readonly Mapper _mapper;
|
||||
private readonly IStringLocalizer<Messages> _localizer;
|
||||
|
||||
public ReportAdapter(IReportContract reportContract, ILogger logger, IStringLocalizer<Messages> localizer)
|
||||
{
|
||||
_reportContract = reportContract;
|
||||
_logger = logger;
|
||||
var config = new MapperConfiguration(cfg =>
|
||||
{
|
||||
cfg.CreateMap<ComponentHistoryDataModel, ComponentHistoryViewModel>();
|
||||
cfg.CreateMap<ManifacturingFurnitureDataModel, ManifacturingFurnitureViewModel>();
|
||||
cfg.CreateMap<WorkerSalaryByPeriodDataModel, WorkerSalaryByPeriodViewModel>();
|
||||
});
|
||||
_mapper = new Mapper(config);
|
||||
_localizer = localizer;
|
||||
}
|
||||
|
||||
@@ -37,7 +29,7 @@ internal class ReportAdapter : IReportAdapter
|
||||
{
|
||||
var data = await _reportContract.GetDataComponentsHistoryAsync(ct);
|
||||
return ReportOperationResponse.OK(data.Select(x =>
|
||||
_mapper.Map<ComponentHistoryViewModel>(x)).ToList());
|
||||
CustomMapper.MapObject<ComponentHistoryViewModel>(x)).ToList());
|
||||
}
|
||||
catch (InvalidOperationException ex)
|
||||
{
|
||||
@@ -60,7 +52,7 @@ internal class ReportAdapter : IReportAdapter
|
||||
{
|
||||
try
|
||||
{
|
||||
return ReportOperationResponse.OK((await _reportContract.GetDataManifacturingByPeriodAsync(dateStart.ToUniversalTime(), dateFinish.ToUniversalTime(), ct)).Select(x => _mapper.Map<ManifacturingFurnitureViewModel>(x)).ToList());
|
||||
return ReportOperationResponse.OK((await _reportContract.GetDataManifacturingByPeriodAsync(dateStart.ToUniversalTime(), dateFinish.ToUniversalTime(), ct)).Select(x => CustomMapper.MapObject<ManifacturingFurnitureViewModel>(x)).ToList());
|
||||
}
|
||||
catch (IncorrectDatesException ex)
|
||||
{
|
||||
@@ -89,7 +81,7 @@ internal class ReportAdapter : IReportAdapter
|
||||
try
|
||||
{
|
||||
return ReportOperationResponse.OK((await
|
||||
_reportContract.GetDataSalaryByPeriodAsync(dateStart.ToUniversalTime(), dateFinish.ToUniversalTime(), ct)).Select(x => _mapper.Map<WorkerSalaryByPeriodViewModel>(x)).ToList());
|
||||
_reportContract.GetDataSalaryByPeriodAsync(dateStart.ToUniversalTime(), dateFinish.ToUniversalTime(), ct)).Select(x => CustomMapper.MapObject<WorkerSalaryByPeriodViewModel>(x)).ToList());
|
||||
}
|
||||
catch (IncorrectDatesException ex)
|
||||
{
|
||||
|
||||
@@ -1,9 +1,8 @@
|
||||
using AutoMapper;
|
||||
using FurnitureAssemblyContracts.AdapterContracts;
|
||||
using FurnitureAssemblyContracts.AdapterContracts;
|
||||
using FurnitureAssemblyContracts.AdapterContracts.OperationResponses;
|
||||
using FurnitureAssemblyContracts.BusinessLogicsContracts;
|
||||
using FurnitureAssemblyContracts.DataModels;
|
||||
using FurnitureAssemblyContracts.Exceptions;
|
||||
using FurnitureAssemblyContracts.Mapper;
|
||||
using FurnitureAssemblyContracts.Resources;
|
||||
using FurnitureAssemblyContracts.ViewModels;
|
||||
using Microsoft.Extensions.Localization;
|
||||
@@ -16,7 +15,6 @@ internal class SalaryAdapter : ISalaryAdapter
|
||||
|
||||
private readonly ILogger _logger;
|
||||
|
||||
private readonly Mapper _mapper;
|
||||
|
||||
private readonly IStringLocalizer<Messages> _localizer;
|
||||
|
||||
@@ -24,11 +22,6 @@ internal class SalaryAdapter : ISalaryAdapter
|
||||
{
|
||||
_salaryBusinessLogicContract = salaryBusinessLogicContract;
|
||||
_logger = logger;
|
||||
var config = new MapperConfiguration(cfg =>
|
||||
{
|
||||
cfg.CreateMap<SalaryDataModel, SalaryViewModel>();
|
||||
});
|
||||
_mapper = new Mapper(config);
|
||||
_localizer = localizer;
|
||||
}
|
||||
|
||||
@@ -36,7 +29,7 @@ internal class SalaryAdapter : ISalaryAdapter
|
||||
{
|
||||
try
|
||||
{
|
||||
return SalaryOperationResponse.OK([.. _salaryBusinessLogicContract.GetAllSalariesByPeriod(fromDate.ToUniversalTime(), toDate.ToUniversalTime()).Select(x => _mapper.Map<SalaryViewModel>(x))]);
|
||||
return SalaryOperationResponse.OK([.. _salaryBusinessLogicContract.GetAllSalariesByPeriod(fromDate.ToUniversalTime(), toDate.ToUniversalTime()).Select(x => CustomMapper.MapObject<SalaryViewModel>(x))]);
|
||||
}
|
||||
catch (ValidationException ex)
|
||||
{
|
||||
@@ -64,7 +57,7 @@ internal class SalaryAdapter : ISalaryAdapter
|
||||
{
|
||||
try
|
||||
{
|
||||
return SalaryOperationResponse.OK([.. _salaryBusinessLogicContract.GetAllSalariesByPeriodByWorker(fromDate.ToUniversalTime(), toDate.ToUniversalTime(), workerId).Select(x => _mapper.Map<SalaryViewModel>(x))]);
|
||||
return SalaryOperationResponse.OK([.. _salaryBusinessLogicContract.GetAllSalariesByPeriodByWorker(fromDate.ToUniversalTime(), toDate.ToUniversalTime(), workerId).Select(x => CustomMapper.MapObject<SalaryViewModel>(x))]);
|
||||
}
|
||||
catch (ValidationException ex)
|
||||
{
|
||||
|
||||
@@ -1,10 +1,10 @@
|
||||
using AutoMapper;
|
||||
using FurnitureAssemblyContracts.AdapterContracts;
|
||||
using FurnitureAssemblyContracts.AdapterContracts;
|
||||
using FurnitureAssemblyContracts.AdapterContracts.OperationResponses;
|
||||
using FurnitureAssemblyContracts.BindingModels;
|
||||
using FurnitureAssemblyContracts.BusinessLogicsContracts;
|
||||
using FurnitureAssemblyContracts.DataModels;
|
||||
using FurnitureAssemblyContracts.Exceptions;
|
||||
using FurnitureAssemblyContracts.Mapper;
|
||||
using FurnitureAssemblyContracts.Resources;
|
||||
using FurnitureAssemblyContracts.ViewModels;
|
||||
using Microsoft.Extensions.Localization;
|
||||
@@ -18,26 +18,14 @@ internal class WorkerAdapter : IWorkerAdapter
|
||||
|
||||
private readonly ILogger _logger;
|
||||
|
||||
private readonly Mapper _mapper;
|
||||
|
||||
private readonly IStringLocalizer<Messages> _localizer;
|
||||
|
||||
private readonly JsonSerializerOptions JsonSerializerOptions = new()
|
||||
{
|
||||
PropertyNameCaseInsensitive = true
|
||||
};
|
||||
|
||||
public WorkerAdapter(IWorkerBusinessLogicContract workerBusinessLogicContract, ILogger<WorkerAdapter> logger, IStringLocalizer<Messages> localizer)
|
||||
{
|
||||
_buyerBusinessLogicContract = workerBusinessLogicContract;
|
||||
_logger = logger;
|
||||
var config = new MapperConfiguration(cfg =>
|
||||
{
|
||||
cfg.CreateMap<WorkerBindingModel, WorkerDataModel>();
|
||||
cfg.CreateMap<WorkerDataModel, WorkerViewModel>()
|
||||
.ForMember(x => x.Configuration, x => x.MapFrom(src => JsonSerializer.Serialize(src.ConfigurationModel, JsonSerializerOptions)));
|
||||
});
|
||||
_mapper = new Mapper(config);
|
||||
_localizer = localizer;
|
||||
}
|
||||
|
||||
@@ -45,7 +33,7 @@ internal class WorkerAdapter : IWorkerAdapter
|
||||
{
|
||||
try
|
||||
{
|
||||
return WorkerOperationResponse.OK([.. _buyerBusinessLogicContract.GetAllWorkers(!includeDeleted).Select(x => _mapper.Map<WorkerViewModel>(x))]);
|
||||
return WorkerOperationResponse.OK([.. _buyerBusinessLogicContract.GetAllWorkers(!includeDeleted).Select(x => CustomMapper.MapObject<WorkerViewModel>(x))]);
|
||||
}
|
||||
catch (StorageException ex)
|
||||
{
|
||||
@@ -63,7 +51,7 @@ internal class WorkerAdapter : IWorkerAdapter
|
||||
{
|
||||
try
|
||||
{
|
||||
return WorkerOperationResponse.OK([.. _buyerBusinessLogicContract.GetAllWorkersByPost(id, !includeDeleted).Select(x => _mapper.Map<WorkerViewModel>(x))]);
|
||||
return WorkerOperationResponse.OK([.. _buyerBusinessLogicContract.GetAllWorkersByPost(id, !includeDeleted).Select(x => CustomMapper.MapObject<WorkerViewModel>(x))]);
|
||||
}
|
||||
catch (ValidationException ex)
|
||||
{
|
||||
@@ -86,7 +74,7 @@ internal class WorkerAdapter : IWorkerAdapter
|
||||
{
|
||||
try
|
||||
{
|
||||
return WorkerOperationResponse.OK([.. _buyerBusinessLogicContract.GetAllWorkersByBirthDate(fromDate.ToUniversalTime(), toDate.ToUniversalTime(), !includeDeleted).Select(x => _mapper.Map<WorkerViewModel>(x))]);
|
||||
return WorkerOperationResponse.OK([.. _buyerBusinessLogicContract.GetAllWorkersByBirthDate(fromDate.ToUniversalTime(), toDate.ToUniversalTime(), !includeDeleted).Select(x => CustomMapper.MapObject<WorkerViewModel>(x))]);
|
||||
}
|
||||
catch (IncorrectDatesException ex)
|
||||
{
|
||||
@@ -110,7 +98,7 @@ internal class WorkerAdapter : IWorkerAdapter
|
||||
{
|
||||
try
|
||||
{
|
||||
return WorkerOperationResponse.OK([.. _buyerBusinessLogicContract.GetAllWorkersByEmploymentDate(fromDate.ToUniversalTime(), toDate.ToUniversalTime(), !includeDeleted).Select(x => _mapper.Map<WorkerViewModel>(x))]);
|
||||
return WorkerOperationResponse.OK([.. _buyerBusinessLogicContract.GetAllWorkersByEmploymentDate(fromDate.ToUniversalTime(), toDate.ToUniversalTime(), !includeDeleted).Select(x => CustomMapper.MapObject<WorkerViewModel>(x))]);
|
||||
}
|
||||
catch (IncorrectDatesException ex)
|
||||
{
|
||||
@@ -133,7 +121,7 @@ internal class WorkerAdapter : IWorkerAdapter
|
||||
{
|
||||
try
|
||||
{
|
||||
return WorkerOperationResponse.OK(_mapper.Map<WorkerViewModel>(_buyerBusinessLogicContract.GetWorkerByData(data)));
|
||||
return WorkerOperationResponse.OK(CustomMapper.MapObject<WorkerViewModel>(_buyerBusinessLogicContract.GetWorkerByData(data)));
|
||||
}
|
||||
catch (ArgumentNullException ex)
|
||||
{
|
||||
@@ -166,7 +154,7 @@ internal class WorkerAdapter : IWorkerAdapter
|
||||
{
|
||||
try
|
||||
{
|
||||
_buyerBusinessLogicContract.InsertWorker(_mapper.Map<WorkerDataModel>(workerModel));
|
||||
_buyerBusinessLogicContract.InsertWorker(CustomMapper.MapObject<WorkerDataModel>(workerModel));
|
||||
return WorkerOperationResponse.NoContent();
|
||||
}
|
||||
catch (ArgumentNullException ex)
|
||||
@@ -200,7 +188,7 @@ internal class WorkerAdapter : IWorkerAdapter
|
||||
{
|
||||
try
|
||||
{
|
||||
_buyerBusinessLogicContract.UpdateWorker(_mapper.Map<WorkerDataModel>(workerModel));
|
||||
_buyerBusinessLogicContract.UpdateWorker(CustomMapper.MapObject<WorkerDataModel>(workerModel));
|
||||
return WorkerOperationResponse.NoContent();
|
||||
}
|
||||
catch (ArgumentNullException ex)
|
||||
|
||||
Reference in New Issue
Block a user