PIbd-22_Ulybin_A.A._PimpMyRide_Task_8 #10
@@ -2,12 +2,14 @@
|
||||
using PimpMyRideContracts.Exceptions;
|
||||
using PimpMyRideContracts.Extensions;
|
||||
using PimpMyRideContracts.Infrastructure;
|
||||
using PimpMyRideContracts.Mapper;
|
||||
using PimpMyRideContracts.Resources;
|
||||
|
||||
namespace PimpMyRideContracts.DataModels;
|
||||
|
||||
internal class CarDataModel(string id, string clientId, string make, string model, string stateNumber) : IValidation
|
||||
{
|
||||
[SourceFromMember(SourcePropertyName = "Client")]
|
||||
private readonly ClientDataModel? _client;
|
||||
|
||||
public string Id { get; private set; } = id;
|
||||
@@ -27,6 +29,8 @@ internal class CarDataModel(string id, string clientId, string make, string mode
|
||||
_client = client;
|
||||
}
|
||||
|
||||
public CarDataModel() : this(string.Empty, string.Empty, string.Empty, string.Empty, string.Empty) { }
|
||||
|
||||
public void Validate(IStringLocalizer<Messages> localizer)
|
||||
{
|
||||
if (Id.IsEmpty())
|
||||
|
||||
@@ -15,6 +15,8 @@ internal class ClientDataModel(string id, string fio, string phoneNumber) : IVal
|
||||
|
||||
public string PhoneNumber { get; private set; } = phoneNumber;
|
||||
|
||||
public ClientDataModel() : this(string.Empty, string.Empty, string.Empty) { }
|
||||
|
||||
public void Validate(IStringLocalizer<Messages> localizer)
|
||||
{
|
||||
if (Id.IsEmpty())
|
||||
|
||||
@@ -17,6 +17,8 @@ internal class MaterialDataModel(string id, MaterialType materialType, string de
|
||||
|
||||
public double UnitCost { get; private set; } = unitCost;
|
||||
|
||||
public MaterialDataModel() : this(string.Empty, MaterialType.None, string.Empty, 0) { }
|
||||
|
||||
public void Validate(IStringLocalizer<Messages> localizer)
|
||||
{
|
||||
if (Id.IsEmpty())
|
||||
|
||||
@@ -2,12 +2,14 @@
|
||||
using PimpMyRideContracts.Exceptions;
|
||||
using PimpMyRideContracts.Extensions;
|
||||
using PimpMyRideContracts.Infrastructure;
|
||||
using PimpMyRideContracts.Mapper;
|
||||
using PimpMyRideContracts.Resources;
|
||||
|
||||
namespace PimpMyRideContracts.DataModels;
|
||||
|
||||
internal class MaterialHistoryDataModel(string materialId, double oldPrice) : IValidation
|
||||
{
|
||||
[SourceFromMember(SourcePropertyName = "Material")]
|
||||
private readonly MaterialDataModel? _material;
|
||||
|
||||
public string MaterialId { get; private set; } = materialId;
|
||||
@@ -24,6 +26,8 @@ internal class MaterialHistoryDataModel(string materialId, double oldPrice) : IV
|
||||
_material = material;
|
||||
}
|
||||
|
||||
public MaterialHistoryDataModel() : this(string.Empty, 0) { }
|
||||
|
||||
public void Validate(IStringLocalizer<Messages> localizer)
|
||||
{
|
||||
if (MaterialId.IsEmpty())
|
||||
|
||||
@@ -2,12 +2,14 @@
|
||||
using PimpMyRideContracts.Exceptions;
|
||||
using PimpMyRideContracts.Extensions;
|
||||
using PimpMyRideContracts.Infrastructure;
|
||||
using PimpMyRideContracts.Mapper;
|
||||
using PimpMyRideContracts.Resources;
|
||||
|
||||
namespace PimpMyRideContracts.DataModels;
|
||||
|
||||
internal class OrderDataModel : IValidation
|
||||
{
|
||||
[SourceFromMember(SourcePropertyName = "Car")]
|
||||
private readonly CarDataModel? _car;
|
||||
|
||||
public string Id { get; private set; }
|
||||
@@ -18,8 +20,9 @@ internal class OrderDataModel : IValidation
|
||||
|
||||
public double TotalCost { get; private set; }
|
||||
|
||||
public bool IsCancel { get; private set; }
|
||||
public bool IsCancel { get; private set; }
|
||||
|
||||
[AlternativeName("OrderServices")]
|
||||
public List<OrderServiceDataModel> Services { get; private set; }
|
||||
|
||||
public string CarMake => _car?.Make ?? string.Empty;
|
||||
@@ -39,6 +42,8 @@ internal class OrderDataModel : IValidation
|
||||
_car = car;
|
||||
}
|
||||
|
||||
public OrderDataModel() : this(string.Empty, string.Empty, false, new List<OrderServiceDataModel>()) { }
|
||||
|
||||
public void Validate(IStringLocalizer<Messages> localizer)
|
||||
{
|
||||
if (Id.IsEmpty())
|
||||
|
||||
@@ -3,12 +3,14 @@ using PimpMyRideContracts.Enums;
|
||||
using PimpMyRideContracts.Exceptions;
|
||||
using PimpMyRideContracts.Extensions;
|
||||
using PimpMyRideContracts.Infrastructure;
|
||||
using PimpMyRideContracts.Mapper;
|
||||
using PimpMyRideContracts.Resources;
|
||||
|
||||
namespace PimpMyRideContracts.DataModels;
|
||||
|
||||
internal class OrderServiceDataModel(string orderId, string serviceId, int count, double price) : IValidation
|
||||
{
|
||||
[SourceFromMember(SourcePropertyName = "Service")]
|
||||
private readonly ServiceDataModel? _service;
|
||||
|
||||
public string OrderId { get; private set; } = orderId;
|
||||
@@ -26,6 +28,8 @@ internal class OrderServiceDataModel(string orderId, string serviceId, int count
|
||||
_service = service;
|
||||
}
|
||||
|
||||
public OrderServiceDataModel() : this(string.Empty, string.Empty, 1, 10) { }
|
||||
|
||||
public void Validate(IStringLocalizer<Messages> localizer)
|
||||
{
|
||||
if (OrderId.IsEmpty())
|
||||
|
||||
@@ -7,23 +7,30 @@ using PimpMyRideContracts.Infrastructure;
|
||||
using PimpMyRideContracts.Infrastructure.ServiceConfiguration;
|
||||
using Microsoft.Extensions.Localization;
|
||||
using PimpMyRideContracts.Resources;
|
||||
using PimpMyRideContracts.Mapper;
|
||||
|
||||
namespace PimpMyRideContracts.DataModels;
|
||||
|
||||
internal class ServiceDataModel : IValidation
|
||||
{
|
||||
[SourceFromMember(SourcePropertyName = "Worker")]
|
||||
private readonly WorkerDataModel? _worker;
|
||||
|
||||
public string Id { get; private set; }
|
||||
|
||||
public string WorkerId { get; private set; }
|
||||
|
||||
public WorkType WorkType { get; private set; }
|
||||
public WorkType WorkType { get; private set; }
|
||||
|
||||
[AlternativeName("Configuration")]
|
||||
[AlternativeName("ConfigurationJson")]
|
||||
[PostProcessing(MappingCallMethodName = "ParseJson")]
|
||||
public ServiceConfiguration ConfigurationModel { get; private set; }
|
||||
|
||||
[AlternativeName("ServiceMaterials")]
|
||||
public List<ServiceMaterialDataModel> Materials { get; private set; }
|
||||
|
||||
|
||||
[IgnoreValue]
|
||||
public DateTime ServiceDate { get; private set; } = DateTime.UtcNow;
|
||||
|
||||
public string WorkerFIO => _worker?.FIO ?? string.Empty;
|
||||
@@ -59,19 +66,7 @@ internal class ServiceDataModel : IValidation
|
||||
|
||||
public ServiceDataModel(string id, string workerId, int workType, ServiceConfiguration configurationModel, List<ServiceMaterialDataModel> materials) : this(id, workerId, (WorkType)workType, configurationModel, materials) { }
|
||||
|
||||
public ServiceDataModel(string id, string workerId, WorkType workType, string configurationJson, List<ServiceMaterialDataModel> serviceMaterials) : this(id, workerId, workType, (ServiceConfiguration)null, serviceMaterials)
|
||||
{
|
||||
var obj = JToken.Parse(configurationJson);
|
||||
if (obj is not null)
|
||||
{
|
||||
ConfigurationModel = obj.Value<string>("Type") switch
|
||||
{
|
||||
nameof(WheelsServiceConfiguration) => JsonConvert.DeserializeObject<WheelsServiceConfiguration>(configurationJson)!,
|
||||
nameof(EngineServiceConfiguration) => JsonConvert.DeserializeObject<EngineServiceConfiguration>(configurationJson)!,
|
||||
_ => JsonConvert.DeserializeObject<ServiceConfiguration>(configurationJson)!,
|
||||
};
|
||||
}
|
||||
}
|
||||
public ServiceDataModel() : this(string.Empty, string.Empty, WorkType.None, (ServiceConfiguration)null, new List<ServiceMaterialDataModel>()) { }
|
||||
|
||||
public void Validate(IStringLocalizer<Messages> localizer)
|
||||
{
|
||||
@@ -99,4 +94,25 @@ internal class ServiceDataModel : IValidation
|
||||
if ((Materials?.Count ?? 0) == 0)
|
||||
throw new ValidationException(localizer["ValidationExceptionMessageNoMaterialsInService"]);
|
||||
}
|
||||
|
||||
private ServiceConfiguration? ParseJson(string json)
|
||||
{
|
||||
if (string.IsNullOrWhiteSpace(json)) return null;
|
||||
|
||||
var obj = JToken.Parse(json);
|
||||
var type = obj.Value<string>("Type");
|
||||
switch (type)
|
||||
{
|
||||
case nameof(EngineServiceConfiguration):
|
||||
ConfigurationModel = JsonConvert.DeserializeObject<EngineServiceConfiguration>(json);
|
||||
break;
|
||||
case nameof(WheelsServiceConfiguration):
|
||||
ConfigurationModel = JsonConvert.DeserializeObject<WheelsServiceConfiguration>(json);
|
||||
break;
|
||||
default:
|
||||
ConfigurationModel = JsonConvert.DeserializeObject<ServiceConfiguration>(json);
|
||||
break;
|
||||
}
|
||||
return ConfigurationModel;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2,12 +2,14 @@
|
||||
using PimpMyRideContracts.Exceptions;
|
||||
using PimpMyRideContracts.Extensions;
|
||||
using PimpMyRideContracts.Infrastructure;
|
||||
using PimpMyRideContracts.Mapper;
|
||||
using PimpMyRideContracts.Resources;
|
||||
|
||||
namespace PimpMyRideContracts.DataModels;
|
||||
|
||||
internal class ServiceMaterialDataModel(string serviceId, string materialId, int count, double price) : IValidation
|
||||
{
|
||||
[SourceFromMember(SourcePropertyName = "Material")]
|
||||
private readonly MaterialDataModel? _material;
|
||||
|
||||
public string ServiceId { get; private set; } = serviceId;
|
||||
@@ -25,6 +27,8 @@ internal class ServiceMaterialDataModel(string serviceId, string materialId, int
|
||||
_material = material;
|
||||
}
|
||||
|
||||
public ServiceMaterialDataModel() : this(string.Empty, string.Empty, 0, 0) { }
|
||||
|
||||
public void Validate(IStringLocalizer<Messages> localizer)
|
||||
{
|
||||
if (ServiceId.IsEmpty())
|
||||
|
||||
@@ -3,6 +3,7 @@ using PimpMyRideContracts.Enums;
|
||||
using PimpMyRideContracts.Exceptions;
|
||||
using PimpMyRideContracts.Extensions;
|
||||
using PimpMyRideContracts.Infrastructure;
|
||||
using PimpMyRideContracts.Mapper;
|
||||
using PimpMyRideContracts.Resources;
|
||||
|
||||
namespace PimpMyRideContracts.DataModels;
|
||||
@@ -15,14 +16,19 @@ internal class WorkerDataModel(string id, string fio, SpecialityType specialityT
|
||||
|
||||
public SpecialityType SpecialityType { get; private set; } = specialityType;
|
||||
|
||||
[PostProcessing(ActionType = PostProcessingType.ToUniversalTime)]
|
||||
public DateTime BirthDate { get; private set; } = birthDate.ToUniversalTime();
|
||||
|
||||
[PostProcessing(ActionType = PostProcessingType.ToUniversalTime)]
|
||||
public DateTime EmploymentDate { get; private set; } = employmentDate.ToUniversalTime();
|
||||
|
||||
[CustomDefault(DefaultValue = false)]
|
||||
public bool IsDeleted { get; private set; } = isDeleted;
|
||||
|
||||
public WorkerDataModel(string id, string fio, SpecialityType specialityType, DateTime birthDate, DateTime employmentDate) : this(id, fio, specialityType, birthDate, employmentDate, false) { }
|
||||
|
||||
public WorkerDataModel() : this(string.Empty, string.Empty, SpecialityType.None, DateTime.UtcNow, DateTime.UtcNow, false) { }
|
||||
|
||||
public void Validate(IStringLocalizer<Messages> localizer)
|
||||
{
|
||||
if (Id.IsEmpty())
|
||||
|
||||
@@ -0,0 +1,7 @@
|
||||
namespace PimpMyRideContracts.Mapper;
|
||||
|
||||
[AttributeUsage(AttributeTargets.Property, AllowMultiple = true)]
|
||||
class AlternativeNameAttribute(string alternativeName) : Attribute
|
||||
{
|
||||
public string AlternativeName { get; set; } = alternativeName;
|
||||
}
|
||||
@@ -0,0 +1,9 @@
|
||||
namespace PimpMyRideContracts.Mapper;
|
||||
|
||||
[AttributeUsage(AttributeTargets.Property, Inherited = true)]
|
||||
class CustomDefaultAttribute : Attribute
|
||||
{
|
||||
public object? DefaultValue { get; set; }
|
||||
|
||||
public DefaultValuesFunc FuncName { get; set; }
|
||||
}
|
||||
216
PimpMyRideProject/PimpMyRideContracts/Mapper/CustomMapper.cs
Normal file
216
PimpMyRideProject/PimpMyRideContracts/Mapper/CustomMapper.cs
Normal file
@@ -0,0 +1,216 @@
|
||||
using System.Collections;
|
||||
using System.ComponentModel;
|
||||
using System.Reflection;
|
||||
|
||||
namespace PimpMyRideContracts.Mapper;
|
||||
|
||||
internal static 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))
|
||||
{
|
||||
//ignore
|
||||
if(property.GetCustomAttribute(typeof(IgnoreValueAttribute)) != null)
|
||||
{
|
||||
FindAndMapDefaultValue(property, newObject);
|
||||
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) && propertyFrom.PropertyType != property.PropertyType)
|
||||
{
|
||||
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)
|
||||
{
|
||||
object? finalValue = null;
|
||||
bool successConversion = false;
|
||||
|
||||
var targetType = property.PropertyType;
|
||||
|
||||
if (propertyFrom.PropertyType.IsEnum && !targetType.IsEnum)
|
||||
{
|
||||
finalValue = fromValue.ToString();
|
||||
successConversion = true;
|
||||
}
|
||||
else if (targetType.IsEnum)
|
||||
{
|
||||
successConversion = Enum.TryParse(targetType, fromValue.ToString(), ignoreCase: true, out object? parsedEnum);
|
||||
if (successConversion)
|
||||
{
|
||||
finalValue = parsedEnum;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
finalValue = fromValue;
|
||||
successConversion = true;
|
||||
|
||||
}
|
||||
|
||||
if (successConversion)
|
||||
{
|
||||
property.SetValue(newObject, finalValue);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
// fields
|
||||
var fieldsTo = typeTo.GetFields(BindingFlags.NonPublic | BindingFlags.Instance);
|
||||
foreach (var field in fieldsTo)
|
||||
{
|
||||
var mapFromAttr = field.GetCustomAttribute<SourceFromMemberAttribute>();
|
||||
if (mapFromAttr is null)
|
||||
continue;
|
||||
|
||||
var sourceProp = typeFrom.GetProperty(mapFromAttr.SourcePropertyName);
|
||||
if (sourceProp is null || !sourceProp.CanRead)
|
||||
continue;
|
||||
|
||||
var sourceValue = sourceProp.GetValue(obj);
|
||||
if (sourceValue is null)
|
||||
continue;
|
||||
|
||||
var targetFieldType = field.FieldType;
|
||||
var mappedValue = typeof(CustomMapper)
|
||||
.GetMethod(nameof(MapObject), new[] { typeof(object) })!
|
||||
.MakeGenericMethod(targetFieldType)
|
||||
.Invoke(null, new[] { sourceValue });
|
||||
|
||||
if (mappedValue is not null)
|
||||
{
|
||||
field.SetValue(newObject, mappedValue);
|
||||
}
|
||||
}
|
||||
|
||||
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<CustomDefaultAttribute>();
|
||||
if (defaultValueAttribute is null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
if (defaultValueAttribute.DefaultValue is not null)
|
||||
{
|
||||
property.SetValue(newObject, defaultValueAttribute.DefaultValue);
|
||||
return;
|
||||
}
|
||||
|
||||
var value = defaultValueAttribute.FuncName switch
|
||||
{
|
||||
DefaultValuesFunc.UtcNow => DateTime.UtcNow,
|
||||
DefaultValuesFunc.Null => (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;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,9 @@
|
||||
|
||||
namespace PimpMyRideContracts.Mapper
|
||||
{
|
||||
enum DefaultValuesFunc
|
||||
{
|
||||
Null,
|
||||
UtcNow
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,8 @@
|
||||
|
||||
namespace PimpMyRideContracts.Mapper
|
||||
{
|
||||
[AttributeUsage(AttributeTargets.Property)]
|
||||
class IgnoreValueAttribute : Attribute
|
||||
{
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,10 @@
|
||||
|
||||
namespace PimpMyRideContracts.Mapper
|
||||
{
|
||||
[AttributeUsage(AttributeTargets.Property | AttributeTargets.Class)]
|
||||
class PostProcessingAttribute : Attribute
|
||||
{
|
||||
public string? MappingCallMethodName { get; set; }
|
||||
public PostProcessingType ActionType { get; set; } = PostProcessingType.None;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,10 @@
|
||||
|
||||
namespace PimpMyRideContracts.Mapper
|
||||
{
|
||||
enum PostProcessingType
|
||||
{
|
||||
None = -1,
|
||||
ToUniversalTime = 1,
|
||||
ToLocalTime = 2,
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,9 @@
|
||||
|
||||
namespace PimpMyRideContracts.Mapper
|
||||
{
|
||||
[AttributeUsage(AttributeTargets.Field)]
|
||||
class SourceFromMemberAttribute : Attribute
|
||||
{
|
||||
public string? SourcePropertyName { get; set; }
|
||||
}
|
||||
}
|
||||
@@ -1,4 +1,6 @@
|
||||
namespace PimpMyRideContracts.ViewModels;
|
||||
using PimpMyRideContracts.Mapper;
|
||||
|
||||
namespace PimpMyRideContracts.ViewModels;
|
||||
|
||||
public class MaterialHistoryViewModel
|
||||
{
|
||||
@@ -6,5 +8,6 @@ public class MaterialHistoryViewModel
|
||||
|
||||
public double OldPrice { get; set; }
|
||||
|
||||
[PostProcessing(ActionType = PostProcessingType.ToLocalTime)]
|
||||
public DateTime ChangeDate { get; set; }
|
||||
}
|
||||
|
||||
@@ -1,4 +1,6 @@
|
||||
namespace PimpMyRideContracts.ViewModels;
|
||||
using PimpMyRideContracts.Mapper;
|
||||
|
||||
namespace PimpMyRideContracts.ViewModels;
|
||||
|
||||
public class OrderViewModel
|
||||
{
|
||||
@@ -8,6 +10,7 @@ public class OrderViewModel
|
||||
|
||||
public required string CarMake { get; set; }
|
||||
|
||||
[PostProcessing(ActionType = PostProcessingType.ToLocalTime)]
|
||||
public DateTime OrderDate { get; set; }
|
||||
|
||||
public double TotalCost { get; set; }
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
using PimpMyRideContracts.DataModels;
|
||||
using PimpMyRideContracts.Enums;
|
||||
using System.Text.Json;
|
||||
using PimpMyRideContracts.Infrastructure.ServiceConfiguration;
|
||||
using PimpMyRideContracts.Mapper;
|
||||
|
||||
namespace PimpMyRideContracts.ViewModels;
|
||||
|
||||
@@ -13,7 +14,12 @@ public class ServiceViewModel
|
||||
|
||||
public required string WorkType { get; set; }
|
||||
|
||||
[AlternativeName("ConfigurationModel")]
|
||||
[PostProcessing(MappingCallMethodName = "ParseConfiguration")]
|
||||
public required string Configuration { get; set; }
|
||||
|
||||
private string ParseConfiguration(ServiceConfiguration model) =>
|
||||
JsonSerializer.Serialize(model, new JsonSerializerOptions() { PropertyNameCaseInsensitive = true });
|
||||
|
||||
public required List<ServiceMaterialViewModel> Materials { get; set; }
|
||||
}
|
||||
|
||||
@@ -1,33 +1,19 @@
|
||||
using AutoMapper;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using Microsoft.Extensions.Localization;
|
||||
using Npgsql;
|
||||
using PimpMyRideContracts.DataModels;
|
||||
using PimpMyRideContracts.Exceptions;
|
||||
using PimpMyRideContracts.Mapper;
|
||||
using PimpMyRideContracts.Resources;
|
||||
using PimpMyRideContracts.StoragesContracts;
|
||||
using PimpMyRideDatabase.Models;
|
||||
|
||||
namespace PimpMyRideDatabase.Implementations;
|
||||
|
||||
internal class CarStorageContract : ICarStorageContract
|
||||
internal class CarStorageContract(PimpMyRideDbContext pimpMyRideDbContext, IStringLocalizer<Messages> localizer) : ICarStorageContract
|
||||
{
|
||||
private readonly PimpMyRideDbContext _dbContext;
|
||||
private readonly Mapper _mapper;
|
||||
private readonly IStringLocalizer<Messages> _localizer;
|
||||
|
||||
public CarStorageContract(PimpMyRideDbContext pimpMyRideDbContext, IStringLocalizer<Messages> localizer)
|
||||
{
|
||||
_dbContext = pimpMyRideDbContext;
|
||||
var config = new MapperConfiguration(cfg =>
|
||||
{
|
||||
cfg.CreateMap<Client, ClientDataModel>();
|
||||
cfg.CreateMap<Car, CarDataModel>();
|
||||
cfg.CreateMap<CarDataModel, Car>();
|
||||
});
|
||||
_mapper = new Mapper(config);
|
||||
_localizer = localizer;
|
||||
}
|
||||
private readonly PimpMyRideDbContext _dbContext = pimpMyRideDbContext;
|
||||
private readonly IStringLocalizer<Messages> _localizer = localizer;
|
||||
|
||||
public List<CarDataModel> GetList(string? clientId = null, string? make = null, string? model = null)
|
||||
{
|
||||
@@ -46,7 +32,7 @@ internal class CarStorageContract : ICarStorageContract
|
||||
{
|
||||
query = query.Where(x => x.Model == model);
|
||||
}
|
||||
return [.. query.Select(x => _mapper.Map<CarDataModel>(x))];
|
||||
return [.. query.Select(x => CustomMapper.MapObject<CarDataModel>(x))];
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
@@ -59,7 +45,7 @@ internal class CarStorageContract : ICarStorageContract
|
||||
{
|
||||
try
|
||||
{
|
||||
return [.. await _dbContext.Cars.Include(x => x.Client).Select(x => _mapper.Map<CarDataModel>(x)).ToListAsync(ct)];
|
||||
return [.. await _dbContext.Cars.Include(x => x.Client).Select(x => CustomMapper.MapObject<CarDataModel>(x)).ToListAsync(ct)];
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
@@ -72,7 +58,7 @@ internal class CarStorageContract : ICarStorageContract
|
||||
{
|
||||
try
|
||||
{
|
||||
return _mapper.Map<CarDataModel>(GetCarById(id));
|
||||
return CustomMapper.MapObjectWithNull<CarDataModel>(GetCarById(id));
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
@@ -85,7 +71,7 @@ internal class CarStorageContract : ICarStorageContract
|
||||
{
|
||||
try
|
||||
{
|
||||
return _mapper.Map<CarDataModel>(_dbContext.Cars.FirstOrDefault(x => x.StateNumber == stateNumber));
|
||||
return CustomMapper.MapObjectWithNull<CarDataModel>(_dbContext.Cars.FirstOrDefault(x => x.StateNumber == stateNumber));
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
@@ -98,7 +84,7 @@ internal class CarStorageContract : ICarStorageContract
|
||||
{
|
||||
try
|
||||
{
|
||||
_dbContext.Cars.Add(_mapper.Map<Car>(carDataModel));
|
||||
_dbContext.Cars.Add(CustomMapper.MapObject<Car>(carDataModel));
|
||||
_dbContext.SaveChanges();
|
||||
}
|
||||
catch (InvalidOperationException ex) when (ex.TargetSite?.Name == "ThrowIdentityConflict")
|
||||
@@ -128,7 +114,7 @@ internal class CarStorageContract : ICarStorageContract
|
||||
try
|
||||
{
|
||||
var element = GetCarById(carDataModel.Id) ?? throw new ElementNotFoundException(carDataModel.Id, _localizer);
|
||||
_dbContext.Cars.Update(_mapper.Map(carDataModel, element));
|
||||
_dbContext.Cars.Update(CustomMapper.MapObject(carDataModel, element));
|
||||
_dbContext.SaveChanges();
|
||||
}
|
||||
catch (ElementNotFoundException)
|
||||
|
||||
@@ -1,38 +1,25 @@
|
||||
using AutoMapper;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using Microsoft.Extensions.Localization;
|
||||
using Npgsql;
|
||||
using PimpMyRideContracts.DataModels;
|
||||
using PimpMyRideContracts.Exceptions;
|
||||
using PimpMyRideContracts.Resources;
|
||||
using PimpMyRideContracts.StoragesContracts;
|
||||
using PimpMyRideContracts.Mapper;
|
||||
using PimpMyRideDatabase.Models;
|
||||
|
||||
namespace PimpMyRideDatabase.Implementations;
|
||||
|
||||
internal class ClientStorageContract : IClientStorageContract
|
||||
internal class ClientStorageContract(PimpMyRideDbContext pimpMyRideDbContext, IStringLocalizer<Messages> localizer) : IClientStorageContract
|
||||
{
|
||||
private readonly PimpMyRideDbContext _dbContext;
|
||||
private readonly Mapper _mapper;
|
||||
private readonly IStringLocalizer<Messages> _localizer;
|
||||
|
||||
public ClientStorageContract(PimpMyRideDbContext pimpMyRideDbContext, IStringLocalizer<Messages> localizer)
|
||||
{
|
||||
_dbContext = pimpMyRideDbContext;
|
||||
var config = new MapperConfiguration(cfg =>
|
||||
{
|
||||
cfg.CreateMap<Client, ClientDataModel>();
|
||||
cfg.CreateMap<ClientDataModel, Client>();
|
||||
});
|
||||
_mapper = new Mapper(config);
|
||||
_localizer = localizer;
|
||||
}
|
||||
private readonly PimpMyRideDbContext _dbContext = pimpMyRideDbContext;
|
||||
private readonly IStringLocalizer<Messages> _localizer = localizer;
|
||||
|
||||
public List<ClientDataModel> GetList()
|
||||
{
|
||||
try
|
||||
{
|
||||
return [.. _dbContext.Clients.Select(x => _mapper.Map<ClientDataModel>(x))];
|
||||
return [.. _dbContext.Clients.Select(x => CustomMapper.MapObject<ClientDataModel>(x))];
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
@@ -46,7 +33,7 @@ internal class ClientStorageContract : IClientStorageContract
|
||||
{
|
||||
try
|
||||
{
|
||||
return _mapper.Map<ClientDataModel>(GetClientById(id));
|
||||
return CustomMapper.MapObjectWithNull<ClientDataModel>(GetClientById(id));
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
@@ -59,7 +46,7 @@ internal class ClientStorageContract : IClientStorageContract
|
||||
{
|
||||
try
|
||||
{
|
||||
return _mapper.Map<ClientDataModel>(_dbContext.Clients.FirstOrDefault(x => x.FIO == fio));
|
||||
return CustomMapper.MapObjectWithNull<ClientDataModel>(_dbContext.Clients.FirstOrDefault(x => x.FIO == fio));
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
@@ -73,7 +60,7 @@ internal class ClientStorageContract : IClientStorageContract
|
||||
{
|
||||
try
|
||||
{
|
||||
return _mapper.Map<ClientDataModel>(_dbContext.Clients.FirstOrDefault(x => x.PhoneNumber == phoneNumber));
|
||||
return CustomMapper.MapObjectWithNull<ClientDataModel>(_dbContext.Clients.FirstOrDefault(x => x.PhoneNumber == phoneNumber));
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
@@ -86,7 +73,7 @@ internal class ClientStorageContract : IClientStorageContract
|
||||
{
|
||||
try
|
||||
{
|
||||
_dbContext.Clients.Add(_mapper.Map<Client>(clientDataModel));
|
||||
_dbContext.Clients.Add(CustomMapper.MapObject<Client>(clientDataModel));
|
||||
_dbContext.SaveChanges();
|
||||
}
|
||||
catch (InvalidOperationException ex) when (ex.TargetSite?.Name == "ThrowIdentityConflict")
|
||||
@@ -117,7 +104,7 @@ internal class ClientStorageContract : IClientStorageContract
|
||||
try
|
||||
{
|
||||
var element = GetClientById(clientDataModel.Id) ?? throw new ElementNotFoundException(clientDataModel.Id, _localizer);
|
||||
_dbContext.Clients.Update(_mapper.Map(clientDataModel, element));
|
||||
_dbContext.Clients.Update(CustomMapper.MapObject(clientDataModel, element));
|
||||
_dbContext.SaveChanges();
|
||||
}
|
||||
catch (ElementNotFoundException)
|
||||
|
||||
@@ -1,34 +1,20 @@
|
||||
using AutoMapper;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using Microsoft.Extensions.Localization;
|
||||
using Npgsql;
|
||||
using PimpMyRideContracts.DataModels;
|
||||
using PimpMyRideContracts.Enums;
|
||||
using PimpMyRideContracts.Exceptions;
|
||||
using PimpMyRideContracts.Mapper;
|
||||
using PimpMyRideContracts.Resources;
|
||||
using PimpMyRideContracts.StoragesContracts;
|
||||
using PimpMyRideDatabase.Models;
|
||||
|
||||
namespace PimpMyRideDatabase.Implementations;
|
||||
|
||||
internal class MaterialStorageContracts : IMaterialStorageContracts
|
||||
internal class MaterialStorageContracts(PimpMyRideDbContext pimpMyRideDbContext, IStringLocalizer<Messages> localizer) : IMaterialStorageContracts
|
||||
{
|
||||
private readonly PimpMyRideDbContext _dbContext;
|
||||
private readonly Mapper _mapper;
|
||||
private readonly IStringLocalizer<Messages> _localizer;
|
||||
|
||||
public MaterialStorageContracts(PimpMyRideDbContext pimpMyRideDbContext, IStringLocalizer<Messages> localizer)
|
||||
{
|
||||
_dbContext = pimpMyRideDbContext;
|
||||
var config = new MapperConfiguration(cfg =>
|
||||
{
|
||||
cfg.CreateMap<Material, MaterialDataModel>();
|
||||
cfg.CreateMap<MaterialDataModel, Material>();
|
||||
cfg.CreateMap<MaterialHistory, MaterialHistoryDataModel>();
|
||||
});
|
||||
_mapper = new Mapper(config);
|
||||
_localizer = localizer;
|
||||
}
|
||||
private readonly PimpMyRideDbContext _dbContext = pimpMyRideDbContext;
|
||||
private readonly IStringLocalizer<Messages> _localizer = localizer;
|
||||
|
||||
public List<MaterialDataModel> GetList(MaterialType? materialType = MaterialType.None)
|
||||
{
|
||||
@@ -39,7 +25,7 @@ internal class MaterialStorageContracts : IMaterialStorageContracts
|
||||
{
|
||||
query = query.Where(x => x.MaterialType == materialType);
|
||||
}
|
||||
return [.. query.Select(x => _mapper.Map<MaterialDataModel>(x))];
|
||||
return [.. query.Select(x => CustomMapper.MapObject<MaterialDataModel>(x))];
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
@@ -52,7 +38,7 @@ internal class MaterialStorageContracts : IMaterialStorageContracts
|
||||
{
|
||||
try
|
||||
{
|
||||
return _mapper.Map<MaterialDataModel>(_dbContext.Materials.FirstOrDefault(x => x.Description == description));
|
||||
return CustomMapper.MapObjectWithNull<MaterialDataModel>(_dbContext.Materials.FirstOrDefault(x => x.Description == description));
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
@@ -65,7 +51,7 @@ internal class MaterialStorageContracts : IMaterialStorageContracts
|
||||
{
|
||||
try
|
||||
{
|
||||
return _mapper.Map<MaterialDataModel>(GetMaterialById(id));
|
||||
return CustomMapper.MapObjectWithNull<MaterialDataModel>(GetMaterialById(id));
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
@@ -78,7 +64,7 @@ internal class MaterialStorageContracts : IMaterialStorageContracts
|
||||
{
|
||||
try
|
||||
{
|
||||
return [.. _dbContext.MaterialHistories.Include(x => x.Material).Where(x => x.MaterialId == materialId).OrderByDescending(x => x.ChangeDate).Select(x => _mapper.Map<MaterialHistoryDataModel>(x))];
|
||||
return [.. _dbContext.MaterialHistories.Include(x => x.Material).Where(x => x.MaterialId == materialId).OrderByDescending(x => x.ChangeDate).Select(x => CustomMapper.MapObject<MaterialHistoryDataModel>(x))];
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
@@ -91,7 +77,7 @@ internal class MaterialStorageContracts : IMaterialStorageContracts
|
||||
{
|
||||
try
|
||||
{
|
||||
_dbContext.Materials.Add(_mapper.Map<Material>(materialDataModel));
|
||||
_dbContext.Materials.Add(CustomMapper.MapObject<Material>(materialDataModel));
|
||||
_dbContext.SaveChanges();
|
||||
}
|
||||
catch (InvalidOperationException ex) when (ex.TargetSite?.Name == "ThrowIdentityConflict")
|
||||
@@ -129,7 +115,7 @@ internal class MaterialStorageContracts : IMaterialStorageContracts
|
||||
_dbContext.MaterialHistories.Add(new MaterialHistory() { MaterialId = element.Id, OldPrice = element.UnitCost });
|
||||
_dbContext.SaveChanges();
|
||||
}
|
||||
_dbContext.Materials.Update(_mapper.Map(materialDataModel, element));
|
||||
_dbContext.Materials.Update(CustomMapper.MapObject(materialDataModel, element));
|
||||
_dbContext.SaveChanges();
|
||||
transaction.Commit();
|
||||
}
|
||||
|
||||
@@ -1,38 +1,37 @@
|
||||
using AutoMapper;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using Microsoft.Extensions.Localization;
|
||||
using PimpMyRideContracts.DataModels;
|
||||
using PimpMyRideContracts.Exceptions;
|
||||
using PimpMyRideContracts.Mapper;
|
||||
using PimpMyRideContracts.Resources;
|
||||
using PimpMyRideContracts.StoragesContracts;
|
||||
using PimpMyRideDatabase.Models;
|
||||
|
||||
namespace PimpMyRideDatabase.Implementations;
|
||||
|
||||
internal class OrderStorageContract : IOrderStorageContract
|
||||
internal class OrderStorageContract(PimpMyRideDbContext dbContext, IStringLocalizer<Messages> localizer) : IOrderStorageContract
|
||||
{
|
||||
private readonly PimpMyRideDbContext _dbContext;
|
||||
private readonly Mapper _mapper;
|
||||
private readonly IStringLocalizer<Messages> _localizer;
|
||||
private readonly PimpMyRideDbContext _dbContext = dbContext;
|
||||
private readonly IStringLocalizer<Messages> _localizer = localizer;
|
||||
|
||||
public OrderStorageContract(PimpMyRideDbContext dbContext, IStringLocalizer<Messages> localizer)
|
||||
{
|
||||
_dbContext = dbContext;
|
||||
var config = new MapperConfiguration(cfg =>
|
||||
{
|
||||
cfg.CreateMap<Client, ClientDataModel>();
|
||||
cfg.CreateMap<Car, CarDataModel>();
|
||||
cfg.CreateMap<Service, ServiceDataModel>();
|
||||
cfg.CreateMap<OrderService, OrderServiceDataModel>()
|
||||
.ConstructUsing(src => new OrderServiceDataModel(src.OrderId, src.ServiceId, src.Count, src.Price)); cfg.CreateMap<OrderServiceDataModel, OrderService>();
|
||||
cfg.CreateMap<Order, OrderDataModel>();
|
||||
cfg.CreateMap<OrderDataModel, Order>()
|
||||
.ForMember(x => x.IsCancel, x => x.MapFrom(src => false))
|
||||
.ForMember(x => x.OrderServices, x => x.MapFrom(src => src.Services));
|
||||
});
|
||||
_mapper = new Mapper(config);
|
||||
_localizer = localizer;
|
||||
}
|
||||
//public OrderStorageContract(PimpMyRideDbContext dbContext, IStringLocalizer<Messages> localizer)
|
||||
//{
|
||||
// _dbContext = dbContext;
|
||||
// var config = new MapperConfiguration(cfg =>
|
||||
// {
|
||||
// cfg.CreateMap<Client, ClientDataModel>();
|
||||
// cfg.CreateMap<Car, CarDataModel>();
|
||||
// cfg.CreateMap<Service, ServiceDataModel>();
|
||||
// cfg.CreateMap<OrderService, OrderServiceDataModel>()
|
||||
// .ConstructUsing(src => new OrderServiceDataModel(src.OrderId, src.ServiceId, src.Count, src.Price)); cfg.CreateMap<OrderServiceDataModel, OrderService>();
|
||||
// cfg.CreateMap<Order, OrderDataModel>();
|
||||
// cfg.CreateMap<OrderDataModel, Order>()
|
||||
// .ForMember(x => x.IsCancel, x => x.MapFrom(src => false))
|
||||
// .ForMember(x => x.OrderServices, x => x.MapFrom(src => src.Services));
|
||||
// });
|
||||
// _mapper = new Mapper(config);
|
||||
// _localizer = localizer;
|
||||
//}
|
||||
|
||||
public List<OrderDataModel> GetList(DateTime? startDate = null, DateTime? endDate = null, string? carId = null)
|
||||
{
|
||||
@@ -47,7 +46,7 @@ internal class OrderStorageContract : IOrderStorageContract
|
||||
{
|
||||
query = query.Where(x => x.CarId == carId);
|
||||
}
|
||||
return [.. query.Select(x => _mapper.Map<OrderDataModel>(x))];
|
||||
return [.. query.Select(x => CustomMapper.MapObject<OrderDataModel>(x))];
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
@@ -60,7 +59,7 @@ internal class OrderStorageContract : IOrderStorageContract
|
||||
{
|
||||
try
|
||||
{
|
||||
return [.. await _dbContext.Orders.Include(x => x.OrderServices)!.ThenInclude(x => x.Service).Where(x => x.OrderDate >= startDate && x.OrderDate < endDate).Select(x => _mapper.Map<OrderDataModel>(x)).ToListAsync(ct)];
|
||||
return [.. await _dbContext.Orders.Include(x => x.OrderServices)!.ThenInclude(x => x.Service).Where(x => x.OrderDate >= startDate && x.OrderDate < endDate).Select(x => CustomMapper.MapObject<OrderDataModel>(x)).ToListAsync(ct)];
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
@@ -73,7 +72,7 @@ internal class OrderStorageContract : IOrderStorageContract
|
||||
{
|
||||
try
|
||||
{
|
||||
return _mapper.Map<OrderDataModel>(GetOrderById(id));
|
||||
return CustomMapper.MapObjectWithNull<OrderDataModel>(GetOrderById(id));
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
@@ -86,7 +85,7 @@ internal class OrderStorageContract : IOrderStorageContract
|
||||
{
|
||||
try
|
||||
{
|
||||
_dbContext.Orders.Add(_mapper.Map<Order>(orderDataModel));
|
||||
_dbContext.Orders.Add(CustomMapper.MapObject<Order>(orderDataModel));
|
||||
_dbContext.SaveChanges();
|
||||
}
|
||||
catch (Exception ex)
|
||||
|
||||
@@ -1,52 +1,19 @@
|
||||
using AutoMapper;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using Microsoft.Extensions.Localization;
|
||||
using PimpMyRideContracts.DataModels;
|
||||
using PimpMyRideContracts.Enums;
|
||||
using PimpMyRideContracts.Exceptions;
|
||||
using PimpMyRideContracts.Mapper;
|
||||
using PimpMyRideContracts.Resources;
|
||||
using PimpMyRideContracts.StoragesContracts;
|
||||
using PimpMyRideDatabase.Models;
|
||||
|
||||
namespace PimpMyRideDatabase.Implementations;
|
||||
|
||||
internal class ServiceStorageContracts : IServiceStorageContracts
|
||||
internal class ServiceStorageContracts(PimpMyRideDbContext pimpMyRideDbContext, IStringLocalizer<Messages> localizer) : IServiceStorageContracts
|
||||
{
|
||||
private readonly PimpMyRideDbContext _dbContext;
|
||||
private readonly Mapper _mapper;
|
||||
private readonly IStringLocalizer<Messages> _localizer;
|
||||
|
||||
public ServiceStorageContracts(PimpMyRideDbContext dbContext, IStringLocalizer<Messages> localizer)
|
||||
{
|
||||
_dbContext = dbContext;
|
||||
var config = new MapperConfiguration(cfg =>
|
||||
{
|
||||
cfg.CreateMap<Material, MaterialDataModel>();
|
||||
cfg.CreateMap<ServiceMaterial, ServiceMaterialDataModel>();
|
||||
cfg.CreateMap<ServiceMaterialDataModel, ServiceMaterial>();
|
||||
cfg.CreateMap<Worker, WorkerDataModel>();
|
||||
cfg.CreateMap<Service, ServiceDataModel>()
|
||||
.ConstructUsing(s => new ServiceDataModel(
|
||||
s.Id,
|
||||
s.WorkerId,
|
||||
s.WorkType,
|
||||
s.Configuration,
|
||||
s.ServiceMaterials != null
|
||||
? s.ServiceMaterials.Select(sm => new ServiceMaterialDataModel(
|
||||
sm.ServiceId,
|
||||
sm.MaterialId,
|
||||
sm.Count,
|
||||
sm.Price)).ToList()
|
||||
: new List<ServiceMaterialDataModel>(),
|
||||
_mapper.Map<WorkerDataModel>(s.Worker) // Передаем WorkerDataModel
|
||||
));
|
||||
cfg.CreateMap<ServiceDataModel, Service>()
|
||||
.ForMember(dest => dest.ServiceMaterials, opt => opt.MapFrom(src => src.Materials))
|
||||
.ForMember(dest => dest.Configuration, opt => opt.MapFrom(src => src.ConfigurationModel));
|
||||
});
|
||||
_mapper = new Mapper(config);
|
||||
_localizer = localizer;
|
||||
}
|
||||
private readonly PimpMyRideDbContext _dbContext = pimpMyRideDbContext;
|
||||
private readonly IStringLocalizer<Messages> _localizer = localizer;
|
||||
|
||||
public List<ServiceDataModel> GetList(string? workerId = null, WorkType? workType = WorkType.None)
|
||||
{
|
||||
@@ -61,7 +28,7 @@ internal class ServiceStorageContracts : IServiceStorageContracts
|
||||
{
|
||||
query = query.Where(x => x.WorkType == workType);
|
||||
}
|
||||
return [.. query.Select(x => _mapper.Map<ServiceDataModel>(x))];
|
||||
return [.. query.Select(x => CustomMapper.MapObject<ServiceDataModel>(x))];
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
@@ -75,7 +42,7 @@ internal class ServiceStorageContracts : IServiceStorageContracts
|
||||
try
|
||||
{
|
||||
return [.. await _dbContext.Services.Include(x => x.Worker)
|
||||
.Where(x => x.ServiceDate >= startDate && x.ServiceDate <= endDate).Select(x => _mapper.Map<ServiceDataModel>(x)).ToListAsync(ct)];
|
||||
.Where(x => x.ServiceDate >= startDate && x.ServiceDate <= endDate).Select(x => CustomMapper.MapObject < ServiceDataModel >(x)).ToListAsync(ct)];
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
@@ -88,7 +55,7 @@ internal class ServiceStorageContracts : IServiceStorageContracts
|
||||
{
|
||||
try
|
||||
{
|
||||
return _mapper.Map<ServiceDataModel>(GetServiceById(id));
|
||||
return CustomMapper.MapObjectWithNull<ServiceDataModel>(GetServiceById(id));
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
@@ -101,7 +68,7 @@ internal class ServiceStorageContracts : IServiceStorageContracts
|
||||
{
|
||||
try
|
||||
{
|
||||
_dbContext.Services.Add(_mapper.Map<Service>(serviceDataModel));
|
||||
_dbContext.Services.Add(CustomMapper.MapObject<Service>(serviceDataModel));
|
||||
_dbContext.SaveChanges();
|
||||
}
|
||||
catch (Exception ex)
|
||||
|
||||
@@ -1,32 +1,20 @@
|
||||
using AutoMapper;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using Microsoft.Extensions.Localization;
|
||||
using Npgsql;
|
||||
using PimpMyRideContracts.DataModels;
|
||||
using PimpMyRideContracts.Enums;
|
||||
using PimpMyRideContracts.Exceptions;
|
||||
using PimpMyRideContracts.Mapper;
|
||||
using PimpMyRideContracts.Resources;
|
||||
using PimpMyRideContracts.StoragesContracts;
|
||||
using PimpMyRideDatabase.Models;
|
||||
|
||||
namespace PimpMyRideDatabase.Implementations;
|
||||
|
||||
internal class WorkerStorageContract : IWorkerStorageContract
|
||||
internal class WorkerStorageContract(PimpMyRideDbContext pimpMyRideDbContext, IStringLocalizer<Messages> localizer) : IWorkerStorageContract
|
||||
{
|
||||
private readonly PimpMyRideDbContext _dbContext;
|
||||
private readonly Mapper _mapper;
|
||||
private readonly IStringLocalizer<Messages> _localizer;
|
||||
|
||||
public WorkerStorageContract(PimpMyRideDbContext dbContext, IStringLocalizer<Messages> localizer)
|
||||
{
|
||||
_dbContext = dbContext;
|
||||
var config = new MapperConfiguration(cfg =>
|
||||
{
|
||||
cfg.AddMaps(typeof(Worker));
|
||||
});
|
||||
_mapper = new Mapper(config);
|
||||
_localizer = localizer;
|
||||
}
|
||||
private readonly PimpMyRideDbContext _dbContext = pimpMyRideDbContext;
|
||||
private readonly IStringLocalizer<Messages> _localizer = localizer;
|
||||
|
||||
public List<WorkerDataModel> GetList(bool onlyActive = true, SpecialityType? specialityType = SpecialityType.None, DateTime? fromBirthDate = null, DateTime? toBirthDate = null, DateTime? fromEmploymentDate = null, DateTime? toEmploymentDate = null)
|
||||
{
|
||||
@@ -51,7 +39,7 @@ internal class WorkerStorageContract : IWorkerStorageContract
|
||||
query = query.Where(x => x.EmploymentDate >= DateTime.SpecifyKind(fromEmploymentDate.Value, DateTimeKind.Utc) &&
|
||||
x.EmploymentDate <= DateTime.SpecifyKind(toEmploymentDate.Value, DateTimeKind.Utc));
|
||||
}
|
||||
return [.. query.Select(x => _mapper.Map<WorkerDataModel>(x))];
|
||||
return [.. query.Select(x => CustomMapper.MapObject<WorkerDataModel>(x))];
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
@@ -64,7 +52,7 @@ internal class WorkerStorageContract : IWorkerStorageContract
|
||||
{
|
||||
try
|
||||
{
|
||||
return _mapper.Map<WorkerDataModel>(_dbContext.Workers.FirstOrDefault(x => x.FIO == fio && !x.IsDeleted ));
|
||||
return CustomMapper.MapObjectWithNull<WorkerDataModel>(_dbContext.Workers.FirstOrDefault(x => x.FIO == fio && !x.IsDeleted ));
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
@@ -77,7 +65,7 @@ internal class WorkerStorageContract : IWorkerStorageContract
|
||||
{
|
||||
try
|
||||
{
|
||||
return _mapper.Map<WorkerDataModel>(GetWorkerById(id));
|
||||
return CustomMapper.MapObjectWithNull<WorkerDataModel>(GetWorkerById(id));
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
@@ -90,7 +78,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")
|
||||
@@ -115,7 +103,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,4 +1,5 @@
|
||||
using System.ComponentModel.DataAnnotations.Schema;
|
||||
using PimpMyRideContracts.Mapper;
|
||||
|
||||
namespace PimpMyRideDatabase.Models;
|
||||
|
||||
@@ -8,14 +9,18 @@ internal class Order
|
||||
|
||||
public required string CarId { get; set; }
|
||||
|
||||
[CustomDefault(FuncName = DefaultValuesFunc.UtcNow)]
|
||||
public DateTime OrderDate { get; set; }
|
||||
|
||||
public double TotalCost { get; set; }
|
||||
|
||||
|
||||
[IgnoreValue]
|
||||
[CustomDefault(DefaultValue = false)]
|
||||
public bool IsCancel { get; set; }
|
||||
|
||||
public Car? Car { get; set; }
|
||||
|
||||
[AlternativeName("Services")]
|
||||
[ForeignKey("OrderId")]
|
||||
public List<OrderService>? OrderServices { get; set; }
|
||||
}
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
using PimpMyRideContracts.Enums;
|
||||
using PimpMyRideContracts.Infrastructure.ServiceConfiguration;
|
||||
using PimpMyRideContracts.Mapper;
|
||||
using System.ComponentModel.DataAnnotations.Schema;
|
||||
|
||||
namespace PimpMyRideDatabase.Models;
|
||||
@@ -12,12 +13,14 @@ internal class Service
|
||||
|
||||
public WorkType WorkType { get; set; }
|
||||
|
||||
[AlternativeName("ConfigurationModel")]
|
||||
public required ServiceConfiguration Configuration { get; set; }
|
||||
|
||||
public Worker? Worker { get; set; }
|
||||
|
||||
public DateTime ServiceDate { get; set; }
|
||||
|
||||
[AlternativeName("Materials")]
|
||||
[ForeignKey("ServiceId")]
|
||||
public List<ServiceMaterial>? ServiceMaterials { get; set; }
|
||||
|
||||
|
||||
@@ -27,31 +27,6 @@ internal class ReportControllerTests : BaseWebApiControllerTest
|
||||
PimpMyRideDbContext.RemoveClientsFromDatabase();
|
||||
}
|
||||
|
||||
[Test]
|
||||
public async Task GetCars_WhenHaveRecords_ShouldSuccess_Test()
|
||||
{
|
||||
//Arrange
|
||||
var Client1 = PimpMyRideDbContext.InsertClientToDatabaseAndReturn(fio: "name 1", phoneNumber: "89991112233");
|
||||
var Client2 = PimpMyRideDbContext.InsertClientToDatabaseAndReturn(fio: "name 2", phoneNumber: "89991112234");
|
||||
PimpMyRideDbContext.InsertCarToDatabaseAndReturn(clientId: Client1.Id, make: "name 1.1", stateNumber: "911");
|
||||
PimpMyRideDbContext.InsertCarToDatabaseAndReturn(clientId: Client1.Id, make: "name 1.2", stateNumber: "912");
|
||||
PimpMyRideDbContext.InsertCarToDatabaseAndReturn(clientId: Client1.Id, make: "name 1.3", stateNumber: "913");
|
||||
PimpMyRideDbContext.InsertCarToDatabaseAndReturn(clientId: Client2.Id, make: "name 2.1", stateNumber: "914");
|
||||
PimpMyRideDbContext.InsertCarToDatabaseAndReturn(clientId: Client2.Id, make: "name 2.2", stateNumber: "915");
|
||||
//Act
|
||||
var response = await HttpClient.GetAsync("/api/report/getCars");
|
||||
//Assert
|
||||
Assert.That(response.StatusCode, Is.EqualTo(HttpStatusCode.OK));
|
||||
var data = await GetModelFromResponseAsync<List<ClientCarViewModel>>(response);
|
||||
Assert.That(data, Is.Not.Null);
|
||||
Assert.Multiple(() =>
|
||||
{
|
||||
Assert.That(data, Has.Count.EqualTo(2));
|
||||
Assert.That(data.First(x => x.ClientFIO == Client1.FIO).Cars, Has.Count.EqualTo(3));
|
||||
Assert.That(data.First(x => x.ClientFIO == Client2.FIO).Cars, Has.Count.EqualTo(2));
|
||||
});
|
||||
}
|
||||
|
||||
[Test]
|
||||
public async Task LoadCars_WhenHaveRecords_ShouldSuccess_Test()
|
||||
{
|
||||
|
||||
@@ -1,40 +1,28 @@
|
||||
using AutoMapper;
|
||||
using Microsoft.Extensions.Localization;
|
||||
using Microsoft.Extensions.Localization;
|
||||
using PimpMyRideContracts.AdapterContracts;
|
||||
using PimpMyRideContracts.AdapterContracts.OperationResponses;
|
||||
using PimpMyRideContracts.BindingModels;
|
||||
using PimpMyRideContracts.BusinessLogicsContracts;
|
||||
using PimpMyRideContracts.DataModels;
|
||||
using PimpMyRideContracts.Exceptions;
|
||||
using PimpMyRideContracts.Mapper;
|
||||
using PimpMyRideContracts.Resources;
|
||||
using PimpMyRideContracts.ViewModels;
|
||||
|
||||
namespace PimpMyRideWebApi.Adapters;
|
||||
|
||||
internal class CarAdapter : ICarAdapter
|
||||
internal class CarAdapter(ICarBusinessLogicContract carBusinessLogicContract, IStringLocalizer<Messages> localizer,
|
||||
ILogger logger) : ICarAdapter
|
||||
{
|
||||
private readonly ICarBusinessLogicContract _carBusinessLogicContract;
|
||||
private readonly IStringLocalizer<Messages> _localizer;
|
||||
private readonly ILogger _logger;
|
||||
private readonly Mapper _mapper;
|
||||
|
||||
public CarAdapter(ICarBusinessLogicContract carBusinessLogicContract, IStringLocalizer<Messages> localizer, ILogger<CarAdapter> logger)
|
||||
{
|
||||
_carBusinessLogicContract = carBusinessLogicContract;
|
||||
_logger = logger;
|
||||
var config = new MapperConfiguration(cfg => {
|
||||
cfg.CreateMap<CarBindingModel, CarDataModel>();
|
||||
cfg.CreateMap<CarDataModel, CarViewModel>();
|
||||
});
|
||||
_mapper = new Mapper(config);
|
||||
_localizer = localizer;
|
||||
}
|
||||
private readonly ICarBusinessLogicContract _carBusinessLogicContract = carBusinessLogicContract;
|
||||
private readonly IStringLocalizer<Messages> _localizer = localizer;
|
||||
private readonly ILogger _logger = logger;
|
||||
|
||||
public CarOperationResponse GetList()
|
||||
{
|
||||
try
|
||||
{
|
||||
return CarOperationResponse.OK([.. _carBusinessLogicContract.GetAllCars().Select(x => _mapper.Map<CarViewModel>(x))]);
|
||||
return CarOperationResponse.OK([.. _carBusinessLogicContract.GetAllCars().Select(x => CustomMapper.MapObject<CarViewModel>(x))]);
|
||||
}
|
||||
catch (StorageException ex)
|
||||
{
|
||||
@@ -52,7 +40,7 @@ internal class CarAdapter : ICarAdapter
|
||||
{
|
||||
try
|
||||
{
|
||||
return CarOperationResponse.OK([.. _carBusinessLogicContract.GetAllCarsByClient(id).Select(x => _mapper.Map<CarViewModel>(x))]);
|
||||
return CarOperationResponse.OK([.. _carBusinessLogicContract.GetAllCarsByClient(id).Select(x => CustomMapper.MapObject<CarViewModel>(x))]);
|
||||
}
|
||||
catch (ValidationException ex)
|
||||
{
|
||||
@@ -75,7 +63,7 @@ internal class CarAdapter : ICarAdapter
|
||||
{
|
||||
try
|
||||
{
|
||||
return CarOperationResponse.OK([.. _carBusinessLogicContract.GetAllCarsByMake(make, model).Select(x => _mapper.Map<CarViewModel>(x))]);
|
||||
return CarOperationResponse.OK([.. _carBusinessLogicContract.GetAllCarsByMake(make, model).Select(x => CustomMapper.MapObject<CarViewModel>(x))]);
|
||||
}
|
||||
catch (ValidationException ex)
|
||||
{
|
||||
@@ -99,7 +87,7 @@ internal class CarAdapter : ICarAdapter
|
||||
try
|
||||
{
|
||||
return
|
||||
CarOperationResponse.OK(_mapper.Map<CarViewModel>(_carBusinessLogicContract.GetCarByData(data)));
|
||||
CarOperationResponse.OK(CustomMapper.MapObject<CarViewModel>(_carBusinessLogicContract.GetCarByData(data)));
|
||||
}
|
||||
catch (ArgumentNullException ex)
|
||||
{
|
||||
@@ -127,7 +115,7 @@ internal class CarAdapter : ICarAdapter
|
||||
{
|
||||
try
|
||||
{
|
||||
_carBusinessLogicContract.InsertCar(_mapper.Map<CarDataModel>(carModel));
|
||||
_carBusinessLogicContract.InsertCar(CustomMapper.MapObject<CarDataModel>(carModel));
|
||||
return CarOperationResponse.NoContent();
|
||||
}
|
||||
catch (ArgumentNullException ex)
|
||||
@@ -161,7 +149,7 @@ internal class CarAdapter : ICarAdapter
|
||||
{
|
||||
try
|
||||
{
|
||||
_carBusinessLogicContract.UpdateCar(_mapper.Map<CarDataModel>(carModel));
|
||||
_carBusinessLogicContract.UpdateCar(CustomMapper.MapObject<CarDataModel>(carModel));
|
||||
return CarOperationResponse.NoContent();
|
||||
}
|
||||
catch (ArgumentNullException ex)
|
||||
|
||||
@@ -1,5 +1,4 @@
|
||||
using AutoMapper;
|
||||
using Microsoft.Extensions.Localization;
|
||||
using Microsoft.Extensions.Localization;
|
||||
using PimpMyRideContracts.AdapterContracts;
|
||||
using PimpMyRideContracts.AdapterContracts.OperationResponses;
|
||||
using PimpMyRideContracts.BindingModels;
|
||||
@@ -8,33 +7,22 @@ using PimpMyRideContracts.DataModels;
|
||||
using PimpMyRideContracts.Exceptions;
|
||||
using PimpMyRideContracts.Resources;
|
||||
using PimpMyRideContracts.ViewModels;
|
||||
using PimpMyRideContracts.Mapper;
|
||||
|
||||
namespace PimpMyRideWebApi.Adapters;
|
||||
|
||||
internal class ClientAdapter : IClientAdapter
|
||||
internal class ClientAdapter(IClientBusinessLogicContract clientBusinessLogicContract, IStringLocalizer<Messages> localizer,
|
||||
ILogger logger) : IClientAdapter
|
||||
{
|
||||
private readonly IClientBusinessLogicContract _clientBusinessLogicContract;
|
||||
private readonly IStringLocalizer<Messages> _localizer;
|
||||
private readonly ILogger _logger;
|
||||
private readonly Mapper _mapper;
|
||||
|
||||
public ClientAdapter(IClientBusinessLogicContract clientBusinessLogicContract, IStringLocalizer<Messages> localizer, ILogger<ClientAdapter> logger)
|
||||
{
|
||||
_clientBusinessLogicContract = clientBusinessLogicContract;
|
||||
_logger = logger;
|
||||
var config = new MapperConfiguration(cfg => {
|
||||
cfg.CreateMap<ClientBindingModel, ClientDataModel>();
|
||||
cfg.CreateMap<ClientDataModel, ClientViewModel>();
|
||||
});
|
||||
_mapper = new Mapper(config);
|
||||
_localizer = localizer;
|
||||
}
|
||||
private readonly IClientBusinessLogicContract _clientBusinessLogicContract = clientBusinessLogicContract;
|
||||
private readonly IStringLocalizer<Messages> _localizer = localizer;
|
||||
private readonly ILogger _logger = logger;
|
||||
|
||||
public ClientOperationResponse GetList()
|
||||
{
|
||||
try
|
||||
{
|
||||
return ClientOperationResponse.OK([.. _clientBusinessLogicContract.GetAllClients().Select(x => _mapper.Map<ClientViewModel>(x))]);
|
||||
return ClientOperationResponse.OK([.. _clientBusinessLogicContract.GetAllClients().Select(x => CustomMapper.MapObject<ClientViewModel>(x))]);
|
||||
}
|
||||
catch (StorageException ex)
|
||||
{
|
||||
@@ -53,7 +41,7 @@ internal class ClientAdapter : IClientAdapter
|
||||
try
|
||||
{
|
||||
return
|
||||
ClientOperationResponse.OK(_mapper.Map<ClientViewModel>(_clientBusinessLogicContract.GetClientByData(data)));
|
||||
ClientOperationResponse.OK(CustomMapper.MapObject<ClientViewModel>(_clientBusinessLogicContract.GetClientByData(data)));
|
||||
}
|
||||
catch (ArgumentNullException ex)
|
||||
{
|
||||
@@ -81,7 +69,7 @@ internal class ClientAdapter : IClientAdapter
|
||||
{
|
||||
try
|
||||
{
|
||||
_clientBusinessLogicContract.InsertClient(_mapper.Map<ClientDataModel>(clientModel));
|
||||
_clientBusinessLogicContract.InsertClient(CustomMapper.MapObject<ClientDataModel>(clientModel));
|
||||
return ClientOperationResponse.NoContent();
|
||||
}
|
||||
catch (ArgumentNullException ex)
|
||||
@@ -115,7 +103,7 @@ internal class ClientAdapter : IClientAdapter
|
||||
{
|
||||
try
|
||||
{
|
||||
_clientBusinessLogicContract.UpdateClient(_mapper.Map<ClientDataModel>(clientModel));
|
||||
_clientBusinessLogicContract.UpdateClient(CustomMapper.MapObject<ClientDataModel>(clientModel));
|
||||
return ClientOperationResponse.NoContent();
|
||||
}
|
||||
catch (ArgumentNullException ex)
|
||||
|
||||
@@ -1,6 +1,4 @@
|
||||
using AutoMapper;
|
||||
using DocumentFormat.OpenXml.Office2010.Excel;
|
||||
using Microsoft.Extensions.Localization;
|
||||
using Microsoft.Extensions.Localization;
|
||||
using PimpMyRideContracts.AdapterContracts;
|
||||
using PimpMyRideContracts.AdapterContracts.OperationResponses;
|
||||
using PimpMyRideContracts.BindingModels;
|
||||
@@ -8,40 +6,26 @@ using PimpMyRideContracts.BusinessLogicsContracts;
|
||||
using PimpMyRideContracts.DataModels;
|
||||
using PimpMyRideContracts.Enums;
|
||||
using PimpMyRideContracts.Exceptions;
|
||||
using PimpMyRideContracts.Mapper;
|
||||
using PimpMyRideContracts.Resources;
|
||||
using PimpMyRideContracts.ViewModels;
|
||||
|
||||
namespace PimpMyRideWebApi.Adapters;
|
||||
|
||||
internal class MaterialAdapter : IMaterialAdapter
|
||||
internal class MaterialAdapter(IMaterialBusinessLogicContract materialBusinessLogicContract, IStringLocalizer<Messages> localizer,
|
||||
ILogger logger) : IMaterialAdapter
|
||||
{
|
||||
private readonly IMaterialBusinessLogicContract _materialBusinessLogicContract;
|
||||
private readonly IMaterialBusinessLogicContract _materialBusinessLogicContract = materialBusinessLogicContract;
|
||||
|
||||
private readonly IStringLocalizer<Messages> _localizer;
|
||||
private readonly IStringLocalizer<Messages> _localizer = localizer;
|
||||
|
||||
private readonly ILogger _logger;
|
||||
|
||||
private readonly Mapper _mapper;
|
||||
|
||||
public MaterialAdapter(IMaterialBusinessLogicContract materialBusinessLogicContract, IStringLocalizer<Messages> localizer, ILogger<MaterialAdapter> logger)
|
||||
{
|
||||
_materialBusinessLogicContract = materialBusinessLogicContract;
|
||||
_logger = logger;
|
||||
var config = new MapperConfiguration(cfg =>
|
||||
{
|
||||
cfg.CreateMap<MaterialBindingModel, MaterialDataModel>();
|
||||
cfg.CreateMap<MaterialDataModel, MaterialViewModel>();
|
||||
cfg.CreateMap<MaterialHistoryDataModel, MaterialHistoryViewModel>();
|
||||
});
|
||||
_mapper = new Mapper(config);
|
||||
_localizer = localizer;
|
||||
}
|
||||
private readonly ILogger _logger = logger;
|
||||
|
||||
public MaterialOperationResponse GetList()
|
||||
{
|
||||
try
|
||||
{
|
||||
return MaterialOperationResponse.OK([.. _materialBusinessLogicContract.GetAllMaterials().Select(x => _mapper.Map<MaterialViewModel>(x))]);
|
||||
return MaterialOperationResponse.OK([.. _materialBusinessLogicContract.GetAllMaterials().Select(x => CustomMapper.MapObject<MaterialViewModel>(x))]);
|
||||
}
|
||||
catch (StorageException ex)
|
||||
{
|
||||
@@ -59,7 +43,7 @@ internal class MaterialAdapter : IMaterialAdapter
|
||||
{
|
||||
try
|
||||
{
|
||||
return MaterialOperationResponse.OK([.. _materialBusinessLogicContract.GetAllMaterialsByType(materialType).Select(x => _mapper.Map<MaterialViewModel>(x))]);
|
||||
return MaterialOperationResponse.OK([.. _materialBusinessLogicContract.GetAllMaterialsByType(materialType).Select(x => CustomMapper.MapObject<MaterialViewModel>(x))]);
|
||||
}
|
||||
catch (ArgumentNullException ex)
|
||||
{
|
||||
@@ -87,7 +71,7 @@ internal class MaterialAdapter : IMaterialAdapter
|
||||
{
|
||||
try
|
||||
{
|
||||
return MaterialOperationResponse.OK([.. _materialBusinessLogicContract.GetMaterialHistoryById(id).Select(x => _mapper.Map<MaterialHistoryViewModel>(x))]);
|
||||
return MaterialOperationResponse.OK([.. _materialBusinessLogicContract.GetMaterialHistoryById(id).Select(x => CustomMapper.MapObject<MaterialHistoryViewModel>(x))]);
|
||||
}
|
||||
catch (ValidationException ex)
|
||||
{
|
||||
@@ -110,7 +94,7 @@ internal class MaterialAdapter : IMaterialAdapter
|
||||
{
|
||||
try
|
||||
{
|
||||
return MaterialOperationResponse.OK(_mapper.Map<MaterialViewModel>(_materialBusinessLogicContract.GetMaterialByData(data)));
|
||||
return MaterialOperationResponse.OK(CustomMapper.MapObject<MaterialViewModel>(_materialBusinessLogicContract.GetMaterialByData(data)));
|
||||
}
|
||||
catch (ArgumentNullException ex)
|
||||
{
|
||||
@@ -143,7 +127,7 @@ internal class MaterialAdapter : IMaterialAdapter
|
||||
{
|
||||
try
|
||||
{
|
||||
_materialBusinessLogicContract.InsertMaterial(_mapper.Map<MaterialDataModel>(materialModel));
|
||||
_materialBusinessLogicContract.InsertMaterial(CustomMapper.MapObject<MaterialDataModel>(materialModel));
|
||||
return MaterialOperationResponse.NoContent();
|
||||
}
|
||||
catch (ArgumentNullException ex)
|
||||
@@ -177,7 +161,7 @@ internal class MaterialAdapter : IMaterialAdapter
|
||||
{
|
||||
try
|
||||
{
|
||||
_materialBusinessLogicContract.UpdateMaterial(_mapper.Map<MaterialDataModel>(materialModel));
|
||||
_materialBusinessLogicContract.UpdateMaterial(CustomMapper.MapObject<MaterialDataModel>(materialModel));
|
||||
return MaterialOperationResponse.NoContent();
|
||||
}
|
||||
catch (ArgumentNullException ex)
|
||||
|
||||
@@ -1,50 +1,29 @@
|
||||
using AutoMapper;
|
||||
using Microsoft.Extensions.Localization;
|
||||
using Microsoft.Extensions.Localization;
|
||||
using PimpMyRideContracts.AdapterContracts;
|
||||
using PimpMyRideContracts.AdapterContracts.OperationResponses;
|
||||
using PimpMyRideContracts.BindingModels;
|
||||
using PimpMyRideContracts.BusinessLogicsContracts;
|
||||
using PimpMyRideContracts.DataModels;
|
||||
using PimpMyRideContracts.Exceptions;
|
||||
using PimpMyRideContracts.Mapper;
|
||||
using PimpMyRideContracts.Resources;
|
||||
using PimpMyRideContracts.ViewModels;
|
||||
|
||||
namespace PimpMyRideWebApi.Adapters;
|
||||
|
||||
internal class OrderAdapter : IOrderAdapter
|
||||
internal class OrderAdapter(IOrderBusinessLogicContract orderBusinessLogicContract, IStringLocalizer<Messages> localizer, ILogger<OrderAdapter> logger) : IOrderAdapter
|
||||
{
|
||||
private readonly IOrderBusinessLogicContract _orderBusinessLogicContract;
|
||||
private readonly IOrderBusinessLogicContract _orderBusinessLogicContract = orderBusinessLogicContract;
|
||||
|
||||
private readonly IStringLocalizer<Messages> _localizer;
|
||||
private readonly IStringLocalizer<Messages> _localizer = localizer;
|
||||
|
||||
private readonly ILogger _logger;
|
||||
|
||||
private readonly Mapper _mapper;
|
||||
|
||||
public OrderAdapter(IOrderBusinessLogicContract orderBusinessLogicContract, IStringLocalizer<Messages> localizer, ILogger<OrderAdapter> logger)
|
||||
{
|
||||
_orderBusinessLogicContract = orderBusinessLogicContract;
|
||||
_logger = logger;
|
||||
var config = new MapperConfiguration(cfg =>
|
||||
{
|
||||
cfg.CreateMap<OrderDataModel, OrderViewModel>();
|
||||
cfg.CreateMap<OrderServiceBindingModel, OrderServiceDataModel>();
|
||||
cfg.CreateMap<OrderServiceDataModel, OrderServiceViewModel>();
|
||||
cfg.CreateMap<OrderBindingModel, OrderDataModel>()
|
||||
.ForCtorParam("id", opt => opt.MapFrom(src => src.Id))
|
||||
.ForCtorParam("carId", opt => opt.MapFrom(src => src.CarId))
|
||||
.ForCtorParam("isCancel", opt => opt.MapFrom(src => false))
|
||||
.ForCtorParam("orderServices", opt => opt.MapFrom(src => src.Services));
|
||||
});
|
||||
_mapper = new Mapper(config);
|
||||
_localizer = localizer;
|
||||
}
|
||||
private readonly ILogger _logger = logger;
|
||||
|
||||
public OrderOperationResponse GetList(DateTime fromDate, DateTime toDate)
|
||||
{
|
||||
try
|
||||
{
|
||||
return OrderOperationResponse.OK([.. _orderBusinessLogicContract.GetAllOrdersByPeriod(fromDate.ToUniversalTime(), toDate.ToUniversalTime()).Select(x => _mapper.Map<OrderViewModel>(x))]);
|
||||
return OrderOperationResponse.OK([.. _orderBusinessLogicContract.GetAllOrdersByPeriod(fromDate.ToUniversalTime(), toDate.ToUniversalTime()).Select(x => CustomMapper.MapObject<OrderViewModel>(x))]);
|
||||
}
|
||||
catch (IncorrectDatesException ex)
|
||||
{
|
||||
@@ -67,7 +46,7 @@ internal class OrderAdapter : IOrderAdapter
|
||||
{
|
||||
try
|
||||
{
|
||||
return OrderOperationResponse.OK([.. _orderBusinessLogicContract.GetAllOrdersByCarByPeriod(id, fromDate.ToUniversalTime(), toDate.ToUniversalTime()).Select(x => _mapper.Map<OrderViewModel>(x))]);
|
||||
return OrderOperationResponse.OK([.. _orderBusinessLogicContract.GetAllOrdersByCarByPeriod(id, fromDate.ToUniversalTime(), toDate.ToUniversalTime()).Select(x => CustomMapper.MapObject<OrderViewModel>(x))]);
|
||||
}
|
||||
catch (IncorrectDatesException ex)
|
||||
{
|
||||
@@ -95,7 +74,7 @@ internal class OrderAdapter : IOrderAdapter
|
||||
{
|
||||
try
|
||||
{
|
||||
return OrderOperationResponse.OK(_mapper.Map<OrderViewModel>(_orderBusinessLogicContract.GetOrderByData(id)));
|
||||
return OrderOperationResponse.OK(CustomMapper.MapObject<OrderViewModel>(_orderBusinessLogicContract.GetOrderByData(id)));
|
||||
}
|
||||
catch (ArgumentNullException ex)
|
||||
{
|
||||
@@ -128,8 +107,8 @@ internal class OrderAdapter : IOrderAdapter
|
||||
{
|
||||
try
|
||||
{
|
||||
var data = _mapper.Map<OrderDataModel>(orderModel);
|
||||
_orderBusinessLogicContract.InsertOrder(_mapper.Map<OrderDataModel>(orderModel));
|
||||
var data = CustomMapper.MapObject<OrderDataModel>(orderModel);
|
||||
_orderBusinessLogicContract.InsertOrder(CustomMapper.MapObject<OrderDataModel>(orderModel));
|
||||
return OrderOperationResponse.NoContent();
|
||||
}
|
||||
catch (ArgumentNullException ex)
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
using AutoMapper;
|
||||
//using AutoMapper;
|
||||
using Microsoft.Extensions.Localization;
|
||||
using PimpMyRideBusinessLogic.Implementations;
|
||||
using PimpMyRideContracts.AdapterContracts;
|
||||
@@ -7,40 +7,41 @@ using PimpMyRideContracts.BindingModels;
|
||||
using PimpMyRideContracts.BusinessLogicsContracts;
|
||||
using PimpMyRideContracts.DataModels;
|
||||
using PimpMyRideContracts.Exceptions;
|
||||
using PimpMyRideContracts.Mapper;
|
||||
using PimpMyRideContracts.Resources;
|
||||
using PimpMyRideContracts.ViewModels;
|
||||
|
||||
namespace PimpMyRideWebApi.Adapters;
|
||||
|
||||
internal class ReportAdapter : IReportAdapter
|
||||
internal class ReportAdapter(IReportContract reportContract, IStringLocalizer<Messages> localizer, ILogger<CarAdapter> logger) : IReportAdapter
|
||||
{
|
||||
private readonly IReportContract _reportContract;
|
||||
private readonly IReportContract _reportContract = reportContract;
|
||||
|
||||
private readonly IStringLocalizer<Messages> _localizer;
|
||||
private readonly IStringLocalizer<Messages> _localizer = localizer;
|
||||
|
||||
private readonly ILogger _logger;
|
||||
private readonly ILogger _logger = logger;
|
||||
|
||||
private readonly Mapper _mapper;
|
||||
//private readonly Mapper _mapper;
|
||||
|
||||
public ReportAdapter(IReportContract reportContract, IStringLocalizer<Messages> localizer, ILogger<CarAdapter> logger)
|
||||
{
|
||||
_reportContract = reportContract;
|
||||
_logger = logger;
|
||||
var config = new MapperConfiguration(cfg => {
|
||||
cfg.CreateMap<ClientCarDataModel, ClientCarViewModel>();
|
||||
cfg.CreateMap<OrderDataModel, OrderViewModel>();
|
||||
cfg.CreateMap<OrderServiceDataModel, OrderServiceViewModel>();
|
||||
cfg.CreateMap<WorkerServiceByPeriodDataModel, WorkerServiceByPeriodViewModel>();
|
||||
});
|
||||
_mapper = new Mapper(config);
|
||||
_localizer = localizer;
|
||||
}
|
||||
//public ReportAdapter(IReportContract reportContract, IStringLocalizer<Messages> localizer, ILogger<CarAdapter> logger)
|
||||
|
|
||||
//{
|
||||
// _reportContract = reportContract;
|
||||
// _logger = logger;
|
||||
// var config = new MapperConfiguration(cfg => {
|
||||
// cfg.CreateMap<ClientCarDataModel, ClientCarViewModel>();
|
||||
// cfg.CreateMap<OrderDataModel, OrderViewModel>();
|
||||
// cfg.CreateMap<OrderServiceDataModel, OrderServiceViewModel>();
|
||||
// cfg.CreateMap<WorkerServiceByPeriodDataModel, WorkerServiceByPeriodViewModel>();
|
||||
// });
|
||||
// _mapper = new Mapper(config);
|
||||
// _localizer = localizer;
|
||||
//}
|
||||
|
||||
public async Task<ReportOperationResponse> GetDataCarsByClientAsync(CancellationToken ct)
|
||||
{
|
||||
try
|
||||
{
|
||||
return ReportOperationResponse.OK([.. (await _reportContract.GetDataCarsByClientAsync(ct)).Select(x => _mapper.Map<ClientCarViewModel>(x))]);
|
||||
return ReportOperationResponse.OK([.. (await _reportContract.GetDataCarsByClientAsync(ct)).Select(x => CustomMapper.MapObject<ClientCarViewModel>(x))]);
|
||||
}
|
||||
catch (InvalidOperationException ex)
|
||||
{
|
||||
@@ -64,7 +65,7 @@ internal class ReportAdapter : IReportAdapter
|
||||
try
|
||||
{
|
||||
return ReportOperationResponse.OK((await _reportContract.GetDataOrderByPeriodAsync(dateStart.ToUniversalTime(), dateFinish.ToUniversalTime(), ct))
|
||||
.Select(x => _mapper.Map<OrderViewModel>(x)).ToList());
|
||||
.Select(x => CustomMapper.MapObject<OrderViewModel>(x)).ToList());
|
||||
}
|
||||
catch (IncorrectDatesException ex)
|
||||
{
|
||||
@@ -93,7 +94,7 @@ internal class ReportAdapter : IReportAdapter
|
||||
{
|
||||
try
|
||||
{
|
||||
return ReportOperationResponse.OK((await _reportContract.GetDataServiceByPeriodAsync(dateStart.ToUniversalTime(), dateFinish.ToUniversalTime(), ct)).Select(x => _mapper.Map<WorkerServiceByPeriodViewModel>(x)).ToList());
|
||||
return ReportOperationResponse.OK((await _reportContract.GetDataServiceByPeriodAsync(dateStart.ToUniversalTime(), dateFinish.ToUniversalTime(), ct)).Select(x => CustomMapper.MapObject<WorkerServiceByPeriodViewModel>(x)).ToList());
|
||||
}
|
||||
catch (IncorrectDatesException ex)
|
||||
{
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
using System.Text.Json;
|
||||
using AutoMapper;
|
||||
//using AutoMapper;
|
||||
using Microsoft.Extensions.Localization;
|
||||
using Newtonsoft.Json;
|
||||
using PimpMyRideContracts.AdapterContracts;
|
||||
@@ -10,52 +10,27 @@ using PimpMyRideContracts.DataModels;
|
||||
using PimpMyRideContracts.Enums;
|
||||
using PimpMyRideContracts.Exceptions;
|
||||
using PimpMyRideContracts.Infrastructure.ServiceConfiguration;
|
||||
using PimpMyRideContracts.Mapper;
|
||||
using PimpMyRideContracts.Resources;
|
||||
using PimpMyRideContracts.ViewModels;
|
||||
|
||||
namespace PimpMyRideWebApi.Adapters;
|
||||
|
||||
internal class ServiceAdapter : IServiceAdapter
|
||||
internal class ServiceAdapter(IServiceBusinessLogicContract serviceBusinessLogicContract, IStringLocalizer<Messages> localizer, ILogger<ServiceAdapter> logger) : IServiceAdapter
|
||||
{
|
||||
private readonly IServiceBusinessLogicContract _serviceBusinessLogicContract;
|
||||
private readonly IServiceBusinessLogicContract _serviceBusinessLogicContract = serviceBusinessLogicContract;
|
||||
|
||||
private readonly IStringLocalizer<Messages> _localizer;
|
||||
private readonly IStringLocalizer<Messages> _localizer = localizer;
|
||||
|
||||
private readonly ILogger _logger;
|
||||
|
||||
private readonly Mapper _mapper;
|
||||
private readonly ILogger _logger = logger;
|
||||
|
||||
private readonly JsonSerializerOptions JsonSerializerOptions = new() { PropertyNameCaseInsensitive = true };
|
||||
|
||||
public ServiceAdapter(IServiceBusinessLogicContract serviceBusinessLogicContract, IStringLocalizer<Messages> localizer, ILogger<ServiceAdapter> logger)
|
||||
{
|
||||
_serviceBusinessLogicContract = serviceBusinessLogicContract;
|
||||
_logger = logger;
|
||||
var config = new MapperConfiguration(cfg =>
|
||||
{
|
||||
cfg.CreateMap<ServiceBindingModel, ServiceDataModel>()
|
||||
.ConstructUsing(src => new ServiceDataModel(
|
||||
src.Id!,
|
||||
src.WorkerId,
|
||||
src.WorkType,
|
||||
src.ConfigurationJson!,
|
||||
src.Materials.Select(m => _mapper.Map<ServiceMaterialDataModel>(m)).ToList()
|
||||
));
|
||||
cfg.CreateMap<ServiceDataModel, ServiceViewModel>()
|
||||
.ForMember(dest => dest.WorkerFIO, opt => opt.MapFrom(src => src.WorkerFIO))
|
||||
.ForMember(x => x.Configuration, x => x.MapFrom(src => System.Text.Json.JsonSerializer.Serialize(src.ConfigurationModel, JsonSerializerOptions)));
|
||||
cfg.CreateMap<ServiceMaterialBindingModel, ServiceMaterialDataModel>();
|
||||
cfg.CreateMap<ServiceMaterialDataModel, ServiceMaterialViewModel>();
|
||||
});
|
||||
_mapper = new Mapper(config);
|
||||
_localizer = localizer;
|
||||
}
|
||||
|
||||
public ServiceOperationResponse GetList()
|
||||
{
|
||||
try
|
||||
{
|
||||
return ServiceOperationResponse.OK([.. _serviceBusinessLogicContract.GetAllServices().Select(x => _mapper.Map<ServiceViewModel>(x))]);
|
||||
return ServiceOperationResponse.OK([.. _serviceBusinessLogicContract.GetAllServices().Select(x => CustomMapper.MapObject<ServiceViewModel>(x))]);
|
||||
}
|
||||
catch (IncorrectDatesException ex)
|
||||
{
|
||||
@@ -78,7 +53,7 @@ internal class ServiceAdapter : IServiceAdapter
|
||||
{
|
||||
try
|
||||
{
|
||||
return ServiceOperationResponse.OK([.. _serviceBusinessLogicContract.GetAllServicesByWork(id, workType).Select(x => _mapper.Map<ServiceViewModel>(x))]);
|
||||
return ServiceOperationResponse.OK([.. _serviceBusinessLogicContract.GetAllServicesByWork(id, workType).Select(x => CustomMapper.MapObject<ServiceViewModel>(x))]);
|
||||
}
|
||||
catch (IncorrectDatesException ex)
|
||||
{
|
||||
@@ -106,7 +81,7 @@ internal class ServiceAdapter : IServiceAdapter
|
||||
{
|
||||
try
|
||||
{
|
||||
return ServiceOperationResponse.OK(_mapper.Map<ServiceViewModel>(_serviceBusinessLogicContract.GetServiceByData(data)));
|
||||
return ServiceOperationResponse.OK(CustomMapper.MapObject<ServiceViewModel>(_serviceBusinessLogicContract.GetServiceByData(data)));
|
||||
}
|
||||
catch (ArgumentNullException ex)
|
||||
{
|
||||
@@ -139,8 +114,8 @@ internal class ServiceAdapter : IServiceAdapter
|
||||
{
|
||||
try
|
||||
{
|
||||
var data = _mapper.Map<ServiceDataModel>(saleModel);
|
||||
_serviceBusinessLogicContract.InsertService(_mapper.Map<ServiceDataModel>(saleModel));
|
||||
var data = CustomMapper.MapObject<ServiceDataModel>(saleModel);
|
||||
_serviceBusinessLogicContract.InsertService(CustomMapper.MapObject<ServiceDataModel>(saleModel));
|
||||
return ServiceOperationResponse.NoContent();
|
||||
}
|
||||
catch (ArgumentNullException ex)
|
||||
|
||||
@@ -1,5 +1,4 @@
|
||||
using AutoMapper;
|
||||
using PimpMyRideContracts.AdapterContracts.OperationResponses;
|
||||
using PimpMyRideContracts.AdapterContracts.OperationResponses;
|
||||
using PimpMyRideContracts.AdapterContracts;
|
||||
using PimpMyRideContracts.BindingModels;
|
||||
using PimpMyRideContracts.BusinessLogicsContracts;
|
||||
@@ -9,37 +8,24 @@ using PimpMyRideContracts.ViewModels;
|
||||
using PimpMyRideContracts.Enums;
|
||||
using Microsoft.Extensions.Localization;
|
||||
using PimpMyRideContracts.Resources;
|
||||
using PimpMyRideContracts.Mapper;
|
||||
|
||||
namespace PimpMyRideWebApi.Adapters;
|
||||
|
||||
internal class WorkerAdapter : IWorkerAdapter
|
||||
internal class WorkerAdapter(IWorkerBusinessLogicContract workerBusinessLogicContract, IStringLocalizer<Messages> localizer,
|
||||
ILogger logger) : IWorkerAdapter
|
||||
{
|
||||
private readonly IWorkerBusinessLogicContract _buyerBusinessLogicContract;
|
||||
private readonly IWorkerBusinessLogicContract _workerBusinessLogicContract = workerBusinessLogicContract;
|
||||
|
||||
private readonly IStringLocalizer<Messages> _localizer;
|
||||
private readonly IStringLocalizer<Messages> _localizer = localizer;
|
||||
|
||||
private readonly ILogger _logger;
|
||||
|
||||
private readonly Mapper _mapper;
|
||||
|
||||
public WorkerAdapter(IWorkerBusinessLogicContract workerBusinessLogicContract, IStringLocalizer<Messages> localizer, ILogger<WorkerAdapter> logger)
|
||||
{
|
||||
_buyerBusinessLogicContract = workerBusinessLogicContract;
|
||||
_logger = logger;
|
||||
var config = new MapperConfiguration(cfg =>
|
||||
{
|
||||
cfg.CreateMap<WorkerBindingModel, WorkerDataModel>();
|
||||
cfg.CreateMap<WorkerDataModel, WorkerViewModel>();
|
||||
});
|
||||
_mapper = new Mapper(config);
|
||||
_localizer = localizer;
|
||||
}
|
||||
private readonly ILogger _logger = logger;
|
||||
|
||||
public WorkerOperationResponse GetList(bool includeDeleted)
|
||||
{
|
||||
try
|
||||
{
|
||||
return WorkerOperationResponse.OK([.. _buyerBusinessLogicContract.GetAllWorkers(!includeDeleted).Select(x => _mapper.Map<WorkerViewModel>(x))]);
|
||||
return WorkerOperationResponse.OK([.. _workerBusinessLogicContract.GetAllWorkers(!includeDeleted).Select(x => CustomMapper.MapObject<WorkerViewModel>(x))]);
|
||||
}
|
||||
catch (StorageException ex)
|
||||
{
|
||||
@@ -57,7 +43,7 @@ internal class WorkerAdapter : IWorkerAdapter
|
||||
{
|
||||
try
|
||||
{
|
||||
return WorkerOperationResponse.OK([.. _buyerBusinessLogicContract.GetAllWorkersBySpeciality(specialityType, !includeDeleted).Select(x => _mapper.Map<WorkerViewModel>(x))]);
|
||||
return WorkerOperationResponse.OK([.. _workerBusinessLogicContract.GetAllWorkersBySpeciality(specialityType, !includeDeleted).Select(x => CustomMapper.MapObject<WorkerViewModel>(x))]);
|
||||
}
|
||||
catch (ValidationException ex)
|
||||
{
|
||||
@@ -80,7 +66,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([.. _workerBusinessLogicContract.GetAllWorkersByBirthDate(fromDate.ToUniversalTime(), toDate.ToUniversalTime(), !includeDeleted).Select(x => CustomMapper.MapObject<WorkerViewModel>(x))]);
|
||||
}
|
||||
catch (IncorrectDatesException ex)
|
||||
{
|
||||
@@ -103,7 +89,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([.. _workerBusinessLogicContract.GetAllWorkersByEmploymentDate(fromDate.ToUniversalTime(), toDate.ToUniversalTime(), !includeDeleted).Select(x => CustomMapper.MapObject<WorkerViewModel>(x))]);
|
||||
}
|
||||
catch (IncorrectDatesException ex)
|
||||
{
|
||||
@@ -126,7 +112,7 @@ internal class WorkerAdapter : IWorkerAdapter
|
||||
{
|
||||
try
|
||||
{
|
||||
return WorkerOperationResponse.OK(_mapper.Map<WorkerViewModel>(_buyerBusinessLogicContract.GetWorkerByData(data)));
|
||||
return WorkerOperationResponse.OK(CustomMapper.MapObject<WorkerViewModel>(_workerBusinessLogicContract.GetWorkerByData(data)));
|
||||
}
|
||||
catch (ArgumentNullException ex)
|
||||
{
|
||||
@@ -159,7 +145,7 @@ internal class WorkerAdapter : IWorkerAdapter
|
||||
{
|
||||
try
|
||||
{
|
||||
_buyerBusinessLogicContract.InsertWorker(_mapper.Map<WorkerDataModel>(workerModel));
|
||||
_workerBusinessLogicContract.InsertWorker(CustomMapper.MapObject<WorkerDataModel>(workerModel));
|
||||
return WorkerOperationResponse.NoContent();
|
||||
}
|
||||
catch (ArgumentNullException ex)
|
||||
@@ -193,7 +179,7 @@ internal class WorkerAdapter : IWorkerAdapter
|
||||
{
|
||||
try
|
||||
{
|
||||
_buyerBusinessLogicContract.UpdateWorker(_mapper.Map<WorkerDataModel>(workerModel));
|
||||
_workerBusinessLogicContract.UpdateWorker(CustomMapper.MapObject<WorkerDataModel>(workerModel));
|
||||
return WorkerOperationResponse.NoContent();
|
||||
}
|
||||
catch (ArgumentNullException ex)
|
||||
@@ -232,7 +218,7 @@ internal class WorkerAdapter : IWorkerAdapter
|
||||
{
|
||||
try
|
||||
{
|
||||
_buyerBusinessLogicContract.DeleteWorker(id);
|
||||
_workerBusinessLogicContract.DeleteWorker(id);
|
||||
return WorkerOperationResponse.NoContent();
|
||||
}
|
||||
catch (ArgumentNullException ex)
|
||||
|
||||
Reference in New Issue
Block a user
Закомментированного кода быть не должно