Exemplo n.º 1
0
        public async Task <CreateImageResult> CreateImageAsync(CreateImageCommand command)
        {
            if (String.IsNullOrWhiteSpace(command.Name))
            {
                return(new CreateImageResult(new Error("Empty name", "Name can't be empty")));
            }

            var image = new ImageEntity()
            {
                Description = command.Description,
                Name        = command.Name,
                Data        = command.Data,
                ContentType = command.ContentType,
                FileName    = command.FileName
            };

            var result = await ImageStore.CreateImageAsync(image, CancellationToken);

            if (result.Succeeded)
            {
                return(new CreateImageResult(image.ImageId));
            }
            else
            {
                return(new CreateImageResult(result.Errors));
            }
        }
Exemplo n.º 2
0
        public void Post([FromBody] CreateImageCommand request)
        {
            var repository = new ImagesRepository();

            var tagRepository = new TagsRepository();

            var tags = new List <ImorTag>();

            foreach (var tag in request.Tags)
            {
                var existingTag = tagRepository.GetTagByUri(tag);

                if (existingTag != null)
                {
                    tags.Add(existingTag);
                }
            }

            repository.InsertImage(new ImorImage
            {
                Uri         = request.Uri,
                Description = request.Description,
                Content     = request.Content,
                Tags        = tags
            });
        }
Exemplo n.º 3
0
        public async Task CreateImage(CreateImageCommand command)
        {
            var response = await _client.ExecuteAsync(new CreateImageRequest
            {
                FromImage = command.FromImage
            });

            await response.GetContentOrThrow <EmptyResponse>();
        }
Exemplo n.º 4
0
        public IActionResult Create(ImageCreate model)
        {
            CreateImageCommand command = new CreateImageCommand();

            if (!ModelState.IsValid)
            {
                return(View(model));
            }
            try
            {
                if (model.ImageFile == null || model.ImageFile.Length == 0)
                {
                    throw new ArgumentException("Image not found");
                }
                if (model.ImageFile.Length > 0)
                {
                    using (var ms = new MemoryStream())
                    {
                        model.ImageFile.CopyTo(ms);
                        command.image = new AlbumImage {
                            Image = ms.ToArray(), ImageAlt = model.ImageAlt, ImageName = model.ImageName, ImageUrl = model.ImageUrl
                        };
                        command.image.ImageTags = new List <AlbumImageTag>();
                    }
                }

                if (model.TagIDs != null && model.TagIDs.Length > 0 && model.TagNames != null && model.TagNames.Length > 0)
                {
                    if (model.TagNames.Length == model.TagIDs.Length)
                    {
                        command.image.ImageTags = new List <AlbumImageTag>();
                        for (int i = 0; i < model.TagIDs.Length; i++)
                        {
                            command.image.ImageTags.Add(new AlbumImageTag {
                                ImageTagId = model.TagIDs[i], Name = model.TagNames[i]
                            });
                        }
                    }
                    else
                    {
                        throw new ArgumentException("Tag Name and Tag Ids don't have the same amount");
                    }
                }

                this.service.Create(command);
                if (command.Response != CreateImageCommand.SUCCESS)
                {
                    throw new ArgumentException(CreateImageCommand.ERROR, "Business Logic Error");
                }
            }
            catch (Exception ex)
            {
                throw ex;
            }
            return(RedirectToAction("Edit", new { id = command.image.ImageId, message = "Image Saved!" }));
        }
Exemplo n.º 5
0
 public void Create(CreateImageCommand command)
 {
     try
     {
         command.image.ImageId = repository.Insert(Convert(command.image));
     }
     catch (Exception ex)
     {
         command.Response = String.Format(EventMessage.ERROR, ex.Message);
         return;
     }
     command.Response = EventMessage.SUCCESS;
 }
        public void Create_ReturnsSuccessAndId_WhenPassedParameters()
        {
            Mock <ImageRepository> mockImageRepository = new Mock <ImageRepository>();
            CreateImageCommand     command             = new CreateImageCommand();

            command.image           = new AlbumImage();
            command.image.ImageAlt  = "1";
            command.image.ImageName = "1";
            command.image.ImageUrl  = "1";
            Image mockImage = createMockImage(1);

            mockImageRepository.Setup(x => x.Insert(It.IsAny <Image>())).Returns(mockImage.ImageId);

            ImageService imageService = new ImageService(mockImageRepository.Object);

            imageService.Create(command);
            Assert.That(command.Response, Is.EqualTo(EventMessage.SUCCESS));
            Assert.That(command.image.ImageId, Is.EqualTo(mockImage.ImageId));
        }
        public void Post([FromBody] CreateImageCommand request)
        {
            var repository = new ImagesRepository();

            var tagRepository = new TagsRepository();

            var tags = new List <ImorTag>();

            foreach (var tagLabel in request.Tags)
            {
                var existingTag = tagRepository.GetTagByUri(tagLabel);

                if (existingTag != null)
                {
                    tags.Add(existingTag);
                }
                else
                {
                    var tag = new ImorTag()
                    {
                        Uri         = ImorEnum.GetUri(tagLabel),
                        Label       = tagLabel,
                        Description = "This is a label for " + tagLabel
                    };

                    tagRepository.InsertImorTag(tag);

                    tags.Add(tag);
                }
            }

            repository.InsertImage(new ImorImage
            {
                Uri         = request.Uri,
                Description = request.Description,
                Content     = request.Content,
                Tags        = tags
            });
        }
Exemplo n.º 8
0
 public async Task CreateImage(CreateImageCommand command)
 {
     await Mediator.Send(command);
 }
Exemplo n.º 9
0
 public async Task <IActionResult> CreateImage([FromBody] CreateImageCommand image)
 {
     return(Ok(await Mediator.Send(image)));
 }
Exemplo n.º 10
0
        public async Task <ActionResult <int> > Create(CreateImageCommand command)
        {
            command.UserId = _currentUserService.UserId;

            return(await Mediator.Send(command));
        }