예제 #1
0
        public async Task <RemoveApprenticeshipViewModel> GetVirtualApprenticeshipsForRemoval(string hashedAccountId, string apprenticeshipsId, string estimationName)
        {
            var estimations = await GetAccountEstimation(hashedAccountId);

            var virtualApprenticeships = estimations.FindVirtualApprenticeship(apprenticeshipsId);

            if (virtualApprenticeships == null)
            {
                throw new ApprenticeshipAlreadyRemovedException();
            }
            var vm = new RemoveApprenticeshipViewModel
            {
                ApprenticeshipId    = apprenticeshipsId,
                HashedAccountId     = hashedAccountId,
                NumberOfApprentices = virtualApprenticeships.ApprenticesCount,
                CourseTitle         = virtualApprenticeships.CourseTitle,
                Level          = virtualApprenticeships.Level,
                EstimationName = estimationName
            };

            return(vm);
        }
예제 #2
0
        public async Task <ActionResult> RemoveApprenticeships(RemoveApprenticeshipViewModel viewModel, string hashedAccountId, string estimationName, string id)
        {
            if (viewModel.ConfirmedDeletion.HasValue && viewModel.ConfirmedDeletion.Value)
            {
                await _addApprenticeshipOrchestrator.RemoveApprenticeship(hashedAccountId, id);

                return(await _estimationOrchestrator.HasValidApprenticeships(hashedAccountId)
                ? RedirectToAction(nameof(CostEstimation), new { hashedaccountId = hashedAccountId, estimateName = Constants.DefaultEstimationName, apprenticeshipRemoved = true })
                : RedirectToAction(nameof(StartEstimation), new { hashedaccountId = hashedAccountId }));
            }
            else if (viewModel.ConfirmedDeletion.HasValue && !viewModel.ConfirmedDeletion.Value)
            {
                return(RedirectToAction(nameof(CostEstimation),
                                        new
                {
                    hashedaccountId = hashedAccountId,
                    estimateName = estimationName,
                    apprenticeshipRemoved = false
                }));
            }

            return(View(nameof(ConfirmApprenticeshipsRemoval), viewModel));
        }