Example #1
0
        private async Task RaiseAdvertConfirmedMessage(ConfirmAdvertisement model)
        {
            var topicArn = _configuration.GetValue <string>("TopicArn");
            var dbModel  = await _advertisementStorageService.GetByIdAsync(model.Id);

            using var client = new AmazonSimpleNotificationServiceClient();
            var message = new AdvertisementConfirmedMessage
            {
                Id    = model.Id,
                Title = dbModel.Title
            };

            var messageJson = JsonConvert.SerializeObject(message);
            await client.PublishAsync(topicArn, messageJson);
        }
Example #2
0
        public async Task <IActionResult> Confirm([FromBody] ConfirmAdvertisement model)
        {
            try
            {
                await _advertisementStorageService.Confirm(model);
                await RaiseAdvertConfirmedMessage(model);
            }
            catch (KeyNotFoundException)
            {
                return(new NotFoundResult());
            }
            catch (Exception)
            {
                return(StatusCode(500));
            }

            return(new OkResult());
        }
        public async Task Confirm(ConfirmAdvertisement confirm)
        {
            using var context = new DynamoDBContext(_client);
            var dbModel = await context.LoadAsync <AdvertisementDb>(confirm.Id);

            if (dbModel is null)
            {
                throw new KeyNotFoundException($"A record with ID={confirm.Id} has not been found");
            }
            if (confirm.Status == AdvertisementStatus.Active)
            {
                dbModel.FilePath = confirm.FilePath;
                dbModel.Status   = AdvertisementStatus.Active;
                await context.SaveAsync(dbModel);
            }
            else
            {
                await context.DeleteAsync(dbModel);
            }
        }