Ejemplo n.º 1
0
        protected override IProviderResponse <TEntityFragment> MapResponse <TEntityFragment>(IDocumentFragment <TSvcFragmentEntity> cbSvcResult, string fragmentKey)
        {
            if (cbSvcResult != null)
            {
                int fragmentIndex;

                dynamic data = (Int32.TryParse(fragmentKey, out fragmentIndex)) ? cbSvcResult.Content <TEntityFragment>(fragmentIndex) : cbSvcResult.Content <TEntityFragment>(fragmentKey);

                if (data == null && typeof(TEntityFragment) == typeof(bool))
                {
                    data = cbSvcResult.Exists(fragmentKey);
                }

                return(new ProviderResponse <TEntityFragment>()
                {
                    Data = data,
                    Success = cbSvcResult.Success,
                    Message = cbSvcResult.Message,
                    ResponseStatus = cbSvcResult.Status.ToString("f"),
                    Exception = cbSvcResult.Exception,
                    Version = cbSvcResult.Cas
                });
            }

            return(new ProviderResponse <TEntityFragment>()
            {
                Success = false,
                Message = string.Empty,
                ResponseStatus = CustomResponseErrors.CBSvcMappingError.ToString("f")
            });
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Get the existence result for a fragement of type <typeparamref name="TContent"/> from a document of type <typeparamref name="TDocument"/>,
        /// using a given lambda expression path.
        /// </summary>
        /// <typeparam name="TDocument">Type of the parent document.</typeparam>
        /// <typeparam name="TContent">Type of the subdocument.</typeparam>
        /// <param name="result"><see cref="IDocumentFragment{TDocument}"/> where the the subdocument lookup was returned.</param>
        /// <param name="path">Lambda expression path that navigates to the subdocument from the parent document.
        /// This must be a path that was provided originally to the <see cref="ILookupInBuilder{TDocument}"/>.</param>
        /// <returns>True if the subdocument exists.</returns>
        /// <exception cref="ArgumentNullException"><paramref name="result"/> or <paramref name="path"/> is null.</exception>
        public static bool Exists <TDocument, TContent>(this IDocumentFragment <TDocument> result, Expression <Func <TDocument, TContent> > path)
        {
            if (result == null)
            {
                throw new ArgumentNullException("result");
            }
            if (path == null)
            {
                throw new ArgumentNullException("path");
            }

            return(result.Exists(ParsePath(result as ITypeSerializerProvider, path)));
        }