protected override async Task HandleRequirementAsync(
            AuthorizationHandlerContext context,
            VaryLimitRequirement requirement,
            JobStatusUpdate resource
            )
        {
            var workOrder     = resource.RelatedWorkOrder;
            var contractorRef = workOrder.AssignedToPrimary.ContractorReference;

            var updatedCodes = resource.MoreSpecificSORCode.RateScheduleItem
                               .Select(rsi => new { rsi.CustomCode, Amount = rsi.Quantity.Amount }).ToList();

            var originalCodes = workOrder.WorkElements.SelectMany(we => we.RateScheduleItem).Where(rsi => rsi.Original).Select(rsi => new { rsi.OriginalQuantity, rsi.CustomCode });

            double totalCost = 0;
            await updatedCodes.ForEachAsync(async c => totalCost += c.Amount *await _sorGateway.GetCost(contractorRef, c.CustomCode));

            double originalCost = 0;
            await originalCodes.ForEachAsync(async c => originalCost += c.OriginalQuantity.Value *await _sorGateway.GetCost(contractorRef, c.CustomCode));

            var limit = double.Parse(context.User.FindFirst(CustomClaimTypes.VaryLimit).Value);

            if (totalCost <= originalCost + limit)
            {
                context.Succeed(requirement);
            }
        }
Beispiel #2
0
 private async Task AddCodeCosts(IEnumerable <RateScheduleItem> newCodes, string contractorReference)
 {
     foreach (var newCode in newCodes)
     {
         newCode.Original = false;
         newCode.CodeCost = await _scheduleOfRatesGateway.GetCost(contractorReference, newCode.CustomCode);
     }
 }
Beispiel #3
0
        protected override async Task HandleRequirementAsync(
            AuthorizationHandlerContext context,
            RaiseLimitRequirement requirement,
            WorkOrder resource
            )
        {
            var contractorRef = resource.AssignedToPrimary?.ContractorReference;
            var rawCodes      = resource.WorkElements
                                .SelectMany(we => we.RateScheduleItem)
                                .Select(rsi => new { rsi.CustomCode, rsi.Quantity.Amount });
            double totalCost = 0;
            await rawCodes.ForEachAsync(async c => totalCost += c.Amount *await _sorGateway.GetCost(contractorRef, c.CustomCode));

            var limit = double.Parse(context.User.FindFirst(CustomClaimTypes.RaiseLimit).Value);

            if (totalCost <= limit)
            {
                context.Succeed(requirement);
            }
        }
 private async Task <double?> GetCost(string contractorReference, string customCode)
 {
     return(await _scheduleOfRatesGateway.GetCost(contractorReference, customCode));
 }