Esempio n. 1
0
        public async Task <ProCoSysResponsible> TryGetResponsibleAsync(string plant, string code)
        {
            if (!await _plantCache.HasCurrentUserAccessToPlantAsync(plant))
            {
                throw new ArgumentException($"Invalid plant: {plant}");
            }

            var url = $"{_baseAddress}Library/Responsible" +
                      $"?plantId={plant}" +
                      $"&code={WebUtility.UrlEncode(code)}" +
                      $"&api-version={_apiVersion}";

            return(await _mainApiClient.TryQueryAndDeserializeAsync <ProCoSysResponsible>(url));
        }
        public CloneCommandValidator(IPlantCache plantCache)
        {
            CascadeMode = CascadeMode.Stop;

            RuleFor(command => command.SourcePlant)
            .MustAsync((_, sourcePlant, token) => UserHaveAccessToPlantAsync(sourcePlant.ToUpperInvariant()))
            .WithMessage(command => $"Source plant is not valid or access missing! Plant={command.SourcePlant}");

            RuleFor(command => command.TargetPlant)
            .MustAsync((_, targetPlant, token) => UserHaveAccessToPlantAsync(targetPlant.ToUpperInvariant()))
            .WithMessage(command => $"Target plant is not valid or access missing! Plant={command.TargetPlant}")
            .Must((_, targetPlant, token) => NotBeABasisPlant(targetPlant.ToUpperInvariant()))
            .WithMessage(command => $"Target plant can not be a basis plant! Plant={command.TargetPlant}");

            async Task <bool> UserHaveAccessToPlantAsync(string plantId)
            => await plantCache.HasCurrentUserAccessToPlantAsync(plantId);

            bool NotBeABasisPlant(string plantId) => !BasisPlants.Contains(plantId);
        }