示例#1
0
        public async Task <ActionResult> GetOfficeAsync(int officeId)
        {
            var office = await _officesRepository.GetAsync(officeId);

            if (office == null)
            {
                throw ApiException.NotFound("Office not found");
            }

            return(Ok(_mapper.Map <OfficeModel>(office)));
        }
示例#2
0
        public async Task <PlayerGet> Handle(PlayerGetRequest request, CancellationToken cancellationToken)
        {
            var player = await _repository.Get(request.Id);

            if (player == null)
            {
                throw ApiException.NotFound(request.Id);
            }
            player.Badges = await _badgesClient.Get(request.Id);

            return(player);
        }
示例#3
0
        public async Task <ActionResult> DeleteOfficeAsync(int officeId)
        {
            var office = await _officesRepository.GetAsync(officeId);

            if (office == null)
            {
                throw ApiException.NotFound("Office not found");
            }

            await _officesRepository.DeleteAsync(office);

            return(Ok());
        }
示例#4
0
        private async Task <Door> GetAndEnsureDoorAsync(int officeId, int doorId)
        {
            var door = await _doorsRepository.GetAsync(doorId);

            if (door == null)
            {
                throw ApiException.NotFound("Door not found");
            }

            if (door.OfficeId != officeId)
            {
                throw ApiException.NotFound("Door not found");
            }

            return(door);
        }
示例#5
0
        public async Task <ActionResult> CreateDoorAsync(int officeId, [FromBody] CreateDoorRequest request)
        {
            if (request == null)
            {
                return(BadRequest());
            }

            var office = await _officesRepository.GetAsync(officeId);

            if (office == null)
            {
                throw ApiException.NotFound("Office not found");
            }

            var door = _mapper.Map <Door>(request);

            var doorId = await _officesRepository.AddDoorAsync(office, door);

            return(Ok(new CreateDoorResponse
            {
                DoorId = doorId
            }));
        }