Here is the same code:-
/// <summary>
///
Update Opportunity status to lost
/// </summary>
/// <param
name="_ID">opportunity GUID</param>
/// <param
name="_Service">CRM IOrganizationService object</param>
private void UpdateOpptyStatusLost(Guid
_ID, IOrganizationService _Service)
{
try
{
Entity oppClose = new Entity("opportunityclose");
// Set the
opportunityclose activity subject.
oppClose["subject"] = "lost
opportunity";
// Create an
entity reference to the opportunity being lost.
oppClose["opportunityid"] = new EntityReference("opportunity", _ID);
// Create the
LostOpportunityRequest request.
LoseOpportunityRequest loseOppReq =
new LoseOpportunityRequest();
loseOppReq.OpportunityClose =
oppClose;
loseOppReq.Status = new OptionSetValue(-1);
// Execute the
request.
_Service.Execute(loseOppReq);
}
catch (Exception _ex)
{
throw _ex;
}
}