public async Task <ActionResult <LegacyReleaseViewModel> > CreateLegacyRelease( CreateLegacyReleaseViewModel legacyRelease) { return(await _legacyReleaseService .CreateLegacyRelease(legacyRelease) .HandleFailuresOrOk()); }
public async Task <Either <ActionResult, LegacyReleaseViewModel> > CreateLegacyRelease( CreateLegacyReleaseViewModel legacyRelease) { return(await _persistenceHelper .CheckEntityExists <Publication>( legacyRelease.PublicationId, publication => publication.Include(p => p.LegacyReleases) ) .OnSuccess(_userService.CheckCanCreateLegacyRelease) .OnSuccess(async publication => { var saved = await _context.LegacyReleases.AddAsync(new LegacyRelease { Description = legacyRelease.Description, Url = legacyRelease.Url, Order = publication.LegacyReleases.Count > 0 ? publication.LegacyReleases.Max(release => release.Order) + 1 : 1, PublicationId = legacyRelease.PublicationId }); await _context.SaveChangesAsync(); return _mapper.Map <LegacyReleaseViewModel>(saved.Entity); })); }