Beispiel #1
0
        public Task <Either <ActionResult, ContentSectionViewModel> > AddContentSection(
            Guid methodologyVersionId,
            ContentSectionAddRequest request,
            ContentListType contentType)
        {
            return(_persistenceHelper
                   .CheckEntityExists <MethodologyVersion>(methodologyVersionId)
                   .OnSuccess(CheckCanUpdateMethodology)
                   .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.MethodologyVersions.Update(methodology);
                await _context.SaveChangesAsync();
                return _mapper.Map <ContentSectionViewModel>(newContentSection);
            }));
        }
 public async Task <ActionResult <ContentSectionViewModel> > AddContentSection(
     Guid releaseId, ContentSectionAddRequest request = null)
 {
     return(await _contentService
            .AddContentSectionAsync(releaseId, request)
            .HandleFailuresOrOk());
 }
 public async Task <ActionResult <ContentSectionViewModel> > AddContentSection(
     Guid methodologyId,
     [FromQuery] MethodologyContentService.ContentListType type,
     ContentSectionAddRequest request = null)
 {
     return(await _contentService
            .AddContentSection(methodologyId, request, type)
            .HandleFailuresOrOk());
 }