public async STT.Task <SAVM.VmCredential> UpdateAsync(Guid id, SAVM.VmCredential vmCredential, CancellationToken ct)
        {
            if (!(await _authorizationService.AuthorizeAsync(_user, null, new ContentDeveloperRequirement())).Succeeded)
            {
                throw new ForbiddenException();
            }

            var vmCredentialToUpdate = await _context.VmCredentials.SingleOrDefaultAsync(v => v.Id == id, ct);

            if (vmCredentialToUpdate == null)
            {
                throw new EntityNotFoundException <SAVM.VmCredential>();
            }

            vmCredential.CreatedBy    = vmCredentialToUpdate.CreatedBy;
            vmCredential.DateCreated  = vmCredentialToUpdate.DateCreated;
            vmCredential.DateModified = DateTime.UtcNow;
            vmCredential.ModifiedBy   = _user.GetId();
            _mapper.Map(vmCredential, vmCredentialToUpdate);

            _context.VmCredentials.Update(vmCredentialToUpdate);
            await _context.SaveChangesAsync(ct);

            var updatedVmCredential = _mapper.Map(vmCredentialToUpdate, vmCredential);

            return(updatedVmCredential);
        }
        public async STT.Task <SAVM.VmCredential> CreateAsync(SAVM.VmCredential vmCredential, CancellationToken ct)
        {
            if (!(await _authorizationService.AuthorizeAsync(_user, null, new ContentDeveloperRequirement())).Succeeded)
            {
                throw new ForbiddenException();
            }

            if (vmCredential.ScenarioTemplateId == null && vmCredential.ScenarioId == null)
            {
                throw new ArgumentException("A VmCredential MUST be associated to either a Scenario Template or a Scenario.");
            }

            vmCredential.DateCreated = DateTime.UtcNow;
            vmCredential.CreatedBy   = _user.GetId();
            var vmCredentialEntity = _mapper.Map <VmCredentialEntity>(vmCredential);

            _context.VmCredentials.Add(vmCredentialEntity);
            await _context.SaveChangesAsync(ct);

            vmCredential = await GetAsync(vmCredentialEntity.Id, ct);

            return(vmCredential);
        }
        public async STT.Task <IActionResult> Update([FromRoute] Guid id, [FromBody] SAVM.VmCredential vmCredential, CancellationToken ct)
        {
            var updatedVmCredential = await _VmCredentialService.UpdateAsync(id, vmCredential, ct);

            return(Ok(updatedVmCredential));
        }
        public async STT.Task <IActionResult> Create([FromBody] SAVM.VmCredential vmCredential, CancellationToken ct)
        {
            var createdVmCredential = await _VmCredentialService.CreateAsync(vmCredential, ct);

            return(CreatedAtAction(nameof(this.Get), new { id = createdVmCredential.Id }, createdVmCredential));
        }