Beispiel #1
0
        public async Task <ActionResult> RecoveryCost(Guid id, bool?backToOverview = null)
        {
            object percentageResult;
            object estimatedValueAmountResult;
            object estimatedValueUnitResult;
            object shipmentInfoUnitsResult;

            if (TempData.TryGetValue(PercentageKey, out percentageResult) &&
                TempData.TryGetValue(EstimatedValueAmountKey, out estimatedValueAmountResult) &&
                TempData.TryGetValue(EstimatedValueUnitKey, out estimatedValueUnitResult) &&
                TempData.TryGetValue(ShipmentInfoUnitsKey, out shipmentInfoUnitsResult))
            {
                var recoveryCost = await mediator.SendAsync(new GetRecoveryCost(id));

                var estimatedValue    = Convert.ToDecimal(estimatedValueAmountResult);
                var unit              = (ValuePerWeightUnits)estimatedValueUnitResult;
                var percentage        = Convert.ToDecimal(percentageResult);
                var shipmentInfoUnits = (ValuePerWeightUnits)shipmentInfoUnitsResult;

                var model = new RecoveryCostViewModel(
                    percentage,
                    new ValuePerWeightData(estimatedValue, unit),
                    recoveryCost,
                    shipmentInfoUnits);

                return(View(model));
            }

            return(RedirectToAction("Percentage", "WasteRecovery", new { backToOverview }));
        }
Beispiel #2
0
        public async Task <ActionResult> RecoveryCost(Guid id, RecoveryCostViewModel model, bool?backToOverview)
        {
            if (!ModelState.IsValid)
            {
                return(View(model));
            }

            var saveData = new SaveWasteRecovery(id,
                                                 model.PercentageRecoverable,
                                                 new ValuePerWeightData(model.EstimatedValueAmount, model.EstimatedValueUnit),
                                                 new ValuePerWeightData(model.Amount.ToMoneyDecimal(), model.SelectedUnits.Value));

            var recoveryCost = await mediator.SendAsync(new GetRecoveryCost(id));

            var estimatedValue = await mediator.SendAsync(new GetEstimatedValue(id));

            var percentageRecoverable = await mediator.SendAsync(new GetRecoverablePercentage(id));

            await mediator.SendAsync(saveData);

            if (recoveryCost == null || estimatedValue == null || percentageRecoverable == null)
            {
                await this.AddAuditData(id, NotificationAuditType.Added, NotificationAuditScreenType.WasteRecovery);
            }
            else
            {
                if (recoveryCost.Amount != saveData.RecoveryCost.Amount || recoveryCost.Unit != saveData.RecoveryCost.Unit ||
                    estimatedValue.Amount != saveData.EstimatedValue.Amount || estimatedValue.Unit != saveData.EstimatedValue.Unit ||
                    percentageRecoverable != saveData.PercentageRecoverable)
                {
                    await this.AddAuditData(id, NotificationAuditType.Updated, NotificationAuditScreenType.WasteRecovery);
                }
            }

            if (model.PercentageRecoverable < 100)
            {
                return(RedirectToAction("DisposalMethod", "WasteRecovery"));
            }

            return(RedirectToAction("Index", "Home"));
        }