コード例 #1
0
        public async Task <IActionResult> UpdateProjectAsync(int projectId, [FromBody] UpdateProjectRequest request, [FromServices] IUpdateProjectCommand command, [FromServices] IGetProjectQuery query)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }
            string user    = User.Identity.Name;
            var    project = await query.RunAsync(projectId);

            try
            {
                var authorizationResult = await _authorizationService.AuthorizeAsync(User, project, Operations.Update);

                if (authorizationResult.Succeeded)
                {
                    ProjectResponse response = await command.ExecuteAsync(projectId, request, user);

                    return(response == null
                        ? (IActionResult)NotFound("Project Not Found")
                        : Ok(response));
                }
                return(StatusCode(403, "Вы не можете изменить этот проект!"));
            }
            catch (ProjectLockedException)
            {
                return(BadRequest("В данный момент изменение проекта невозможно!"));
            }
            catch (DbUpdateConcurrencyException)
            {
                return(BadRequest("Ошибка параллелизма!"));
            }
        }
コード例 #2
0
        public async Task <IActionResult> CreateTaskAsync([FromBody] CreateTaskRequest request, [FromServices] ICreateTaskCommand command, [FromServices] IGetProjectQuery query)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }
            try
            {
                var project = await query.RunAsync(request.ProjectId);

                if ((await _authorizationService.AuthorizeAsync(User, project, Operations.CreateTask)).Succeeded)
                {
                    TaskResponse response = await command.ExecuteAsync(request);

                    return(Created(Url.RouteUrl(new { response.Id }), response));
                }
                return(StatusCode(403, "Вы не можете создать задачу для этого проекта!"));
            }
            catch (ArgumentException ex)
            {
                return(BadRequest(ex.Message));
            }
        }