public static async Task <IActionResult> GetCart(
            [HttpTrigger(AuthorizationLevel.Function, "get", Route = "v1/carts/{cartId}/Items")] HttpRequest req,
            string cartId,
            ILogger log)
        {
            var cartRepo = new CartRepository(new CartServiceApi(StaticHttpClient.Instance));
            var cart     = await cartRepo.GetCartAsync(cartId);

            return(cart.result.IsSuccess
                ? new ObjectResult(cart.info)
                : ActionResultFactory.CreateError(cart.result, cart.info));
        }
        public static async Task <IActionResult> CreateCart(
            [HttpTrigger(AuthorizationLevel.Function, "post", Route = "v1/carts")] HttpRequest req,
            [CosmosDB(
                 databaseName: "smartretailboxmanagement",
                 collectionName: "Terminals",
                 ConnectionStringSetting = "CosmosDbConnectionString")] DocumentClient client,
            ILogger log)
        {
            var parameter = await HttpRequestUtility.GetRequestParameterAsync <CreateCartParameter>(req);

            var userRepo = new UserRepository(StaticHttpClient.Instance);
            var user     = await userRepo.AuthenticateUserAsync();

            if (!user.result.IsSuccess)
            {
                return(new UnauthorizedResult());
            }

            var terminalRepo = new TerminalRepository(client);
            var terminal     = await terminalRepo.FindByBoxIdAsync(parameter.BoxId);

            if (!terminal.result.IsSuccess)
            {
                return(ActionResultFactory.CreateError <CreateCartResponse>(terminal.result));
            }

            var cartRepo = new CartRepository(new CartServiceApi(StaticHttpClient.Instance));
            var cart     = await cartRepo.CreateCartAsync(terminal.info.CompanyCode, terminal.info.StoreCode, terminal.info.TerminalNo, user.info.UserId, user.info.UserName);

            if (!cart.result.IsSuccess)
            {
                return(ActionResultFactory.CreateError <CreateCartResponse>(cart.result));
            }

            var boxRepo   = new BoxRepository(client);
            var updResult = await boxRepo.SetCartIdAsync(parameter.BoxId, parameter.DeviceId, user.info.UserId, cart.info.CartId);

            if (!updResult.IsSuccess)
            {
                return(ActionResultFactory.CreateError <CreateCartResponse>(updResult));
            }

            await BoxUtility.RequestUnLockAsync(terminal.info.BoxId, terminal.info.BoxDeviceId);

            return(new CreatedResult(
                       string.Empty,
                       new CreateCartResponse
            {
                CartId = cart.info.CartId
            }));
        }