public ImageResponse ImageRevision(ImageRevisionDto model)
        {
            try
            {
                if (!SecurityHandler.IsValidPassword(model?.password))
                {
                    throw new UnauthorizedAccessException();
                }

                var filename = ContentDispositionHeaderValue
                               .Parse(model.file.ContentDisposition)
                               .FileName
                               .ToString()
                               .Trim('"');

                var fileStream = model.file.OpenReadStream();

                var cmd = new UploadImageRevisionCommand(model, fileStream, filename);

                UploadImageRevisionCommandHandler.HandleAsync(cmd);

                return(GetImageById(model?.imageId));
            }

            catch (Exception ex)
            {
                throw ex;
            }
        }
        public UploadImageRevisionCommand(ImageRevisionDto model, Stream file, string filename)
        {
            if (file?.Length > 0)
            {
                var datenow = DateTime.Now;

                File = new MemoryStream();

                file.CopyTo(File);
                File.Position = 0;
                file.Dispose();

                ImageId = model.imageId;

                Revision = new Revision
                {
                    Description  = model.description,
                    RevisionDate = new DateTime(datenow.Year, datenow.Month, datenow.Day, datenow.Hour, datenow.Minute, datenow.Second),
                    Thumb        = new Thumbnail
                    {
                        Filename = $"thumb_{filename}"
                    },
                    Filename = filename
                };
            }
        }
        public void PassingRevisionDtoAndFileInfoGetsCorrectlyConverted()
        {
            var dto = new ImageRevisionDto();

            dto.description = "desc";
            dto.imageId     = "imageId";

            var stream   = new MemoryStream(Encoding.UTF8.GetBytes("asdf"));
            var filename = "testname";

            var cmd = new UploadImageRevisionCommand(dto, stream, filename);

            Assert.NotNull(cmd.File);
            Assert.That(cmd.Revision.Filename, Is.EqualTo(filename));
            Assert.That(cmd.Revision.Description, Is.EqualTo(dto.description));
            Assert.That(cmd.ImageId, Is.EqualTo(dto.imageId));
            Assert.That(cmd.Revision.Filename, Is.EqualTo(filename));
            Assert.That(cmd.Revision.RevisionDate, Is.Not.Null);
            Assert.That(cmd.Revision.Thumb.Filename, Is.EqualTo($"thumb_{filename}"));
        }