예제 #1
0
        public async Task Confirm(ConfirmAdvertModel model)
        {
            using (AmazonDynamoDBClient client = new AmazonDynamoDBClient())
            {
                using (DynamoDBContext context = new DynamoDBContext(client))
                {
                    AdvertDbModel result = await context.LoadAsync <AdvertDbModel>(model.Id);

                    if (result == null)
                    {
                        throw new Exception($"key not found {model.Id}");
                    }
                    if (model.Status == AdvertStatus.Active)
                    {
                        result.FilePath = model.FilePath;
                        result.Status   = AdvertStatus.Active;

                        await context.SaveAsync(result);
                    }
                    else
                    {
                        await context.DeleteAsync(result);
                    }
                }
            }
        }
예제 #2
0
        public async Task <string> Add(AdvertModel model)
        {
            AdvertDbModel dbModel = _mapper.Map <AdvertDbModel>(model);

            dbModel.Id = Guid.NewGuid().ToString();
            dbModel.CreationDateTime = DateTime.UtcNow;
            dbModel.Status           = AdvertStatus.Pending;

            using (AmazonDynamoDBClient client = new AmazonDynamoDBClient())
            {
                DescribeTableResponse table = await client.DescribeTableAsync("Adverts");

                bool tableStatus = string.Compare(table.Table.TableStatus, "active", true) == 0;

                if (tableStatus)
                {
                    using (DynamoDBContext context = new DynamoDBContext(client))
                    {
                        await context.SaveAsync(dbModel);
                    }
                }
            }

            return(dbModel.Id);
        }
        public async Task ConfirmAsync(ConfirmAdvertModel model)
        {
            using (AmazonDynamoDBClient client = new AmazonDynamoDBClient())
            {
                using (DynamoDBContext context = new DynamoDBContext(client))
                {
                    AdvertDbModel record = await context.LoadAsync <AdvertDbModel>(model.Id);

                    if (record == null)
                    {
                        throw new KeyNotFoundException($"A record with ID={model.Id} was not found.");
                    }
                    if (model.Status == AdvertStatus.Active)
                    {
                        record.FilePath = model.FilePath;
                        record.Status   = AdvertStatus.Active;
                        await context.SaveAsync(record);
                    }
                    else
                    {
                        await context.DeleteAsync(record);
                    }
                }
            }
        }
예제 #4
0
        public async Task Confirm(ConfirmAdvertModel model)
        {
            AmazonDynamoDBConfig clientConfig = new AmazonDynamoDBConfig();

            // This client will access the US East 1 region.
            clientConfig.RegionEndpoint = RegionEndpoint.USEast2;
            //AmazonDynamoDBClient client = new AmazonDynamoDBClient(clientConfig);

            using (var client = new AmazonDynamoDBClient(clientConfig))
            {
                using (var context = new DynamoDBContext(client))
                {
                    AdvertDbModel record = await context.LoadAsync <AdvertDbModel>(model.Id);


                    if (record == null)
                    {
                        throw new KeyNotFoundException($"a RECORD WITH ID {model.Id} NOT EXISTS IN DB");
                    }

                    if (model.Status == AdvertStatus.Active)
                    {
                        record.Status = AdvertStatus.Active;
                        await context.SaveAsync(record);
                    }
                    else
                    {
                        await context.DeleteAsync(record);
                    }
                }
            }
        }
예제 #5
0
        public async Task <string> AddAsync(AdvertModel model)
        {
            // add validation in production
            AdvertDbModel dbModel = _mapper.Map <AdvertDbModel>(model);

            dbModel.Id = new Guid().ToString();
            dbModel.CreationDateTime = DateTime.UtcNow;
            dbModel.Status           = AdvertStatus.Pending;

            using (var context = new DynamoDBContext(_client))
            {
                await context.SaveAsync(dbModel);
            }

            return(dbModel.Id);
        }
예제 #6
0
        public async Task <AdvertModel> GetByIdAsync(string id)
        {
            using (AmazonDynamoDBClient client = GetDynamoDBClient())
            {
                using (var context = new DynamoDBContext(client))
                {
                    AdvertDbModel dbModel = await context.LoadAsync <AdvertDbModel>(id);

                    if (dbModel != null)
                    {
                        return(_mapper.Map <AdvertModel>(dbModel));
                    }
                }
            }

            throw new KeyNotFoundException();
        }
예제 #7
0
        public async Task <string> GetById(string id)
        {
            using (AmazonDynamoDBClient client = new AmazonDynamoDBClient())
            {
                using (DynamoDBContext context = new DynamoDBContext(client))
                {
                    AdvertDbModel dbModel = await context.LoadAsync <AdvertDbModel>(id);

                    if (dbModel == null)
                    {
                        throw new Exception($"key not found {id}");
                    }

                    return(dbModel.Title);
                }
            }

            throw new KeyNotFoundException();
        }
        public async Task <string> AddAsync(AdvertModel model)
        {
            AdvertDbModel dbModel = _mapper.Map <AdvertDbModel>(model);

            dbModel.Id = Guid.NewGuid().ToString();
            dbModel.CreationDateTime = DateTime.UtcNow;
            dbModel.Status           = AdvertStatus.Pending;

            using (AmazonDynamoDBClient client = new AmazonDynamoDBClient())
            {
                Amazon.DynamoDBv2.Model.DescribeTableResponse table = await client.DescribeTableAsync("Adverts");

                using (DynamoDBContext context = new DynamoDBContext(client))
                {
                    await context.SaveAsync(dbModel);
                }
            }
            return(dbModel.Id);
        }
예제 #9
0
 private static async Task UpdateAdvertAsActive(DynamoDBContext ctx, AdvertDbModel record)
 {
     record.Status = AdvertStatus.Active;
     await ctx.SaveAsync(record);
 }
예제 #10
0
 private static async Task DeleteAdvert(DynamoDBContext ctx, AdvertDbModel record)
 {
     await ctx.DeleteAsync(record);
 }