/// <summary> /// This method firstly create task, then complete it if passed task does not have id. /// If passed entity has id, then change state back to active first, update data, then /// complete it again. /// </summary> /// <param name="activity">Activity Record to update</param> /// <param name="contact">Contact Record for regarding information</param> public async Task UpsertTask(Activity activity, Contact contact) { // Get AccessToken _proxy.AccessToken = await ADALHelper.GetTokenSilent(); // Instantiate a Task entity. Entity task = new Entity("task"); task["subject"] = activity.Subject; task["actualstart"] = activity.ActualEnd.Date; task["actualend"] = activity.ActualEnd.Date; task["description"] = activity.Notes; task["regardingobjectid"] = new EntityReference("contact", contact.Id); task.Id = activity.Id; // If passed data does not have id, then its new operation. if (task.Id == null || task.Id == Guid.Empty) { // Create record first Guid taskId = await _proxy.Create(task); // Then complete it SetStateRequest setStateRequest = new SetStateRequest() { EntityMoniker = new EntityReference("task", taskId), State = new OptionSetValue(1), Status = new OptionSetValue(5) }; await _proxy.Execute(setStateRequest); } else { // First set state back to active SetStateRequest setStateRequest = new SetStateRequest() { EntityMoniker = new EntityReference("task", task.Id), State = new OptionSetValue(0), Status = new OptionSetValue(3) }; await _proxy.Execute(setStateRequest); // then update task await _proxy.Update(task); // finally complete it again setStateRequest = new SetStateRequest() { EntityMoniker = new EntityReference("task", task.Id), State = new OptionSetValue(1), Status = new OptionSetValue(5) }; await _proxy.Execute(setStateRequest); } }
async partial void SetLatLong(UIBarButtonItem sender) { OrganizationDataWebServiceProxy orgService = new OrganizationDataWebServiceProxy { ServiceUrl = MasterViewController.CrmUrl, AccessToken = NSUserDefaults.StandardUserDefaults.StringForKey("AccessToken") }; Entity account = (Entity)_detailItem; account["address1_latitude"] = _iPhoneLocationManager.Location.Coordinate.Latitude; account["address1_longitude"] = _iPhoneLocationManager.Location.Coordinate.Longitude; AccountLatitude.Text = _iPhoneLocationManager.Location.Coordinate.Latitude.ToString(CultureInfo.InvariantCulture); AccountLongitude.Text = _iPhoneLocationManager.Location.Coordinate.Longitude.ToString(CultureInfo.InvariantCulture); await orgService.Update(account); }