public async Task <GalleryDTO> CreateGalleryAsync(Guid userId, GalleryCreationDTO galleryCreationDTO)
        {
            GalleryEntity entity = galleryCreationDTO.ToGalleryEntity(userId);

            GalleryEntity addedEntity = await _galleryRepository.PostGallery(entity);

            if (_galleryRepository.Save() == false)
            {
                throw new Exception();
            }

            return(addedEntity.ToGalleryDto(0));
        }
        public async Task <ActionResult <GalleryDTO> > CreateGallery(GalleryCreationDTO creationDto)
        {
            Guid userId = new Guid(HttpContext.User.Identity.Name);

            try
            {
                GalleryDTO dto = await _galleryService.CreateGalleryAsync(userId, creationDto);

                return(CreatedAtAction(nameof(GetGallery), new { id = dto.Id }, dto));
            }
            catch (Exception ex)
            {
                var problemDetails = new ProblemDetails
                {
                    Title    = "An unexpected error occurred.",
                    Status   = StatusCodes.Status500InternalServerError,
                    Detail   = "Unable to create the gallery at this moment due to an error, the error has been logged and sent to the developers for fixing.",
                    Instance = HttpContext.TraceIdentifier,
                };
                return(StatusCode(StatusCodes.Status500InternalServerError, problemDetails));
            }
        }
        public async Task CreateGallery()
        {
            // Arrange
            var controller = new GalleryController(GalleryService.Object);

            controller.ControllerContext = APIControllerUtils.CreateApiControllerContext(UserEntities[1].Id.ToString());

            GalleryCreationDTO newGalleryItem = new GalleryCreationDTO("CreatedTestName");

            // Act
            ActionResult <GalleryDTO> response = await controller.CreateGallery(newGalleryItem);

            // Assert
            Assert.IsInstanceOfType(response.Result, typeof(CreatedAtActionResult));
            var result = response.Result as CreatedAtActionResult;

            Assert.AreEqual(201, result.StatusCode);
            Assert.IsNotNull(result.Value);
            Assert.IsInstanceOfType(result.Value, typeof(GalleryDTO));
            GalleryDTO createdItem = result.Value as GalleryDTO;

            Assert.AreEqual(createdItem.Name, "CreatedTestName");
        }