示例#1
0
        public DataTableModel(IListQuery query, IListResult result, Type itemType)
        {
            Query    = query;
            Result   = result;
            ItemType = itemType;

            GetReturnUrlRouteValues = GetReturnUrlRouteValuesDefault;
        }
示例#2
0
        public bool Equals(IListResult other)
        {
            if (other == null)
                return false;

            if (string.IsNullOrEmpty(other.Etag))
                return false;

            return other.Etag == Etag;
        }
示例#3
0
        private IListResult <TResult> HandleException <TResult>(IListResult <TResult> result, Exception exception, object command)
        {
            if (result == null)
            {
                result = new ListResult <TResult>(null);
            }

            _logger.LogError(default(EventId), exception, $"InternalServerError: {command.GetType().FullName}");

            result.Status = HttpStatusCode.InternalServerError;
            result.Errors.Add(exception.GetExceptionResponse());
            return(result);
        }
示例#4
0
        public bool Equals(IListResult other)
        {
            if (other == null)
            {
                return(false);
            }

            if (string.IsNullOrEmpty(other.Etag))
            {
                return(false);
            }

            return(other.Etag == Etag);
        }
示例#5
0
        /// <summary>
        ///     Merges original response with result defined in IResult to return full response message
        /// </summary>
        /// <param name="originalResponse">Original response created from the message</param>
        /// <param name="result">Result with messages</param>
        public static void Merge <T>(this ListResponse <T> originalResponse, IListResult <T> result)
        {
            if (result == null)
            {
                return;
            }
            originalResponse.Status = MergeStatus(originalResponse.Status, result.Status);
            originalResponse.Messages.AddRange(result.Errors);

            if (result.IsInvalid())
            {
                return;
            }
            originalResponse.Payload = result.Values;
        }
示例#6
0
        /// <summary>
        ///     Abstracting execution of the query
        /// </summary>
        /// <typeparam name="TResult">Returning result</typeparam>
        /// <typeparam name="TRequest"></typeparam>
        /// <param name="query">the execution query</param>
        /// <returns>List of results</returns>
        public virtual IListResult <TResult> ExecuteQuery <TRequest, TResult>(IListQuery <TRequest, TResult> query) where TRequest : IRequest
        {
            IListResult <TResult> result = null;

            try
            {
                result = query.Execute(_dataContext);
            }
            catch (Exception exception)
            {
                result = HandleException(result, exception, query);
            }

            return(result);
        }
示例#7
0
        private void SetNextPage <TEntity>(HttpResponseMessage result, IListResult <TEntity> listResult)
            where TEntity : TeamsObject
        {
            if (listResult is ItemsResult <TEntity> itemsResult &&
                result.Headers.TryGetValues("Link", out IEnumerable <string> values) &&
                values.FirstOrDefault() is string link &&
                !string.IsNullOrEmpty(link) &&
                link.Contains("rel=\"next\""))
            {
                link = link
                       .Replace("<https://api.ciscospark.com/v1", "")
                       .Replace(">; rel=\"next\"", "");

                if (Uri.IsWellFormedUriString(link, UriKind.Relative))
                {
                    itemsResult.SetNextPage(link);
                }
            }
        }
示例#8
0
        public IListResult <Models.Log> GetList(string Filter = null, string Sort = null, params object[] Values)
        {
            var query = repository.Query();

            if (!Filter.IsNull())
            {
                query = query.Where(Filter, Values);
            }
            if (!Sort.IsNull())
            {
                query = query.SortBy(Sort);
            }
            var list     = query.ToList().Select(entity => Mapper.Map <Models.Log>(entity)).ToList();
            var response = new IListResult <Models.Log> {
                Status = true, Result = list
            };

            return(response);
        }
示例#9
0
        /// <summary>
        ///     Merges original response with result defined in IResult to return full response message
        /// </summary>
        /// <param name="originalResponse">Original response created from the message</param>
        /// <param name="result">Result with messages</param>
        public static void Merge <T>(this PagedResponse <T> originalResponse, IListResult <T> result)
        {
            if (result == null)
            {
                return;
            }
            originalResponse.Status = MergeStatus(originalResponse.Status, result.Status);
            originalResponse.Messages.AddRange(result.Errors);

            if (result.IsInvalid())
            {
                return;
            }
            originalResponse.Payload          = result.Values;
            originalResponse.Meta.TotalCount  = result.Total;
            originalResponse.Meta.PageSize    = result.PageSize;
            originalResponse.Meta.CurrentPage = result.CurrentPage;
            originalResponse.Meta.UniqueTotal = result.UniqueTotal;
        }
示例#10
0
 public ListResult(IListResult result, IList <T> items = null)
     : this(items, page : result.Page, pageSize : result.PageSize, totalCount : result.TotalCount, wasSuccessful : result.WasSuccessful, message : result.Message)
 {
 }
示例#11
0
 public static bool IsInvalid <TValue>(this IListResult <TValue> originalResult)
 {
     return(!originalResult.IsValid());
 }
示例#12
0
 public static bool IsValid <TValue>(this IListResult <TValue> originalResult)
 {
     return(originalResult.Status == HttpStatusCode.OK);
 }