public async Task AddAsync(DoorActionDto doorActionDto)
        {
            doorActionDto = doorActionDto ?? throw new ArgumentNullException(nameof(doorActionDto));

            var doorAction = _mapper.Map <DoorAction>(doorActionDto);
            await _applicationContext.DoorActions.AddAsync(doorAction);
        }
        public async Task <IActionResult> PostAsync([FromBody] PassageRequest request)
        {
            var currentCardDto = (await _cardManager
                                  .GetAllAsync(uniqueNumbers: new string[] { request.CardUniqueNumber }))
                                 .FirstOrDefault();

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

            var currentDoorReaderDto = (await _doorReaderManager
                                        .GetAllAsync(
                                            serialNumbers: new string[] { request.DoorReaderSerialNumber },
                                            includes: new string[] { nameof(DoorReader.Door) }))
                                       .FirstOrDefault();

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

            var doorActionStatus = DoorActionStatusType.Success;

            if (currentCardDto.Status == CardStatusType.Locked)
            {
                doorActionStatus = DoorActionStatusType.Error;
            }

            if (currentDoorReaderDto.Door.Status != DoorStatusType.Active)
            {
                doorActionStatus = DoorActionStatusType.Error;
            }

            if (currentCardDto.Level < currentDoorReaderDto.Door.Level)
            {
                doorActionStatus = DoorActionStatusType.Denied;
            }

            var doorActionDto = new DoorActionDto
            {
                CardId       = currentCardDto.Id,
                DoorReaderId = currentDoorReaderDto.Id,
                Status       = doorActionStatus,
                TimeStamp    = DateTime.Now,
            };

            await _doorActionManager.AddAsync(doorActionDto);

            await _commitManager.SaveAsync();

            return(doorActionStatus != DoorActionStatusType.Success
                ? BadRequest()
                : Ok());
        }
        public void AddAsync_DoorActionDtoWithoutId_DoorActionIsAdded()
        {
            // Arrange
            var doorActionDto = new DoorActionDto
            {
                Id           = 1,
                DoorReaderId = 1,
                CardId       = 1,
                Status       = DoorActionStatusType.Success,
                TimeStamp    = new DateTime(2000, 1, 1),
            };

            // Act
            _doorActionManager.AddAsync(doorActionDto)
            .GetAwaiter()
            .GetResult();

            _applicationContext.SaveChanges();

            // Assert
            Assert.Equal(1, _applicationContext.DoorActions.Count());
        }