public async Task Handle_ShouldPersistQRCode()
        {
            // Arrange
            var qrcode = new QRCodeDTO
            {
                Code     = "Code_test",
                Created  = new DateTime(2004, 01, 01),
                AnimalId = 3
            };

            var command = new CreateQRCodeCommand
            {
                Model = qrcode
            };

            // Act
            var handler = new CreateQRCodeCommand.CreateQRCodeCommandHandler(Context, Mapper);

            var result = await handler.Handle(command, CancellationToken.None);

            var entity = Context.QRCodes.Find(result.Id);

            // Assert
            entity.ShouldNotBeNull();

            entity.Code.ShouldBe(command.Model.Code);
            entity.Created.ShouldBe(command.Model.Created);
            entity.AnimalId.ShouldBe(command.Model.AnimalId);
        }
        public async Task <IActionResult> Create(AnimalViewModel model)
        {
            model = model ?? throw new ArgumentNullException(nameof(model));

            if (ModelState.IsValid)
            {
                var userId = await _identityService.GetUserIdByNameAsync(User.Identity.Name);

                model.UserId = userId;

                // Создание команды для добавления нового животного
                var animalDTO = new AnimalDTO
                {
                    UserId    = userId,
                    Kind      = model.Kind,
                    Breed     = model.Breed,
                    Gender    = model.Gender.ToLocalType(),
                    Passport  = model.Passport,
                    BirthDate = model.BirthDate,
                    Nickname  = model.Nickname,
                    Features  = model.Features,
                    IsPublic  = model.IsPublic
                };

                var animalCommand = new CreateAnimalCommand
                {
                    Model = animalDTO
                };

                int id;

                try
                {
                    id = await _mediator.Send(animalCommand);
                }
                catch (RequestValidationException failures)
                {
                    foreach (var error in failures.Failures)
                    {
                        ModelState.AddModelError(string.Empty, error.Value[0]);
                    }

                    return(View(model));
                }

                // Создание команды для добавления QR кода для животного
                var qrCodeDTO = new QRCodeDTO
                {
                    Code     = _options.Value.QRGeneratorCode + id,
                    Created  = DateTime.Now,
                    AnimalId = id
                };

                var qrCommand = new CreateQRCodeCommand
                {
                    Model = qrCodeDTO
                };

                await _mediator.Send(qrCommand);

                _logger.LogInformation($"{User.Identity.Name} successfully created animal with id: {id}.");

                return(RedirectToAction("Index", "Profile"));
            }

            return(View(model));
        }