public async STT.Task <ViewModels.Scenario> CreateAsync(ViewModels.ScenarioForm scenarioForm, CancellationToken ct) { if (!(await _authorizationService.AuthorizeAsync(_user, null, new ContentDeveloperRequirement())).Succeeded) { throw new ForbiddenException(); } var scenarioEntity = _mapper.Map <ScenarioEntity>(scenarioForm); scenarioEntity.DateCreated = DateTime.UtcNow; scenarioEntity.CreatedBy = _user.GetId(); //TODO: add permissions // var ScenarioAdminPermission = await _context.Permissions // .Where(p => p.Key == PlayerClaimTypes.ScenarioAdmin.ToString()) // .FirstOrDefaultAsync(); // if (ScenarioAdminPermission == null) // throw new EntityNotFoundException<Permission>($"{PlayerClaimTypes.ScenarioAdmin.ToString()} Permission not found."); _context.Scenarios.Add(scenarioEntity); await _context.SaveChangesAsync(ct); var scenario = await GetAsync(scenarioEntity.Id, ct); return(scenario); }
public async STT.Task <SAVM.Scenario> UpdateAsync(Guid id, ViewModels.ScenarioForm scenarioForm, CancellationToken ct) { if (!(await _authorizationService.AuthorizeAsync(_user, null, new ContentDeveloperRequirement())).Succeeded) { throw new ForbiddenException(); } var scenarioToUpdate = await _context.Scenarios.SingleOrDefaultAsync(v => v.Id == id, ct); if (scenarioToUpdate == null) { throw new EntityNotFoundException <SAVM.Scenario>(); } _mapper.Map(scenarioForm, scenarioToUpdate); scenarioToUpdate.DateModified = DateTime.UtcNow; scenarioToUpdate.ModifiedBy = _user.GetId(); await _context.SaveChangesAsync(ct); var updatedScenario = _mapper.Map <SAVM.Scenario>(scenarioToUpdate); return(updatedScenario); }