Пример #1
0
        public async Task <APIGatewayProxyResponse> FunctionHandler(APIGatewayProxyRequest input, ILambdaContext context)
        {
            LogMessage(context, "Starting Execution");

            try
            {
                AmazonDynamoDBConfig clientConfig = new AmazonDynamoDBConfig();
                clientConfig.RegionEndpoint = RegionEndpoint.USEast1;
                AmazonDynamoDBClient client = new AmazonDynamoDBClient(clientConfig);

                var repo     = new Movimientosrepository(client);
                var mapper   = new Mapper();
                var _service = new MovimientosService(repo, mapper);

                var results = await _service.GetAllItems();

                var response = CreateResponse(results);
                LogMessage(context, "Execution Completed");

                return(response);
            }
            catch (Exception e)
            {
                LogMessage(context, "Error: " + e.ToString());

                return(CreateResponse(null));
            }
        }
Пример #2
0
        public async Task <Response> FunctionHandler(MovimientosRequest input, ILambdaContext context)
        {
            LogMessage(context, "Starting Execution");
            LogMessage(context, JsonConvert.SerializeObject(input));

            try
            {
                AmazonDynamoDBConfig clientConfig = new AmazonDynamoDBConfig();
                clientConfig.RegionEndpoint = RegionEndpoint.USEast1;
                AmazonDynamoDBClient client = new AmazonDynamoDBClient(clientConfig);

                var repo       = new Movimientosrepository(client);
                var mapper     = new Mapper();
                var _service   = new MovimientosService(repo, mapper);
                var totalItems = await _service.GetAllItems();

                var movimientoID = 1;

                if (totalItems.ToList().Count > 0)
                {
                    movimientoID       = totalItems.Max(m => m.MovimientoID) + 1;
                    input.MovimientoID = movimientoID;
                }



                await _service.AddMovimiento(input);

                var response = CreateResponse(error: false, $"Movimiento {movimientoID} creado correctamente");
                LogMessage(context, "Execution Completed");

                return(response);
            }
            catch (Exception e)
            {
                LogMessage(context, "Error: " + e.ToString());

                return(CreateResponse(error: true, message: e.Message));
            }
        }