public Task <Either <ActionResult, ContentSectionViewModel> > AddContentSectionAsync( Guid releaseId, AddContentSectionRequest request) { return(_persistenceHelper .CheckEntityExists <Release>(releaseId, HydrateContentSectionsAndBlocks) .OnSuccess(CheckCanUpdateRelease) .OnSuccess(async release => { var orderForNewSection = request?.Order ?? release.GenericContent.Max(contentSection => contentSection.Order) + 1; release.GenericContent .ToList() .FindAll(contentSection => contentSection.Order >= orderForNewSection) .ForEach(contentSection => contentSection.Order++); var newContentSection = new ContentSection { Heading = "New section", Order = orderForNewSection }; release.AddGenericContentSection(newContentSection); _context.Releases.Update(release); await _context.SaveChangesAsync(); return _mapper.Map <ContentSectionViewModel>(newContentSection); })); }
public Task <Either <ActionResult, ContentSectionViewModel> > AddContentSectionAsync( Guid methodologyId, AddContentSectionRequest request, ContentListType contentType) { return(_persistenceHelper .CheckEntityExists <Methodology>(methodologyId) .OnSuccess(CheckCanUpdateMethodology) .OnSuccess(EnsureMethodologyContentAndAnnexListsNotNull) .OnSuccess(async methodology => { var content = ContentListSelector[contentType](methodology); var orderForNewSection = request?.Order ?? content.Max(contentSection => contentSection.Order) + 1; content .FindAll(contentSection => contentSection.Order >= orderForNewSection) .ForEach(contentSection => contentSection.Order++); var newContentSection = new ContentSection { Id = Guid.NewGuid(), Heading = "New section", Order = orderForNewSection }; content.Add(newContentSection); _context.Methodologies.Update(methodology); await _context.SaveChangesAsync(); return _mapper.Map <ContentSectionViewModel>(newContentSection); })); }
public async Task <ActionResult <ContentSectionViewModel> > AddContentSection( Guid methodologyId, [FromQuery] MethodologyContentService.ContentListType type, AddContentSectionRequest request = null) { return(await _contentService .AddContentSectionAsync(methodologyId, request, type) .HandleFailuresOrOk()); }