public async Task <string> Add(AdvertModels advertModels)
        {
            var dbmodel = _mapper.Map <AdvertDbModel>(advertModels);

            dbmodel.Id = Guid.NewGuid().ToString();
            dbmodel.MyCreationDateTime = DateTime.UtcNow;
            dbmodel.status             = AdvertStatus.pending;

            using (var client = new AmazonDynamoDBClient())
            {
                using (var context = new DynamoDBContext(client))
                {
                    await context.SaveAsync(dbmodel);
                }
            }
            return(dbmodel.Id);
        }
Example #2
0
        public async Task <IActionResult> Create(AdvertModels model)
        {
            try
            {
                var recordId = await _advertStorageService.Add(model);

                return(StatusCode(201, new CreateAdvertResponse {
                    Id = recordId
                }));
            }
            catch (KeyNotFoundException)
            {
                return(NotFound());
            }
            catch (Exception ex)
            {
                return(StatusCode(500, ex.Message));
            }
        }
        public async Task <IActionResult> Create(AdvertModels models)
        {
            string recordId;

            try
            {
                recordId = await _advertStorageService.Add(models);
            }
            catch (KeyNotFoundException)
            {
                return(new NotFoundResult());
            }
            catch (Exception e)
            {
                return(StatusCode(500, e.Message));
            }
            return(StatusCode(201, new CreateAdvertResponse {
                Id = recordId
            }));
        }