private void SaveNextRecord(List <Contact> dirtyCollection, string errorMessage, Action callBack) { Contact contactToSave = dirtyCollection[0]; if (contactToSave.ContactId == null) { OrganizationServiceProxy.BeginCreate(contactToSave, delegate(object r) { try { Guid newID = OrganizationServiceProxy.EndCreate(r); contactToSave.ContactId = newID; contactToSave.EntityState = EntityStates.Unchanged; } catch (Exception ex) { // Something when wrong with create errorMessage = errorMessage + ex.Message + "\n"; } dirtyCollection.Remove(contactToSave); if (dirtyCollection.Count == 0) { callBack(); } else { SaveNextRecord(dirtyCollection, errorMessage, callBack); } }); } else { OrganizationServiceProxy.BeginUpdate(contactToSave, delegate(object r) { try { OrganizationServiceProxy.EndUpdate(r); contactToSave.EntityState = EntityStates.Unchanged; } catch (Exception ex) { // Something when wrong errorMessage = errorMessage + ex.Message + "\n"; } dirtyCollection.Remove(contactToSave); if (dirtyCollection.Count == 0) { callBack(); } else { SaveNextRecord(dirtyCollection, errorMessage, callBack); } }); } }
private void SaveNextRecord(List <QuoteDetail> dirtyCollection, List <string> errorMessages, Action callBack) { QuoteDetail itemToSave = dirtyCollection[0]; if (itemToSave.EntityState == EntityStates.Deleted) { OrganizationServiceProxy.BeginDelete("quotedetail", itemToSave.QuoteDetailId, delegate(object r) { try { OrganizationServiceProxy.EndDelete(r); itemToSave.EntityState = EntityStates.Unchanged; } catch (Exception ex) { // Something when wrong with delete errorMessages.Add(ex.Message); } FinishSaveRecord(dirtyCollection, errorMessages, callBack, itemToSave); }); } else if (itemToSave.QuoteDetailId == null) { OrganizationServiceProxy.BeginCreate(itemToSave, delegate(object r) { try { Guid newID = OrganizationServiceProxy.EndCreate(r); itemToSave.QuoteDetailId = newID; itemToSave.EntityState = EntityStates.Unchanged; } catch (Exception ex) { // Something when wrong with create errorMessages.Add(ex.Message); } FinishSaveRecord(dirtyCollection, errorMessages, callBack, itemToSave); }); } else { OrganizationServiceProxy.BeginUpdate(itemToSave, delegate(object r) { try { OrganizationServiceProxy.EndUpdate(r); itemToSave.EntityState = EntityStates.Unchanged; } catch (Exception ex) { // Something when wrong with update errorMessages.Add(ex.Message); } FinishSaveRecord(dirtyCollection, errorMessages, callBack, itemToSave); }); } }
public void SaveCommand() { bool contactIsValid = ((IValidatedObservable)this).IsValid(); if (!contactIsValid) { ((IValidatedObservable)this).Errors.ShowAllMessages(true); return; } IsBusy.SetValue(true); Contact contact = new Contact(); string accountId = string.Empty; if (ParentPage.Ui != null) { string guid = ParentPage.Data.Entity.GetId(); if (guid != null) { accountId = guid.Replace("{", "").Replace("}", ""); } } //Asociamos los datos de la entidad contacto contact.ParentCustomerId = new EntityReference(new Guid(accountId), "account", null); contact.CreditLimit = CreditLimit.GetValue(); contact.firstname = FirstName.GetValue(); contact.LastName = LastName.GetValue(); contact.PreferredContactMethodCode = PreferredContactMethodCode.GetValue(); OrganizationServiceProxy.BeginCreate(contact, delegate(object state) { try { ContactId.SetValue(OrganizationServiceProxy.EndCreate(state)); OnSaveComplete(null); ((IValidatedObservable)this).Errors.ShowAllMessages(false); } catch (Exception ex) { OnSaveComplete(ex.Message); } finally { IsBusy.SetValue(false); AddNewVisible.SetValue(false); } }); }
public void SaveCommand() { if (!((IValidatedObservable)this).IsValid()) { ((IValidatedObservable)(object)this).Errors.ShowAllMessages(true); return; } this.IsBusy.SetValue(true); this.AddNewVisible.SetValue(false); Connection connection = new Connection(); connection.Record1Id = Record1Id.GetValue(); connection.Record2Id = Record2Id.GetValue(); connection.Record1RoleId = Record1RoleId.GetValue(); connection.Record2RoleId = Record2RoleId.GetValue(); EntityReference oppositeRole = GetOppositeRole(connection.Record1RoleId, connection.Record2Id); connection.Record2RoleId = oppositeRole; OrganizationServiceProxy.BeginCreate(connection, delegate(object state) { try { ConnectionId.SetValue(OrganizationServiceProxy.EndCreate(state)); OnSaveComplete(null); Record1Id.SetValue(null); Record1RoleId.SetValue(null); ((IValidatedObservable)(object)this).Errors.ShowAllMessages(false); } catch (Exception ex) { // Something went wrong - report it OnSaveComplete(ex.Message); } finally { this.IsBusy.SetValue(false); } }); }
public void SaveCommand() { bool isValid = ((IValidatedObservable)this).IsValid(); if (!isValid) { ((IValidatedObservable)this).Errors.ShowAllMessages(true); return; } IsBusy.SetValue(true); AddNewVisible.SetValue(false); Contact contact = new Contact(); contact.FirstName = FirstName.GetValue(); contact.LastName = LastName.GetValue(); contact.ParentCustomerId = ParentCustomerId.GetValue(); contact.PreferredContactMethodCode = PreferredContactMethodCode.GetValue(); contact.CreditLimit = CreditLimit.GetValue(); OrganizationServiceProxy.BeginCreate(contact, delegate(object state) { try { ContactId.SetValue(OrganizationServiceProxy.EndCreate(state)); OnSaveComplete(null); FirstName.SetValue(null); LastName.SetValue(null); PreferredContactMethodCode.SetValue(null); CreditLimit.SetValue(null); ((IValidatedObservable)this).Errors.ShowAllMessages(false); } catch (Exception ex) { OnSaveComplete(ex.Message); } finally { IsBusy.SetValue(false); } }); }
private void SaveNextRecord(List <Contact> dirtyCollection, string errorMessage, Action callBack) { Contact contactToSave = dirtyCollection[0]; if (contactToSave.ContactId == null) { OrganizationServiceProxy.BeginCreate(contactToSave, delegate(object r) { try { Guid newID = OrganizationServiceProxy.EndCreate(r); contactToSave.ContactId = newID; contactToSave.EntityState = EntityStates.Unchanged; } catch (Exception ex) { // Something when wrong with create errorMessage = errorMessage + ex.Message + "\n"; } dirtyCollection.Remove(contactToSave); if (dirtyCollection.Count == 0) { callBack(); } else { SaveNextRecord(dirtyCollection, errorMessage, callBack); } }); } else { OrganizationServiceProxy.BeginUpdate(contactToSave, delegate(object r) { try { OrganizationServiceProxy.EndUpdate(r); contactToSave.EntityState = EntityStates.Unchanged; if (contactToSave.OwnerId != null) { // Assign the record OrganizationServiceProxy.RegisterExecuteMessageResponseType("Assign", typeof(AssignResponse)); AssignRequest assignRequest = new AssignRequest(); assignRequest.Target = contactToSave.ToEntityReference(); assignRequest.Assignee = contactToSave.OwnerId; OrganizationServiceProxy.Execute(assignRequest); } } catch (Exception ex) { // Something when wrong errorMessage = errorMessage + ex.Message + "\n"; } dirtyCollection.Remove(contactToSave); if (dirtyCollection.Count == 0) { callBack(); } else { SaveNextRecord(dirtyCollection, errorMessage, callBack); } }); } }
public Action SaveCommand() { if (_saveCommand == null) { _saveCommand = delegate() { bool confirmed = Script.Confirm(String.Format("Are you sure save these sessions?")); if (!confirmed) { return; } try { IsBusy.SetValue(true); IsBusyProgress.SetValue(0); IsBusyMessage.SetValue("Saving..."); // Create a an array of sessions to be saved List <dev1_session> editedSessions = SessionDataView.GetEditedSessions(); DelegateItterator.CallbackItterate(delegate(int index, Action nextCallback, ErrorCallBack errorCallBack) { dev1_session session = editedSessions[index]; IsBusyProgress.SetValue((index / editedSessions.Count) * 100); // Create/Update the session if (session.dev1_sessionId == null) { OrganizationServiceProxy.BeginCreate(session, delegate(object result) { IsBusyProgress.SetValue((index / editedSessions.Count) * 100); try { session.dev1_sessionId = OrganizationServiceProxy.EndCreate(result); session.EntityState = EntityStates.Unchanged; session.RaisePropertyChanged("EntityState"); nextCallback(); } catch (Exception ex) { // TODO: Mark error row Script.Alert(ex.Message); nextCallback(); } }); } else { OrganizationServiceProxy.BeginUpdate(session, delegate(object result) { try { OrganizationServiceProxy.EndUpdate(result); session.EntityState = EntityStates.Unchanged; session.RaisePropertyChanged("EntityState"); nextCallback(); } catch (Exception ex) { // TODO: Mark error row Script.Alert(ex.Message); nextCallback(); } }); } }, editedSessions.Count, delegate() { // Completed IsBusyProgress.SetValue(100); IsBusy.SetValue(false); }, delegate(Exception ex) { // Error ReportError(ex); }); } catch (Exception ex) { ReportError(ex); } }; } return(_saveCommand); }
public Action SaveCommand() { if (_saveCommand == null) { _saveCommand = delegate() { if (!((IValidatedObservable)SelectedJob).IsValid()) { ValidationErrors validationResult = ValidationApi.Group(SelectedJob.GetValue()); validationResult.ShowAllMessages(true); return; } bool confirmed = Script.Confirm(String.Format("Are you sure you want to save this schedule?")); if (!confirmed) { return; } IsBusy.SetValue(true); IsBusyProgress.SetValue(0); IsBusyMessage.SetValue("Saving..."); // Create a new Scheduled Job dev1_ScheduledJob jobToSave = new dev1_ScheduledJob(); ScheduledJob job = this.SelectedJob.GetValue(); jobToSave.dev1_Name = job.Name.GetValue(); jobToSave.dev1_StartDate = job.StartDate.GetValue(); jobToSave.dev1_WorkflowName = job.WorkflowId.GetValue().Name; jobToSave.dev1_RecurrancePattern = RecurrancePatternMapper.Serialise(job); if (job.ScheduledJobId.GetValue() == null) { // Create the schedule OrganizationServiceProxy.BeginCreate(jobToSave, delegate(object createJobResponse) { try { job.ScheduledJobId.SetValue(OrganizationServiceProxy.EndCreate(createJobResponse)); CreateBulkDeleteJobs(job); } catch (Exception ex) { ReportError(ex); } }); } else { jobToSave.dev1_ScheduledJobId = job.ScheduledJobId.GetValue(); // Update the schedule OrganizationServiceProxy.BeginUpdate(jobToSave, delegate(object createJobResponse) { try { OrganizationServiceProxy.EndUpdate(createJobResponse); DeleteBulkDeleteJobs(job.ScheduledJobId.GetValue(), delegate() { // Create new jobs CreateBulkDeleteJobs(job); }); } catch (Exception ex) { ReportError(ex); } }); } }; } return(_saveCommand); }