Example #1
0
        public async Task NotifySubscribersAboutNewForroLevel(ForroLevel forroLevel)
        {
            var clientSNS = new AmazonSimpleNotificationServiceClient(_awsRegionEndpoint);

            var message = $"The name of new Forró Level is {forroLevel.Name} and ID {forroLevel.ForroLevelId}";

            var publish = new PublishRequest
            {
                TopicArn = _forroLevelSNSTopicArn,
                Subject  = "New Forró Level has been created",
                Message  = message
            };

            _loggerManager.LogInfo($"SNS Topic ARN is {_forroLevelSNSTopicArn}");

            var result = await clientSNS.PublishAsync(publish);

            if (IsSuccessStatusCode(result.HttpStatusCode))
            {
                _loggerManager.LogInfo($"Successfully sent a message to SNS Topic {_forroLevelSNSTopicArn}");
            }
            else
            {
                throw new Exception($"Error trying to publish on SNS topic " +
                                    $"{_forroLevelSNSTopicArn}. HttpStatus returned is {result.HttpStatusCode}");
            }
        }
Example #2
0
        public async Task SendMessageToForroLevelSQS(ForroLevel forroLevel)
        {
            var request = new GetQueueUrlRequest(_forroLevelQueueName);

            var response = await _amazonSQSClient.GetQueueUrlAsync(request);

            var newForroLevelJson = JsonConvert.SerializeObject(forroLevel);

            var sendMessageRequest = new SendMessageRequest(response.QueueUrl, newForroLevelJson);
            var result             = await _amazonSQSClient.SendMessageAsync(sendMessageRequest);
        }
Example #3
0
        public async Task <ForroLevel> Update(ForroLevel forroLevel)
        {
            //The PutItem operation also can perform an update. For more information, see Putting an Item.
            ///For example, if you call PutItem to upload an item and the primary key exists,
            ///the PutItem operation replaces the entire item. Note that,
            ///if there are attributes in the existing item and those attributes are not specified in the input,
            ///the PutItem operation deletes those attributes. However, UpdateItem only updates the specified input attributes,
            ///any other existing attributes of that item remain unchanged.

            await Insert(forroLevel);

            return(forroLevel);
        }
Example #4
0
        public async Task <ForroLevel> Insert(ForroLevel forroLevel, Stream fileLogoStream)
        {
            var imageUrl = await UploadFileToS3(fileLogoStream, forroLevel.ForroLevelId,
                                                forroLevel.Name, forroLevel.ImageUrl, UrlOrThumbNail.URL);

            //Update using actual S3 ObjectKey
            forroLevel.ImageUrl = imageUrl;
            var newForroLevel = await _repository.Insert(forroLevel);

            //Send a message to SQS notifying about the new Forró level
            await _forroLevelMessage.SendMessageToForroLevelSQS(newForroLevel);

            return(newForroLevel);
        }
Example #5
0
        public async Task <ForroLevel> Update(ForroLevel forroLevel, Stream fileLogoStream, Stream fileThumbNailStream)
        {
            var imageUrl = await UploadFileToS3(fileLogoStream, forroLevel.ForroLevelId,
                                                forroLevel.Name, forroLevel.ImageUrl, UrlOrThumbNail.URL);

            var thumbNailImageUrl = await UploadFileToS3(fileThumbNailStream, forroLevel.ForroLevelId,
                                                         forroLevel.Name, forroLevel.ThumbNailImageUrl, UrlOrThumbNail.ThumbNail);

            //Update using actual S3 ObjectKey
            forroLevel.ImageUrl          = imageUrl;
            forroLevel.ThumbNailImageUrl = thumbNailImageUrl;

            var newForroLevel = await _repository.Update(forroLevel);

            return(newForroLevel);
        }
Example #6
0
        private ForroLevel MapForroLevel(Dictionary <string, AttributeValue> result)
        {
            var forroLevel = new ForroLevel
            {
                ForroLevelId = Convert.ToInt32(result["ForroLevelId"].N),
                Name         = result["Name"].S
            };

            if (result.ContainsKey("ImageUrl"))
            {
                forroLevel.ImageUrl = result["ImageUrl"].S;
            }

            if (result.ContainsKey("ThumbNailImageUrl"))
            {
                forroLevel.ThumbNailImageUrl = result["ThumbNailImageUrl"].S;
            }

            return(forroLevel);
        }
Example #7
0
        public async Task <ForroLevel> Insert(ForroLevel forroLevel)
        {
            var attributes = new Dictionary <string, AttributeValue>
            {
                [nameof(ForroLevel.ForroLevelId)] = new AttributeValue()
                {
                    N = forroLevel.ForroLevelId.ToString()
                },
                [nameof(ForroLevel.Name)] = new AttributeValue()
                {
                    S = forroLevel.Name
                }
            };

            if (!string.IsNullOrWhiteSpace(forroLevel.ImageUrl))
            {
                attributes.Add(nameof(ForroLevel.ImageUrl), new AttributeValue()
                {
                    S = forroLevel.ImageUrl
                });
            }

            if (!string.IsNullOrWhiteSpace(forroLevel.ThumbNailImageUrl))
            {
                attributes.Add(nameof(ForroLevel.ThumbNailImageUrl), new AttributeValue()
                {
                    S = forroLevel.ThumbNailImageUrl
                });
            }

            var request = new PutItemRequest()
            {
                TableName = ForroLevelTableName,
                Item      = attributes
            };
            var result = await _client.PutItemAsync(request);

            return(forroLevel);
        }
Example #8
0
        public async Task <ForroLevel> Insert(ForroLevel forroLevel)
        {
            var result = await Insert(forroLevel, null);

            return(result);
        }