//[ODataRoute("Accounts({accountId})/PayinPIs({piId})/WebStack.QA.Test.OData.Containment.Duplicate")]
        public IHttpActionResult DuplicatePayinPI(int accountId, int piId)
        {
            var account = _dataSource.Accounts.Single(a => a.AccountID == accountId);
            var paymentInstrument = account.PayinPIs.Single(pi => pi.PaymentInstrumentID == piId);
            Statement newStatement = null;
            if (paymentInstrument.Statement != null)
            {
                newStatement = new Statement()
                {
                    StatementID = 1,
                    TransactionDescription = (string)paymentInstrument.Statement.TransactionDescription.Clone(),
                    Amount = paymentInstrument.Statement.Amount,
                };
            }
            var newPI = new PaymentInstrument()
            {
                PaymentInstrumentID = account.PayinPIs.Max(pi => pi.PaymentInstrumentID) + 1,
                FriendlyName = paymentInstrument.FriendlyName + " - Copy",
                Statement = newStatement,
            };
            account.PayinPIs.Add(newPI);

            return Ok(newPI);
        }
 public IHttpActionResult PutStatement(int key, int navKey, EdmEntityObject statementObject)
 {
     Statement newStatement = new Statement();
     var properties = typeof(Statement).GetProperties();
     foreach (PropertyInfo propertyInfo in properties)
     {
         object value;
         statementObject.TryGetPropertyValue(propertyInfo.Name, out value);
         propertyInfo.SetValue(newStatement, value);
     }
     return Ok(newStatement);
 }
Esempio n. 3
0
        // To test it is able to put a contained entity which is navigated from a containment navigation property
        // PUT ~/Accounts(1)/PayinPIs(1)/Statement
        public async Task PutStatement(string mode)
        {
            await ResetDatasource();
            string serviceRootUri = string.Format("{0}/{1}", BaseAddress, mode).ToLower();
            string requestUri = string.Format("{0}/{1}/Accounts(100)/PayinPIs(101)/Statement", BaseAddress, mode);
            string newDescription = "newDescription";
            Statement statement = new Statement()
            {
                StatementID = 1010,
                TransactionDescription = newDescription,
            };

            /* {"StatementID":1010,"TransactionDescription":"newDescription","Amount":0.0}*/
            var response = await Client.PutAsJsonAsync<Statement>(requestUri, statement);
            Assert.Equal(HttpStatusCode.OK, response.StatusCode);

            /*
            {
              "@odata.context":"http://*****:*****@odata.context"]);
            Assert.Equal(newDescription, (string)json["TransactionDescription"]);
            Assert.Equal(1010, (int)json["StatementID"]);
        }