Пример #1
0
        public async Task <ActionResult> DeleteCronjob(Guid id, CancellationToken cancellationToken)
        {
            var cronjob = await _db.Cronjobs.SingleOrDefaultAsync(
                e => e.Id == id, cancellationToken : cancellationToken
                );

            if (cronjob is null)
            {
                return(NotFound());
            }

            var result = await _authorizationService.AuthorizeAsync(User, cronjob, AuthorizationPolicies.RequireProjectManagerPolicy);

            if (!result.Succeeded)
            {
                return(Forbid());
            }

            await using var tx = await _db.Database.BeginTransactionAsync(cancellationToken);

            await _cronjobRegistrationService.Remove(cronjob);

            _db.Remove(cronjob);
            await _db.SaveChangesAsync(cancellationToken);

            await tx.CommitAsync(cancellationToken);

            return(NoContent());
        }
Пример #2
0
        public async Task <IActionResult> DeleteTemplate(Guid id, CancellationToken cancellationToken = default)
        {
            var template = await _dbContext.ConfigTemplates.FindAsync(new object[] { id }, cancellationToken : cancellationToken);

            _dbContext.Remove(template);
            await _dbContext.SaveChangesAsync(cancellationToken);

            return(NoContent());
        }
Пример #3
0
        public async Task <IActionResult> DeleteUser(Guid userId, CancellationToken cancellationToken)
        {
            var user = await _dbContext.Users
                       .FirstOrDefaultAsync(e => e.Id == userId, cancellationToken : cancellationToken);

            if (user == null)
            {
                return(NotFound(new ProblemDetails {
                    Detail = "No such user"
                }));
            }

            if (user.Id.ToString() == User.FindFirstValue(ClaimTypes.NameIdentifier))
            {
                return(BadRequest(new ProblemDetails {
                    Detail = "You cannot delete yourself"
                }));
            }

            _dbContext.Remove(user);
            await _dbContext.SaveChangesAsync(cancellationToken);

            return(NoContent());
        }