示例#1
0
        private JsonConverter[] GetCorrectConverters(object entity)
        {
            // Get correct converter
            ExactOnlineJsonConverter converter;

            if (_createUpdateJson)
            {
                var emanager = GetEntityController(entity);
                if (emanager != null)
                {
                    // Entity is an existing entity. Create JsonConverter for updating an existing entity
                    converter = new ExactOnlineJsonConverter(emanager.OriginalEntity, _entityControllerDelegate);
                }
                else
                {
                    // Entity is a new entity. Create JsonConverter for sending only changed fields
                    var emptyEntity = Activator.CreateInstance(entity.GetType());
                    converter = new ExactOnlineJsonConverter(emptyEntity, _entityControllerDelegate);
                }
            }
            else
            {
                converter = new ExactOnlineJsonConverter();
            }

            var converters = new[] { (JsonConverter)converter };

            return(converters);
        }
示例#2
0
        /// <summary>
        /// Converts an Object to Json for Updating
        /// The method creates Json using the original entity
        /// and the current entity to create Json only for altered fields
        /// </summary>
        /// <typeparam name="T">Type of Exact.Web.Api.Models</typeparam>
        /// <param name="originalEntity">Original State of the Entity</param>
        /// <param name="entity">Current State of the Entity</param>
        /// <param name="entityControllerDelegate">Delegate for entitycontroller</param>
        /// <returns>Json String</returns>
        public string ConvertObjectToJson <T>(T originalEntity, T entity, GetEntityController entityControllerDelegate)
        {
            var converter  = new ExactOnlineJsonConverter(originalEntity, entityControllerDelegate);
            var converters = new JsonConverter[1];

            converters[0] = converter;

            return(JsonConvert.SerializeObject(entity, converters));
        }
        private JsonConverter[] GetCorrectConverters(object entity)
        {
            // Get correct converter
            var converter = new ExactOnlineJsonConverter();

            if (_createUpdateJson)
            {
                var emanager = GetEntityController(entity);
                if (emanager != null)
                {
                    // Entity is an existing entity. Create JsonConverter for updating an existing entity
                    converter = new ExactOnlineJsonConverter(emanager.OriginalEntity, _entityControllerDelegate);
                }
            }

            //converter.SkipReferenceField = true;
            var converters = new[] { (JsonConverter)converter };

            return(converters);
        }