public object Patch(string id, [FromBody] PatchModel model)
        {
            Transaction activeTransaction = Store.Transaction;

            if (activeTransaction == null || id != activeTransaction.Id)
            {
                return(NotFound());
            }
            //Patch without specifying any changes is going to return the same as Get
            if (model == null || model.state == null)
            {
                return(TransactionHelper.ToJsonObject(activeTransaction));
            }
            switch (model.state)
            {
            case TransactionState.Committed:
                Store.CommitTransaction();
                activeTransaction.State = TransactionState.Committed;
                break;

            case TransactionState.Aborted:     //Same logic as committed but doesn't commit the server manager
                Store.AbortTransaction();
                activeTransaction.State = TransactionState.Aborted;
                break;

            default:
                break;
            }
            return(TransactionHelper.ToJsonObject(activeTransaction));
        }
        public object Get(string id)
        {
            Transaction activeTransaction = Store.Transaction;

            if (activeTransaction == null || id != activeTransaction.Id)
            {
                return(NotFound());
            }

            return(TransactionHelper.ToJsonObject(activeTransaction));
        }
        public object Get()
        {
            var transaction = Store.Transaction;
            List <Transaction> transactions = new List <Transaction>();

            if (transaction != null)
            {
                transactions.Add(transaction);
            }
            return(new {
                transactions = transactions.Select(trans => TransactionHelper.ToJsonObject(trans))
            });
        }
        public object Post()
        {
            Transaction transaction = Store.BeginTransaction();

            //
            // Set the current management unit
            Context.SetManagementUnit(Store.ManagementUnit);

            //
            // Create response
            dynamic tran = (dynamic)TransactionHelper.ToJsonObject(transaction);

            return(Created((string)TransactionHelper.GetLocation(tran.id), tran));
        }
예제 #5
0
        private void ConfigureTransactions()
        {
            var router = Environment.Host.RouteBuilder;
            var hal    = Environment.Hal;

            router.MapWebApiRoute(Defines.TransactionsResource.Guid, $"{Defines.TRANSACTIONS_PATH}/{{id?}}", new { controller = "transactions" }, skipEdge: true);
            hal.ProvideLink(Defines.TransactionsResource.Guid, "self", trans => new { href = TransactionHelper.GetLocation(trans.id) });

            hal.ProvideLink(Defines.Resource.Guid, Defines.TransactionsResource.Name, _ => new { href = $"/{Defines.TRANSACTIONS_PATH}" });
        }