private void SaveAttribute(int objectId, MpObjectAttribute attribute, string token, MpObjectAttributeConfiguration configuration, bool parallel = false) { if (attribute.ObjectAttributeId == 0) { // These are new so add them if (parallel) { var obs = _mpObjectAttributeService.CreateAttributeAsync(token, objectId, attribute, configuration); obs.Subscribe(); } else { _mpObjectAttributeService.CreateAttribute(token, objectId, attribute, configuration); } } else { // These are existing so update them if (parallel) { _mpObjectAttributeService.UpdateAttributeAsync(token, attribute, configuration); } else { _mpObjectAttributeService.UpdateAttribute(token, attribute, configuration); } } }
private List <MpObjectAttribute> TranslateSingleToMPAttribute(Dictionary <int, ObjectSingleAttributeDTO> objectSingleAttributes) { var results = new List <MpObjectAttribute>(); if (objectSingleAttributes == null) { return(results); } foreach (var objectSingleAttribute in objectSingleAttributes) { var objectAttribute = objectSingleAttribute.Value; if (objectAttribute.Value == null) { continue; } var mpObjectAttribute = new MpObjectAttribute() { AttributeId = objectAttribute.Value.AttributeId, AttributeTypeId = objectSingleAttribute.Key, Notes = objectAttribute.Notes }; results.Add(mpObjectAttribute); } return(results); }
private void SaveAttributeAsync(int objectId, MpObjectAttribute attribute, string token, MpObjectAttributeConfiguration configuration) { if (attribute.ObjectAttributeId == 0) { // These are new so add them _mpObjectAttributeService.CreateAttribute(token, objectId, attribute, configuration); } else { // These are existing so update them _mpObjectAttributeService.UpdateAttribute(token, attribute, configuration); } }
private Dictionary <string, object> TranslateAttributeToDictionary(MpObjectAttribute attribute, MpObjectAttributeConfiguration configuration) { var keyColumn = string.Format("{0}_Attribute_ID", configuration.TableName); var attributeDictionary = new Dictionary <string, object> { { "Attribute_Type_ID", attribute.AttributeTypeId }, { "Attribute_ID", attribute.AttributeId }, { keyColumn, attribute.ObjectAttributeId }, { "Start_Date", attribute.StartDate }, { "End_Date", attribute.EndDate }, { "Notes", attribute.Notes } }; return(attributeDictionary); }
private static MpObjectAttribute TranslateMultiToMPAttribute(ObjectAttributeDTO objectAttribute, ObjectAttributeTypeDTO objectAttributeType) { var mpObjectAttribute = new MpObjectAttribute(); if (objectAttribute == null) { return(mpObjectAttribute); } mpObjectAttribute.AttributeId = objectAttribute.AttributeId; mpObjectAttribute.AttributeTypeId = objectAttributeType != null ? objectAttributeType.AttributeTypeId : 0; mpObjectAttribute.AttributeTypeName = objectAttributeType != null ? objectAttributeType.Name : string.Empty; mpObjectAttribute.StartDate = objectAttribute.StartDate; mpObjectAttribute.EndDate = objectAttribute.EndDate; mpObjectAttribute.Notes = objectAttribute.Notes; return(mpObjectAttribute); }
public void UpdateAttribute(string token, MpObjectAttribute attribute, MpObjectAttributeConfiguration configuration) { var attributeDictionary = TranslateAttributeToDictionary(attribute, configuration); var subPageId = configuration.SubPage; try { _ministryPlatformService.UpdateSubRecord(subPageId, attributeDictionary, token); } catch (Exception e) { var msg = string.Format("Error updating object attribute, objectAttributeId: {0} attributeId: {1}", attribute.ObjectAttributeId, attribute.AttributeId); _logger.Error(msg, e); throw (new ApplicationException(msg, e)); } }
public IObservable <int> CreateAttributeAsync(string token, int objectId, MpObjectAttribute attribute, MpObjectAttributeConfiguration configuration) { return(Observable.Create <int>(o => { var attributeDictionary = TranslateAttributeToDictionary(attribute, configuration); var subPageId = configuration.SubPage; var task = _ministryPlatformService.CreateSubRecordAsync(subPageId, objectId, attributeDictionary, token).ToObservable <int>(); task.Subscribe(); task.Catch <int, Exception>(tx => { var msg = string.Format("Error creating object attribute, objectId: {0} attributeId: {1}", objectId, attribute.AttributeId); _logger.Error(msg, tx); o.OnError(new ApplicationException()); return Observable.Return(-1); }); o.OnNext(task.Wait()); return Disposable.Empty; })); }