public async Task <ActionResult <MethodologyVersionSummaryViewModel> > UpdateMethodology(
     Guid methodologyVersionId,
     MethodologyUpdateRequest request)
 {
     return(await _methodologyService
            .UpdateMethodology(methodologyVersionId, request)
            .HandleFailuresOrOk());
 }
        public async Task UpdateMethodology_Returns_Ok()
        {
            var request = new MethodologyUpdateRequest();

            var methodologyService = new Mock <IMethodologyService>(Strict);

            methodologyService
            .Setup(s => s.UpdateMethodology(_id, request))
            .ReturnsAsync(new MethodologyVersionSummaryViewModel());

            var controller = SetupMethodologyController(methodologyService.Object);

            var result = await controller.UpdateMethodology(_id, request);

            VerifyAllMocks(methodologyService);

            result.AssertOkResult();
        }
コード例 #3
0
        private async Task <Either <ActionResult, MethodologyVersion> > UpdateDetails(
            MethodologyVersion methodologyVersionToUpdate,
            MethodologyUpdateRequest request)
        {
            if (!request.IsDetailUpdateForMethodology(methodologyVersionToUpdate))
            {
                // Details unchanged
                return(methodologyVersionToUpdate);
            }

            return(await _userService.CheckCanUpdateMethodology(methodologyVersionToUpdate)
                   // Check that the Methodology will have a unique slug.  It is possible to have a clash in the case where
                   // another Methodology has previously set its AlternativeTitle (and Slug) to something specific and then
                   // this Methodology attempts to set its AlternativeTitle (and Slug) to the same value.  Whilst an
                   // unlikely scenario, it's entirely possible.
                   .OnSuccessDo(methodologyVersion =>
                                ValidateMethodologySlugUniqueForUpdate(methodologyVersion.Id, request.Slug))
                   .OnSuccess(async methodologyVersion =>
            {
                methodologyVersion.Updated = DateTime.UtcNow;

                if (request.Title != methodologyVersion.Title)
                {
                    methodologyVersion.AlternativeTitle =
                        request.Title != methodologyVersion.Methodology.OwningPublicationTitle
                                ? request.Title
                                : null;

                    // If we're updating a Methodology that is not an Amendment, it's not yet publicly
                    // visible and so its Slug can be updated.  At the point that a Methodology is publicly
                    // visible and the only means of updating it is via Amendments, we will no longer allow its
                    // Slug to change even though its AlternativeTitle can.
                    if (!methodologyVersion.Amendment)
                    {
                        methodologyVersion.Methodology.Slug = request.Slug;
                    }
                }

                await _context.SaveChangesAsync();

                return methodologyVersion;
            }));
        }
コード例 #4
0
 public async Task <Either <ActionResult, MethodologyVersionSummaryViewModel> > UpdateMethodology(Guid id,
                                                                                                  MethodologyUpdateRequest request)
 {
     return(await _persistenceHelper
            .CheckEntityExists <MethodologyVersion>(id, q =>
                                                    q.Include(m => m.Methodology))
            .OnSuccess(methodology => UpdateStatus(methodology, request))
            .OnSuccess(methodology => UpdateDetails(methodology, request))
            .OnSuccess(_ => GetSummary(id)));
 }