Exemplo n.º 1
0
        public object MoveDataValue(MoveDataValueRequest request)
        {
            // Variables.
            var result   = default(object);
            var rootId   = CoreConstants.System.Root.ToInvariantString();
            var parentId = GuidHelper.GetGuid(request.NewParentId);


            // Catch all errors.
            try
            {
                // Parse the data value ID.
                var dataValueId = GuidHelper.GetGuid(request.DataValueId);


                // Get the ID path.
                var path = Entities.Retrieve(parentId).Path
                           .Concat(new[] { dataValueId }).ToArray();


                // Get data value and update path.
                var dataValue = Persistence.Retrieve(dataValueId);
                dataValue.Path = path;


                // Persist data value.
                Persistence.Persist(dataValue);


                // Variables.
                var fullPath = new[] { rootId }
                .Concat(path.Select(x => GuidHelper.GetString(x)))
                .ToArray();


                // Success.
                result = new
                {
                    Success = true,
                    Id      = GuidHelper.GetString(dataValueId),
                    Path    = fullPath
                };
            }
            catch (Exception ex)
            {
                // Error.
                LogHelper.Error <DataValuesController>(MoveDataValueError, ex);
                result = new
                {
                    Success = false,
                    Reason  = UnhandledError
                };
            }


            // Return result.
            return(result);
        }
        public object MoveDataValue(MoveDataValueRequest request)
        {
            // Variables.
            var result = default(object);
            var rootId = CoreConstants.System.Root.ToInvariantString();
            var parentId = GuidHelper.GetGuid(request.NewParentId);

            // Catch all errors.
            try
            {

                // Parse the data value ID.
                var dataValueId = GuidHelper.GetGuid(request.DataValueId);

                // Get the ID path.
                var path = Entities.Retrieve(parentId).Path
                    .Concat(new[] { dataValueId }).ToArray();

                // Get data value and update path.
                var dataValue = Persistence.Retrieve(dataValueId);
                dataValue.Path = path;

                // Persist data value.
                Persistence.Persist(dataValue);

                // Variables.
                var fullPath = new[] { rootId }
                    .Concat(path.Select(x => GuidHelper.GetString(x)))
                    .ToArray();

                // Success.
                result = new
                {
                    Success = true,
                    Id = GuidHelper.GetString(dataValueId),
                    Path = fullPath
                };

            }
            catch (Exception ex)
            {

                // Error.
                LogHelper.Error<DataValuesController>(MoveDataValueError, ex);
                result = new
                {
                    Success = false,
                    Reason = UnhandledError
                };

            }

            // Return result.
            return result;
        }