sana khan
asked on
multiple update data using put method web api
How to multiple update data using put method web api. I have used single update but i am unable to write code for multiple update.
using json for updating data through postman application
public HttpResponseMessage Put(DelegateTable delegatestable)
{
try
{
using (var ctx = new ShowContext())
{
var delegatedata = ctx.delegates.FirstOrDefault(s => s.Barcode__c == delegatestable.Barcode__c);
if (delegatedata != null)
{
if (delegatestable.Salutation__c!=null)
{
delegatedata.Salutation__c = delegatestable.Salutation__c;
}
if (delegatestable.First_Name__c != null)
{
delegatedata.First_Name__c = delegatestable.First_Name__c;
}
if (delegatestable.Last_Name__c != null)
{
delegatedata.Last_Name__c = delegatestable.Last_Name__c;
}
if (delegatestable.Account_Name__c != null)
{
delegatedata.Account_Name__c = delegatestable.Account_Name__c;
}
if (delegatestable.Contact_Email__c != null)
{
delegatedata.Contact_Email__c = delegatestable.Contact_Email__c;
}
if (delegatestable.Category__c != null)
{
delegatedata.Category__c = delegatestable.Category__c;
}
if (delegatestable.Conference_Type__c != null)
{
delegatedata.Conference_Type__c = delegatestable.Conference_Type__c;
}
if (delegatestable.Conference_Selection__c != null)
{
delegatedata.Conference_Selection__c = delegatestable.Conference_Selection__c;
}
if (delegatestable.Payment_Status_Interface__c != null)
{
delegatedata.Payment_Status_Interface__c = delegatestable.Payment_Status_Interface__c;
}
// delegatedata.Barcode__c = delegatestable.Barcode__c;
ctx.SaveChanges();
return Request.CreateResponse(HttpStatusCode.OK, "Record updated");
}
else
{
return Request.CreateResponse(HttpStatusCode.NoContent, delegatedata);
}
}
}
catch (Exception ex)
{
return Request.CreateResponse(HttpStatusCode.BadGateway, ex);
}
}
using json for updating data through postman application
This question needs an answer!
Become an EE member today
7 DAY FREE TRIALMembers can start a 7-Day Free trial then enjoy unlimited access to the platform.
View membership options
or
Learn why we charge membership fees
We get it - no one likes a content blocker. Take one extra minute and find out why we block content.
ASKER
Open in new window