コード例 #1
0
        public static async Task <IActionResult> Run(
            [HttpTrigger(AuthorizationLevel.Anonymous, "get", Route = null)] HttpRequest req,
            ILogger log)
        {
            Dtos.Carrinho carrinho = null;

            var clientId = req.Query["clientId"].ToString();

            if (!string.IsNullOrEmpty(clientId))
            {
                carrinho = await Shared.BlobStorage.GetData(clientId);
            }
            else
            {
                return(new BadRequestObjectResult("Por favor informe o clientId."));
            }

            return(carrinho != null
                ? (ActionResult) new OkObjectResult(carrinho)
                : new NotFoundObjectResult("Carrinho não encontrado."));
        }
コード例 #2
0
        public static async Task <IActionResult> Run(
            [HttpTrigger(AuthorizationLevel.Function, "post", Route = null)] HttpRequest req,
            ILogger log)
        {
            try
            {
                string clientId = req.Query["clientId"];
                string itemId   = req.Query["itemId"];

                if (string.IsNullOrEmpty(clientId) || string.IsNullOrEmpty(itemId))
                {
                    return(new BadRequestObjectResult("Por favor infome o clientId e o itemId"));
                }

                var carrinho = await Shared.BlobStorage.GetData(clientId);

                if (carrinho == null)
                {
                    carrinho = new Dtos.Carrinho
                    {
                        ClientId = clientId,
                        Itens    = new List <string>()
                    }
                }
                ;

                carrinho.Itens.Add(itemId);
                await Shared.BlobStorage.StoreData(carrinho);

                return(new OkObjectResult(""));
            }
            catch (Exception e)
            {
                return(new StatusCodeResult(500));
            }
        }