Beispiel #1
0
        public async Task <Vm> UpdateAsync(Guid id, VmUpdateForm form, CancellationToken ct)
        {
            var vmEntity = await _context.Vms.Where(v => v.Id == id).SingleOrDefaultAsync(ct);

            if (vmEntity == null)
            {
                throw new EntityNotFoundException <Vm>();
            }

            var teams = vmEntity.VmTeams.Select(v => v.TeamId).Distinct();

            if (!(await _playerService.CanManageTeamsAsync(teams, false, ct)))
            {
                throw new ForbiddenException();
            }

            if (!(await _permissionsService.CanWrite(teams, ct)))
            {
                throw new ForbiddenException();
            }

            vmEntity = _mapper.Map(form, vmEntity);

            _context.Vms.Update(vmEntity);
            await _context.SaveChangesAsync(ct);

            return(_mapper.Map <Vm>(vmEntity));
        }
Beispiel #2
0
        public async Task <IActionResult> Update([FromRoute] Guid id, [FromBody] VmUpdateForm form, CancellationToken ct)
        {
            if (!ModelState.IsValid)
            {
                throw new InvalidOperationException();
            }

            var updatedVm = await _vmService.UpdateAsync(id, form, ct);

            return(Ok(updatedVm));
        }