void contact_PropertyChanged(object sender, Xrm.ComponentModel.PropertyChangedEventArgs e)
        {
            Contact update = (Contact)sender;

            //Utility.AlertDialog(String.Format("Actualizar nombre {0}, apellido {1},limite de credito is {2}{3}{4}", update.firstname, update.LastName, update.CreditLimit,update.ContactId,update.LogicalName), delegate() { });

            if (String.IsNullOrEmpty(update.LastName))
            {
                ErrorMessage.SetValue(string.Format("{0} {1}", ResourceStrings.LastName, ResourceStrings.RequiredMessage));
            }
            else
            {
                OrganizationServiceProxy.BeginUpdate(update, delegate(object state)
                {
                    try
                    {
                        OrganizationServiceProxy.Update(update);
                        ErrorMessage.SetValue(null);
                    }
                    catch (Exception ex)
                    {
                        ErrorMessage.SetValue(ex.Message);
                    }
                    finally
                    {
                    }
                });
            }
        }
        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);
                    }
                });
            }
        }
Exemple #3
0
        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);
                });
            }
        }
Exemple #4
0
        private void connection_PropertyChanged(object sender, Xrm.ComponentModel.PropertyChangedEventArgs e)
        {
            Connection connectionToUpdate = new Connection();
            Connection updated            = (Connection)sender;

            connectionToUpdate.ConnectionID = new Guid(updated.Id);
            bool updateRequired = false;

            switch (e.PropertyName)
            {
            case "record2roleid":
                // Check if the record1id is loaded - if not load it now so we can work out the opposite role
                if (updated.Record1Id == null)
                {
                    Connection connection = (Connection)OrganizationServiceProxy.Retrieve(Connection.LogicalName, updated.ConnectionID.Value, new string[] { "record1id" });
                    updated.Record1Id = connection.Record1Id;
                }
                connectionToUpdate.Record2RoleId = updated.Record2RoleId;
                connectionToUpdate.Record1RoleId = ObservableConnection.GetOppositeRole(updated.Record2RoleId, updated.Record1Id);

                updateRequired = true;
                break;

            case "description":
                connectionToUpdate.Description = updated.Description;
                updateRequired = true;
                break;

            case "effectivestart":
                connectionToUpdate.EffectiveStart = updated.EffectiveStart;
                updateRequired = true;
                break;

            case "effectiveend":
                connectionToUpdate.EffectiveEnd = updated.EffectiveEnd;
                updateRequired = true;
                break;
            }


            // Auto save
            if (updateRequired)
            {
                OrganizationServiceProxy.BeginUpdate(connectionToUpdate, delegate(object state)
                {
                    try
                    {
                        OrganizationServiceProxy.EndUpdate(state);
                        ErrorMessage.SetValue(null);
                    }
                    catch (Exception ex)
                    {
                        ErrorMessage.SetValue(ex.Message);
                    }
                });
            }
        }
Exemple #5
0
        private void connection_PropertyChanged(object sender, Xrm.ComponentModel.PropertyChangedEventArgs e)
        {
            Connection connectionToUpdate = new Connection();
            Connection updated            = (Connection)sender;

            connectionToUpdate.ConnectionID = new Guid(updated.Id);
            bool updateRequired = false;

            switch (e.PropertyName)
            {
            case "record2roleid":
                connectionToUpdate.Record2RoleId = updated.Record2RoleId;
                updateRequired = true;
                break;

            case "description":
                connectionToUpdate.Description = updated.Description;
                updateRequired = true;
                break;

            case "effectivestart":
                connectionToUpdate.EffectiveStart = updated.EffectiveStart;
                updateRequired = true;
                break;

            case "effectiveend":
                connectionToUpdate.EffectiveEnd = updated.EffectiveEnd;
                updateRequired = true;
                break;
            }


            // Auto save
            if (updateRequired)
            {
                OrganizationServiceProxy.BeginUpdate(connectionToUpdate, delegate(object state)
                {
                    try
                    {
                        OrganizationServiceProxy.EndUpdate(state);
                        ErrorMessage.SetValue(null);
                    }
                    catch (Exception ex)
                    {
                        ErrorMessage.SetValue(ex.Message);
                    }
                });
            }
        }
Exemple #6
0
        private void Contact_PropertyChanged(object sender, Xrm.ComponentModel.PropertyChangedEventArgs e)
        {
            Contact updated         = (Contact)sender;
            Contact contactToUpdate = new Contact();

            contactToUpdate.ContactId = new Guid(updated.Id);
            bool updateRequired = false;

            switch (e.PropertyName)
            {
            case "firstname":
                contactToUpdate.FirstName = updated.FirstName;
                updateRequired            = true;
                break;

            case "lastname":
                contactToUpdate.LastName = updated.LastName;
                updateRequired           = true;
                break;

            case "preferredcontactmethodcode":
                contactToUpdate.PreferredContactMethodCode = updated.PreferredContactMethodCode;
                updateRequired = true;
                break;

            case "creditlimit":
                contactToUpdate.CreditLimit = updated.CreditLimit;
                updateRequired = true;
                break;
            }
            if (updateRequired)
            {
                OrganizationServiceProxy.BeginUpdate(contactToUpdate, delegate(object state)
                {
                    try
                    {
                        OrganizationServiceProxy.EndUpdate(state);
                        ErrorMessage.SetValue(null);
                    }
                    catch (Exception ex)
                    {
                        ErrorMessage.SetValue(ex.Message);
                    }
                });
            }
        }
 private void connection_PropertyChanged(object sender, Xrm.ComponentModel.PropertyChangedEventArgs e)
 {
     if (e.PropertyName == "record2roleid")
     {
         // Auto Save
         Connection updated            = (Connection)sender;
         Connection connectionToUpdate = new Connection();
         connectionToUpdate.ConnectionID  = new Guid(updated.Id);
         connectionToUpdate.Record2RoleId = updated.Record2RoleId;
         OrganizationServiceProxy.BeginUpdate(connectionToUpdate, delegate(object state)
         {
             try
             {
                 OrganizationServiceProxy.EndUpdate(state);
             }
             catch (Exception ex)
             {
                 ErrorMessage.SetValue(ex.Message);
             }
         });
     }
 }
        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);
                    }
                });
            }
        }
Exemple #9
0
        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);
        }
Exemple #10
0
        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);
        }