Exemplo n.º 1
0
        public async Task <IActionResult> DeleteProjectAsync(int projectId, [FromServices] IDeleteProjectCommand command)
        {
            try
            {
                await command.ExecuteAsync(projectId);

                return(Ok("Успешно"));
            }
            catch (Exception ex)
            {
                return(BadRequest(ex.Message));
            }
        }
Exemplo n.º 2
0
        public async Task <IActionResult> DeleteProjectAsync(int projectId, [FromBody] DeleteProjectRequest request, [FromServices] IDeleteProjectCommand command)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            var response = await command.ExecuteAsync(projectId, request);

            if (!response)
            {
                return(NotFound());
            }

            return(Ok());
        }
Exemplo n.º 3
0
        public async Task <IActionResult> DeleteProjectAsync(int projectId, [FromServices] IDeleteProjectCommand command)
        {
            try
            {
                if ((await _authorizationService.AuthorizeAsync(User, new Project(), Operations.Delete)).Succeeded)
                {
                    string user = User.Identity.Name;
                    await command.ExecuteAsync(projectId, user);

                    return(NoContent());
                }

                return(StatusCode(403, "Вы не можете удалить этот проект!"));
            }
            catch (CannotDeleteProjectWithTasksException ex)
            {
                return(BadRequest(ex.Message));
            }
            catch (ProjectLockedException)
            {
                return(BadRequest("В данный момент удаление проекта невозможно!"));
            }
        }