Пример #1
0
        /// <summary>
        /// A Lambda function that adds a product post.
        /// </summary>
        /// <param name="request"></param>
        /// <returns></returns>
        public async Task <APIGatewayProxyResponse> AddProductAsync(APIGatewayProxyRequest request, ILambdaContext context)
        {
            var product = JsonConvert.DeserializeObject <Product>(request?.Body);

            product.Id = Guid.NewGuid().ToString();
            product.CreatedTimestamp = DateTime.Now;

            context.Logger.LogLine($"Saving product with id {product.Id}");
            await DDBContext.SaveAsync <Product>(product);

            context.Logger.LogLine($"Conditions - {!string.IsNullOrEmpty(product.Id)} && {!string.IsNullOrWhiteSpace(product.Id)}");
            if (!string.IsNullOrEmpty(product.Id) && !string.IsNullOrWhiteSpace(product.Id))
            {
                context.Logger.LogLine($"Product Category - {product.Category}");
                // await FirebaseCloudMessagingHelper.SendPushNotification("dfrrFgYOHiU:APA91bGYyzADHof0ZLQg-on8l3JHIPYerYQtF8SS2VdUusVSh2bO3NntOZKy_W4_BUQ5_JB5kD7NZIZo915vEcdYwZEBKbwPg1n1gdR5pEV0kkiCIvhhD5i5alPY5Tv4VM8sPuNXmcJr", product.Name, "Just added and available for bidding.", product.ImageUrl, null);
                await FirebaseCloudMessagingHelper.SendPushNotification("/topics/" + product.Category, product.Name, "Just added and available for bidding.", product.ImageUrl, product);
            }

            var response = new APIGatewayProxyResponse
            {
                StatusCode = (int)HttpStatusCode.OK,
                Body       = JsonConvert.SerializeObject(product),
                Headers    = HeaderHelper.GetHeaderAttributes()
            };

            return(response);
        }
Пример #2
0
        /// <summary>
        /// A Lambda function that update a product post.
        /// </summary>
        /// <param name="request"></param>
        /// <returns></returns>
        public async Task <APIGatewayProxyResponse> UpdateProductAsync(APIGatewayProxyRequest request, ILambdaContext context)
        {
            var product = JsonConvert.DeserializeObject <Product>(request?.Body);

            string productId = null;

            if (request.PathParameters != null && request.PathParameters.ContainsKey(ID_QUERY_STRING_NAME))
            {
                productId = request.PathParameters[ID_QUERY_STRING_NAME];
            }
            else if (request.QueryStringParameters != null && request.QueryStringParameters.ContainsKey(ID_QUERY_STRING_NAME))
            {
                productId = request.QueryStringParameters[ID_QUERY_STRING_NAME];
            }

            if (string.IsNullOrEmpty(productId))
            {
                return(new APIGatewayProxyResponse
                {
                    StatusCode = (int)HttpStatusCode.BadRequest,
                    Body = $"Missing required parameter {ID_QUERY_STRING_NAME}"
                });
            }
            else
            {
                product.Id = productId;
            }

            context.Logger.LogLine($"Saving product with id {product.Id}");
            await DDBContext.SaveAsync <Product>(product);

            if (!string.IsNullOrEmpty(product.Id) && !string.IsNullOrWhiteSpace(product.Id))
            {
                // await FirebaseCloudMessagingHelper.SendPushNotification("dfrrFgYOHiU:APA91bGYyzADHof0ZLQg-on8l3JHIPYerYQtF8SS2VdUusVSh2bO3NntOZKy_W4_BUQ5_JB5kD7NZIZo915vEcdYwZEBKbwPg1n1gdR5pEV0kkiCIvhhD5i5alPY5Tv4VM8sPuNXmcJr", product.Name, "Just added and available for bidding.", product.ImageUrl, null);
                await FirebaseCloudMessagingHelper.SendPushNotification("/topic/" + product.Category, product.Name, "Just updated and available for bidding.", product.ImageUrl, null);
            }

            var response = new APIGatewayProxyResponse
            {
                StatusCode = (int)HttpStatusCode.OK,
                Body       = JsonConvert.SerializeObject(product),
                Headers    = HeaderHelper.GetHeaderAttributes()
            };

            return(response);
        }