public async Task <ActionResult> EditScheme(Guid schemeId, SchemeViewModelBase model) { if (model.Status == SchemeStatus.Rejected) { return(RedirectToAction("ConfirmRejection", new { schemeId })); } if (model.Status == SchemeStatus.Withdrawn) { return(RedirectToAction("ConfirmWithdrawn", new { schemeId })); } model.CompetentAuthorities = await GetCompetentAuthorities(); if (!ModelState.IsValid) { model = await SetSchemeStatusAndCompetentAuthorities(schemeId, model); await SetBreadcrumb(schemeId, InternalUserActivity.ManageScheme); return(View(model)); } CreateOrUpdateSchemeInformationResult result; using (var client = apiClient()) { UpdateSchemeInformation request = new UpdateSchemeInformation( schemeId, model.SchemeName, model.ApprovalNumber, model.IbisCustomerReference, model.ObligationType.Value, model.CompetentAuthorityId, model.Status); result = await client.SendAsync(User.GetAccessToken(), request); await cache.InvalidateSchemeCache(schemeId); await cache.InvalidateOrganisationSearch(); } switch (result.Result) { case CreateOrUpdateSchemeInformationResult.ResultType.Success: return(RedirectToAction("Overview", new { schemeId })); case CreateOrUpdateSchemeInformationResult.ResultType.ApprovalNumberUniquenessFailure: { ModelState.AddModelError("ApprovalNumber", "Approval number already exists"); await SetBreadcrumb(schemeId, InternalUserActivity.ManageScheme); model = await SetSchemeStatusAndCompetentAuthorities(schemeId, model); return(View(model)); } case CreateOrUpdateSchemeInformationResult.ResultType.IbisCustomerReferenceUniquenessFailure: { string errorMessage = string.Format( "Billing reference \"{0}\" already exists for scheme \"{1}\" ({2})", result.IbisCustomerReferenceUniquenessFailure.IbisCustomerReference, result.IbisCustomerReferenceUniquenessFailure.OtherSchemeName, result.IbisCustomerReferenceUniquenessFailure.OtherSchemeApprovalNumber); ModelState.AddModelError("IbisCustomerReference", errorMessage); await SetBreadcrumb(schemeId, InternalUserActivity.ManageScheme); model = await SetSchemeStatusAndCompetentAuthorities(schemeId, model); return(View(model)); } case CreateOrUpdateSchemeInformationResult.ResultType.IbisCustomerReferenceMandatoryForEAFailure: ModelState.AddModelError("IbisCustomerReference", "Enter a customer billing reference"); await SetBreadcrumb(schemeId, InternalUserActivity.ManageScheme); model = await SetSchemeStatusAndCompetentAuthorities(schemeId, model); return(View(model)); default: throw new NotSupportedException(); } }