Beispiel #1
0
        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));
            }
        }
Beispiel #2
0
        public ObjectAllAttributesDTO GetObjectAttributes(string token, int objectId, MpObjectAttributeConfiguration configuration, List <MpAttribute> mpAttributes)
        {
            var mpObjectAttributes = _mpObjectAttributeService.GetCurrentObjectAttributes(token, objectId, configuration);

            var allAttributes = new ObjectAllAttributesDTO();

            allAttributes.MultiSelect  = TranslateToAttributeTypeDtos(mpObjectAttributes, mpAttributes);
            allAttributes.SingleSelect = TranslateToSingleAttributeTypeDtos(mpObjectAttributes, mpAttributes);

            return(allAttributes);
        }
Beispiel #3
0
        public ObjectAllAttributesDTO GetObjectAttributes(string token, int objectId, MpObjectAttributeConfiguration configuration)
        {
            var mpAttributes = _mpAttributeService.GetAttributes(null);

            return(GetObjectAttributes(token, objectId, configuration, mpAttributes));
        }
Beispiel #4
0
 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);
     }
 }
Beispiel #5
0
 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);
         }
     }
 }
Beispiel #6
0
        public void SaveObjectMultiAttribute(string token, int objectId, ObjectAttributeDTO objectAttribute, MpObjectAttributeConfiguration configuration, bool parallel)
        {
            objectAttribute.StartDate = ConvertToServerDate(objectAttribute.StartDate);
            if (objectAttribute.EndDate != null)
            {
                objectAttribute.EndDate = ConvertToServerDate(objectAttribute.EndDate.Value);
            }

            var mpObjectAttribute   = TranslateMultiToMPAttribute(objectAttribute, null);
            var persistedAttributes = _mpObjectAttributeService.GetCurrentObjectAttributes(token, objectId, configuration, objectAttribute.AttributeId);

            if (persistedAttributes.Count >= 1)
            {
                mpObjectAttribute.ObjectAttributeId = persistedAttributes[0].ObjectAttributeId;
            }

            SaveAttribute(objectId, mpObjectAttribute, token, configuration, parallel);
        }
Beispiel #7
0
        public void SaveObjectAttributes(int objectId,
                                         Dictionary <int, ObjectAttributeTypeDTO> objectAttributes,
                                         Dictionary <int, ObjectSingleAttributeDTO> objectSingleAttributes, MpObjectAttributeConfiguration configuration)
        {
            var currentAttributes = TranslateMultiToMPAttributes(objectAttributes);

            currentAttributes.AddRange(TranslateSingleToMPAttribute(objectSingleAttributes));

            if (objectAttributes == null)
            {
                return;
            }

            var apiUserToken = _apiUserService.GetToken();

            var persistedAttributes = _mpObjectAttributeService.GetCurrentObjectAttributes(apiUserToken, objectId, configuration);
            var attributesToSave    = GetDataToSave(currentAttributes, persistedAttributes);

            foreach (var attribute in attributesToSave)
            {
                SaveAttribute(objectId, attribute, apiUserToken, configuration);
            }
        }
Beispiel #8
0
 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;
     }));
 }
Beispiel #9
0
        public List <MpObjectAttribute> GetCurrentObjectAttributes(string token, int objectId, MpObjectAttributeConfiguration configuration, int?attributeIdFilter = null)
        {
            var    table   = configuration.TableName;
            string columns = $"{table}_Attribute_ID AS ObjectAttributeId, {table}_Attributes.Attribute_ID, {table}_Attributes.Start_Date, {table}_Attributes.End_Date, Attribute_ID_Table.Attribute_Type_ID, Notes, Attribute_ID_Table_Attribute_Category_ID_Table.Attribute_Category, Attribute_ID_Table_Attribute_Type_ID_Table.Attribute_Type, Attribute_ID_Table.Description";
            string filter  = $"{table}_ID = {objectId} AND ({table}_Attributes.End_Date Is Null OR {table}_Attributes.End_Date >= GetDate())";

            if (attributeIdFilter != null)
            {
                filter += $" AND Attribute_ID_Table.Attribute_ID = {attributeIdFilter}";
            }

            var objectAttributes = _ministryPlatformRest.UsingAuthenticationToken(token).SearchTable <MpObjectAttribute>($"{table}_Attributes", filter, columns);

            return(objectAttributes);
        }
Beispiel #10
0
        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);
        }
        public List <MpObjectAttribute> GetCurrentObjectAttributes(string token, int objectId, MpObjectAttributeConfiguration configuration, int?attributeTypeIdFilter = null)
        {
            var subPageViewId = configuration.SelectedSubPage;
            var searchString  = attributeTypeIdFilter.HasValue ? string.Format(",,,,\"{0}\"", attributeTypeIdFilter.Value) : "";
            var records       = _ministryPlatformService.GetSubpageViewRecords(subPageViewId, objectId, token, searchString);

            var keyColumn = string.Format("{0}_Attribute_ID", configuration.TableName);

            var objectAttributes = records.Select(record => new MpObjectAttribute
            {
                ObjectAttributeId = record.ToInt(keyColumn),

                AttributeId       = record.ToInt("Attribute_ID"),
                StartDate         = record.ToDate("Start_Date"),
                EndDate           = record.ToNullableDate("End_Date"),
                Notes             = record.ToString("Notes"),
                AttributeTypeId   = record.ToInt("Attribute_Type_ID"),
                AttributeTypeName = record.ToString("Attribute_Type")
            }).ToList();

            return(objectAttributes);
        }