Добавлен справочник ResponseArea
This commit is contained in:
@@ -0,0 +1,27 @@
|
||||
using AutoMapper;
|
||||
using PARR.DAL.Contracts;
|
||||
using PARR.DAL.Models;
|
||||
using PARR.DAL.Models.AIHIT;
|
||||
using System.Text.RegularExpressions;
|
||||
|
||||
namespace PARR.AIHIT.MappingProfiles.Resolvers
|
||||
{
|
||||
internal class ResponseAreaCodeResolver : IValueResolver<RawDataEK, Host, int>
|
||||
{
|
||||
public int Resolve(RawDataEK source, Host destination, int destMember, ResolutionContext context)
|
||||
{
|
||||
var pattern = "\\d+";
|
||||
var regex = new Regex(pattern);
|
||||
|
||||
int.TryParse(regex.Match(source.ResponseArea!).Value, out int result);
|
||||
|
||||
if (result == 0)
|
||||
return (int)ResponseAreaEnum.gvc;
|
||||
|
||||
if (!Enum.IsDefined(typeof(ResponseAreaEnum), result))
|
||||
throw new Exception($"Неверный код дороги {source.ResponseArea}");
|
||||
|
||||
return result;
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user