/// <summary> /// This method saves note. /// </summary> /// <returns></returns> public async System.Threading.Tasks.Task SaveNote() { progressRing.IsActive = true; // Instantiate note Annotation annotation = new Annotation(); // Set regarding annotation.ObjectId = new EntityReference(EntityMetadataEx.EntityMetadata.LogicalName, Id); annotation.Subject = txtTitle.Text; annotation.NoteText = txtNoteText.Text; // If there is an attachment file, then handle it. if (AttachmentFile != null) { annotation.FileName = AttachmentFile.Name; IRandomAccessStreamWithContentType fileStream = await AttachmentFile.OpenReadAsync(); byte[] fileBytes = null; fileBytes = new byte[fileStream.Size]; using (DataReader reader = new DataReader(fileStream)) { await reader.LoadAsync((uint)fileStream.Size); reader.ReadBytes(fileBytes); } annotation.DocumentBody = Convert.ToBase64String(fileBytes); } if (!String.IsNullOrEmpty(txtId.Text)) { annotation.Id = Guid.Parse(txtId.Text); } // Create a note await CRMHelper.UpsertRecord(annotation); // Reverse the control visibility lvList.Visibility = Visibility.Visible; spNote.Visibility = Visibility.Collapsed; // Reload data await LoadData(); progressRing.IsActive = false; }
/// <summary> /// This methos update UserSettings /// </summary> /// <returns></returns> private async Task SaveSettings() { // Update User Settings. UserSettings userSettings = new UserSettings(); userSettings.Id = CRMHelper.UserSettings.Id; userSettings.PagingLimit = int.Parse((cbRecordsPerView.SelectedItem as TextBlock).Text); userSettings.TimeZoneCode = (cbTimeZones.SelectedItem as TimeZoneDefinition).TimeZoneCode; // Call update await CRMHelper.UpsertRecord(userSettings); // Now update cache data CRMHelper.UserSettings.TimeZoneCode = userSettings.TimeZoneCode; CRMHelper.UserSettings.PagingLimit = userSettings.PagingLimit; await Util.SaveToLocal(CRMHelper.UserSettings, "userSettings.dat"); abAccept.IsEnabled = false; }
/// <summary> /// Saves Email record with Attachments. /// </summary> /// <returns></returns> public async Task Save() { Entity modifiedRecord; // If it is regarding, then pass all the record information which contains mapped data to modifiedrecord. if (isRegarding) { modifiedRecord = Record; } // Otherwise, create blank record else { modifiedRecord = new Entity(); } modifiedRecord.LogicalName = EntityMetadataEx.EntityMetadata.LogicalName; // If update, then assign Id if (isUpdate) { modifiedRecord.Id = Record.Id; } foreach (var field in Fields) { // If no data changed, then no need to pass the value. if (isUpdate && field.FieldData == Record[field.FieldMetadata.LogicalName]) { continue; } // If required fields have no value, then show error message. if ((bool)field.FieldMetadata.IsValidForCreate && (field.FieldMetadata.RequiredLevel.Value == AttributeRequiredLevel.ApplicationRequired || field.FieldMetadata.RequiredLevel.Value == AttributeRequiredLevel.SystemRequired) && field.FieldData == null) { MessageDialog dialog = new MessageDialog(string.Format(loader.GetString("RequiredField"), field.FieldMetadata.DisplayName.UserLocalizedLabel.Label)); await dialog.ShowAsync(); lvFields.SelectedItem = ((lvFields.FindName("lbl" + field.FieldMetadata.LogicalName) as TextBlock).Parent as StackPanel).Parent; lvFields.UpdateLayout(); lvFields.ScrollIntoView(lvFields.SelectedItem); return; } // If value has been changed, then pass the data to modified record. modifiedRecord[field.FieldMetadata.LogicalName] = field.FieldData; } progressRing.IsActive = true; // Create/Update record and store the id back original record Record = await CRMHelper.UpsertRecord(modifiedRecord); // Now check attachments. foreach (ActivityMimeAttachment attachment in this.lvList.Items) { // Assign regarding activity. Attachment should have ObjectTypeCode already attachment.ObjectId = Record.ToEntityReference(); // Then save it await CRMHelper.UpsertRecord(attachment); } progressRing.IsActive = false; }
/// <summary> /// This method saves the record /// </summary> /// <returns></returns> public async System.Threading.Tasks.Task <Entity> Save() { Entity modifiedRecord; // If it is regarding, then pass all the record information which contains mapped data to modifiedrecord. if (isRegarding) { modifiedRecord = Record; } // Otherwise, create blank record else { modifiedRecord = new Entity(); } modifiedRecord.LogicalName = EntityMetadataEx.EntityMetadata.LogicalName; // If update, then assign Id if (isUpdate) { modifiedRecord.Id = Record.Id; } // Only update modified fields foreach (var field in Fields) { // If no data changed, then no need to pass the value. if (isUpdate && field.FieldData == Record[field.FieldMetadata.LogicalName]) { continue; } // If required fields have no value, then show error message. if ((bool)field.FieldMetadata.IsValidForCreate && (field.FieldMetadata.RequiredLevel.Value == AttributeRequiredLevel.ApplicationRequired || field.FieldMetadata.RequiredLevel.Value == AttributeRequiredLevel.SystemRequired) && field.FieldData == null) { MessageDialog dialog = new MessageDialog(string.Format(loader.GetString("RequiredField"), field.FieldMetadata.DisplayName.UserLocalizedLabel.Label)); await dialog.ShowAsync(); lvFields.SelectedItem = ((lvFields.FindName("lbl" + field.FieldMetadata.LogicalName) as TextBlock).Parent as StackPanel).Parent; lvFields.UpdateLayout(); lvFields.ScrollIntoView(lvFields.SelectedItem); return(null); } // If value has been changed, then pass the data to modified record. modifiedRecord[field.FieldMetadata.LogicalName] = field.FieldData; } progressRing.IsActive = true; // Create/Update record. Entity result = await CRMHelper.UpsertRecord(modifiedRecord); // If this is update then retrieve latest data again from server after update and return. if (isUpdate) { ColumnSet columnSet = new ColumnSet(); columnSet.AddColumns(Fields.Select(x => x.FieldMetadata.LogicalName).ToArray()); return(await CRMHelper.RetrieveRecord(EntityMetadataEx.EntityMetadata, result.Id, columnSet)); } // If this is new record, then simply return result. else { return(result); } }