public async Task <ActionResult <CharacterRemoveJobResponse> > PostCharacterRemoveJobAsync(
            [FromServices] NaheulbookExecutionContext executionContext,
            [FromRoute] int characterId,
            CharacterRemoveJobRequest request
            )
        {
            try
            {
                await _characterService.RemoveJobAsync(executionContext, characterId, request);

                return(new CharacterRemoveJobResponse {
                    JobId = request.JobId
                });
            }
            catch (CharacterAlreadyKnowThisJobException ex)
            {
                throw new HttpErrorException(StatusCodes.Status409Conflict, ex);
            }
            catch (JobNotFoundException ex)
            {
                throw new HttpErrorException(StatusCodes.Status400BadRequest, ex);
            }
            catch (ForbiddenAccessException ex)
            {
                throw new HttpErrorException(StatusCodes.Status403Forbidden, ex);
            }
            catch (CharacterNotFoundException ex)
            {
                throw new HttpErrorException(StatusCodes.Status404NotFound, ex);
            }
        }
Exemplo n.º 2
0
        public async Task RemoveJobAsync(NaheulbookExecutionContext executionContext, int characterId, CharacterRemoveJobRequest request)
        {
            using (var uow = _unitOfWorkFactory.CreateUnitOfWork())
            {
                var character = await uow.Characters.GetWithOriginWithJobsAsync(characterId);

                if (character == null)
                {
                    throw new CharacterNotFoundException(characterId);
                }

                _authorizationUtil.EnsureCharacterAccess(executionContext, character);

                var characterJob = character.Jobs.FirstOrDefault(x => x.JobId == request.JobId);
                if (characterJob == null)
                {
                    throw new CharacterDoNotKnowJobException(characterId, request.JobId);
                }

                character.Jobs.Remove(characterJob);

                var notificationSession = _notificationSessionFactory.CreateSession();
                notificationSession.NotifyCharacterRemoveJob(character.Id, request.JobId);

                await uow.SaveChangesAsync();

                await notificationSession.CommitAsync();
            }
        }