Batch update using PUT - wcf data services / odata - c#

I have a java odata service which uses PUT to update data. Client is in dotnet.
I have an object (order) which has an attribute "list object" (order details).
Is it possible to send Order object in one short with order details list using below command
Order orderObj = new Order
OrderDetail oDetailObj = new OrderDetail
context.AttachTo(Orders, orderObj);
Code to set properties of orderObj
for loop to add orders details
{
Code to set properties of oDetailObj
context.AddRelatedObject(orderObj, "OrderDetailsList", oDetailObj);
}
DataServiceResponse response = context.SaveChanges(SaveChangesOptions.ReplaceOnUpdate);
While running this code, only last order detail infomration is submitting to server. I have verified that using fidller
if you have any alternative please suggest.

Related

Magento Change Order Status from REST API

I am 'communicating' with a Magento web app(version 1.9.2.2) via the REST API in a C# ASP.NET MVC application.
The application essentially acts as a backend order flow dashboard for pizzas. I need to display the latest orders and allow the user to check the items off as they are processed (among other things).
I am able to retrieve orders, products, customers etc; but need to be able to update the order status. From my research it seems that this can be achieved by adding an order comment.
That said, my questions are as follows:
Is adding an order comment (thus updating the order status) only possible through the SOAP Service in Magento 1.9?
If the above is true, how can I update the order status of a particular order using another secure approach?
Docs on REST API: http://devdocs.magento.com/guides/m1x/api/rest/Resources/Orders/order_comments.html
To anyone that may be facing the same issue, I discovered that it is not possible to update the order status (AKA add a sales order comment) via the REST API. You have to use the SOAP API and version 2 makes it easiest.
Setup:
In magento, create a SOAP Role and User
Add the SOAP v2 API as a web reference to your Visual Studio project
Code:
public void UpdateOrderStatus(string orderIncrementId, string newStatus, string comment = "")
{
// Init service with uri
var service = new MagentoSoap.MagentoService();
// Login - username and password (soap api key) of the soap user
string sessionId = service.login(Username, Password);
// Update order status
service.salesOrderAddComment(sessionId, orderIncrementId, newStatus, comment, 1, true);
}
You can do this by using the addComment method, which also lets you specify the new order status as one of it's parameters.
$sku='100000003';
$orderStatus = 'Downloaded';
$comment = 'The order was successfully downloaded';
$sendEmailToCustomer = false;
$proxy->call($sessionId, 'sales_order.addComment', array($sku, $orderStatus, $comment, $sendEmailToCustomer));

Clarification on how to update (patch) objects using the Microsoft.Graph Client

The following code is the only way I found so far to update an object using the Microsoft Graph Client Library
Scenario:
Load an exisiting object (an organization)
Modify a value (add entry in securityComplianceNotificationPhones)
Send the update
Code
var client = new GraphServiceClient(...);
var org = client.Organization["orgid"].Request().GetAsync().Result;
var secPhones = new List<string>(org.SecurityComplianceNotificationPhones);
secPhones.Add("12345");
var patchOrg = new Organization();
patchOrg.SecurityComplianceNotificationPhones = secPhones;
var orgReq = new OrganizationRequest(
client.Organization[org.Id].Request().RequestUrl,
client, new Option[] {});
orgReq.UpdateAsync(patchOrg).Wait();
I needed to use the patchOrg instance because of two things:
The Graph API documentation states
"In the request body, supply the values for relevant fields that
should be updated. Existing properties that are not included in the
request body will maintain their previous values or be recalculated
based on changes to other property values. For best performance you
shouldn't include existing values that haven't changed."
If you actually do include existing values that haven't changed
(i.e. assginedLicenses) the request fails, if those existing values
are readonly.
My question is: Is/will there be a more straightforward way of updating existing objects like for example in the Azure ActiveDirectory GraphClient? Just for comparison, the same scenario in Azure Active Directory Graph
var client = new ActiveDirectoryClient(...);
var org = client.TenantDetails.GetByObjectId("orgid").ExecuteAsync().Result;
org.SecurityComplianceNotificationPhones.Add("12345");
org.UpdateAsync().Wait();
The Graph client library model is slightly different from the older SDK model the AAD client library you linked. The older model passed around objects that tried to be a bit smarter and reason about which properties were changed, only sending those. One of the main drawbacks of this model was that the library made many more service calls in the background and had a much heavier payload in each call since ExecuteAsync() would often need to retrieve every object in the request builder chain. The newer library does require the developer to do more explicit reasoning about what data is being passed but also gives greater control over network calls and payload. Each model has its tradeoffs.
To accomplish what you want, here's the approach I would recommend instead of creating a second org object altogether:
var client = new GraphServiceClient(...);
var orgRequest = client.Organization["orgid"].Request();
var org = orgRequest.Select("securityComplianceNotificationPhones").GetAsync().Result;
var secPhones = new List<string>(org.SecurityComplianceNotificationPhones);
secPhones.Add("12345");
org.SecurityComplianceNotificationPhones = secPhones;
orgRequest.UpdateAsync(org).Wait();

Dynamics CRM executing multiple requests c#

I want to update a field of an account and I have the guid of account.
Can I update the field (for instance, address of the account) without retrieve request using an update request?
Here my code
Entity account= _service.Retrieve("account", Guid.Parse(accountGuid), new ColumnSet(true));
account.Attributes["new_password"] = password;
_service.Update(account);
Is it possible to use ExecuteMultipleRequest in this scenario?
If you have the Id of the record, yes, it can be done without a Retrieve.
Just write
Entity accountToUpdate = new Entity("account");
accountToUpdate.Id = Guid.Parse(accountGuid);
accountToUpdate["new_password"] = password;
_service.Update(accountToUpdate);
ExecuteMultipleRequest is used to batch multiple request at once, in that case you need to create first an UpdateRequest and add to the collection first, you can google for examples.

How to get with paypal C# sdk, the transactionid of a directpayment method

Im using the c# sdk to do a direct payment to paypal.
Everything works great, however im not getting the transactionId because the sdk's "Payment" object does not have a transactionId nor does the http response.
the code is very simple.
Payment pymnt = new Payment();
pymnt.intent = "sale";
pymnt.payer = payr;
pymnt.transactions = transactions;
Payment createdPayment = pymnt.Create(apiContext);
Pymnt Create method, creates and Executes the payment and retrieves back the properties by converting them from json.
I am getting back payid.I checked documentation but couldnt find any on how to get transactionId via payid.
Another part of my application that is created with paypal standard gets the paypal transaction id via the "txn_id" query parameter in the IPN method and saved it in the database.
Thus we need save the transactionid in the database to be consistent.
Please help.
(A similar question was asked on GitHub.)
The transaction ID for a payment can be found via the related_resources property of each transaction associated with a payment.
For example, if you make a sale payment, the transaction ID can be retrieved via the following:
var payment = Payment.Get(apiContext, "PAY-89W644977H834061FKTDRCCY");
var transactionId = payment.transactions[0].related_resources[0].sale.id;

Magento: Getting the transaction ID via soap

i recently tried to connect to a magento webshop via magentos SOAPv2 adapter.
Sharpdevelop did generate some c# wrappers getting the WSDL.
I could login and query orders, but when it comes to payment methods I was wondering why there's no way to get the transaction ID.
Here's what I tried:
salesOrderEntity ent = ms.salesOrderInfo(mlogin,"<my_order_id>");
The salesOrderEntity class contains a salesOrderPaymentEntity which should contain an attribute last_trans_id, but it doesn't.
Does anyone have an idea where to get the transaction ID from payment information? I didn't even find a reference to last_trans_id in the proxy code generated by sharpdevelop.
Thanks in advance for any suggestions.
-chris-
After some time i took up this question again and found a solution in my case.
A salesOrderEntity contains a list of salesOrderStatusHistoryEntity objects.
And those contain a field named 'comment' where in my case the Transaction IDs can by found in a textual way like
Transaction ID:"800736757864..."
This helped me.
Chris the OP has answered the question, but just to add some extra value to this Q&A here's the code I've got working.
As some background, the reason I am using Transaction IDs at all is because they are used by Paypal. I'm writing a cron job that pulls the Paypal orders from the Paypal API for the previous 24 hours, then we pull all orders from Magento via SOAP for the previous 24 hours, get the transaction IDs and match them to the Paypal list. It's to make sure there are no Paypal orders which are not on Magento, occasionally we get an IPN failure which prevents Magento quotes being converted to orders and the customer gets billed by Paypal but no product is shipped to them as the order is never created. If there's a mismatch an email alert is sent to customer services.
$startDate = gmdate('Y-m-d H:i:s', strtotime('-1 day', time()));
$complex_params =array(
array('key'=>'created_at','value'=>array('key' =>'from','value' => $startDate))
);
$result = $client_v2->salesOrderList($session_id, array('complex_filter' => $complex_params));
// We've got all the orders, now we need to run through them and get the transaction id from the order info
// We create an array just to hold the transaction Ids
$ikoTransactionIds = array();
foreach ($result as $invoice) {
$invoiceInfo = $client_v2->salesOrderInfo($session_id, $invoice->increment_id);
$history = $invoiceInfo->status_history;
$comments = $history[0]->comment;
// Only the Paypal based records have transaction Ids in the comments, orders placed via credit card do not. In these cases $comments are null
if ($comments) {
// Check if the text 'Transaction ID:' exists at all
if ((strpos($comments, "Transaction ID:")) !== FALSE) {
list($before, $transactionId) = explode('Transaction ID: ', $comments);
// Remove the trailing period
$transactionId = rtrim($transactionId ,".");
// Remove the quotes
$transactionId = str_replace('"', '', $transactionId);
// We add the id to our array of ids for this Magento install
$ikoTransactionIds[] = $transactionId;
}
}
}

Categories