public async STT.Task <ViewModels.Result> UpdateAsync(Guid id, ViewModels.Result result, CancellationToken ct) { if (!(await _authorizationService.AuthorizeAsync(_user, null, new ContentDeveloperRequirement())).Succeeded) { throw new ForbiddenException(); } var resultToUpdate = await _context.Results.SingleOrDefaultAsync(v => v.Id == id, ct); if (resultToUpdate == null) { throw new EntityNotFoundException <SAVM.Result>(); } result.DateCreated = resultToUpdate.DateCreated; result.CreatedBy = resultToUpdate.CreatedBy; result.DateModified = DateTime.UtcNow; result.ModifiedBy = _user.GetId(); _mapper.Map(result, resultToUpdate); _context.Results.Update(resultToUpdate); await _context.SaveChangesAsync(ct); return(_mapper.Map(resultToUpdate, result)); }
public async STT.Task <ViewModels.Result> CreateAsync(ViewModels.Result result, CancellationToken ct) { if (!(await _authorizationService.AuthorizeAsync(_user, null, new ContentDeveloperRequirement())).Succeeded) { throw new ForbiddenException(); } result.DateCreated = DateTime.UtcNow; result.CreatedBy = _user.GetId(); var resultEntity = _mapper.Map <ResultEntity>(result); //TODO: add permissions // var ResultAdminPermission = await _context.Permissions // .Where(p => p.Key == PlayerClaimTypes.ResultAdmin.ToString()) // .FirstOrDefaultAsync(); // if (ResultAdminPermission == null) // throw new EntityNotFoundException<Permission>($"{PlayerClaimTypes.ResultAdmin.ToString()} Permission not found."); _context.Results.Add(resultEntity); await _context.SaveChangesAsync(ct); return(await GetAsync(resultEntity.Id, ct)); }