public DataTableModel(IListQuery query, IListResult result, Type itemType) { Query = query; Result = result; ItemType = itemType; GetReturnUrlRouteValues = GetReturnUrlRouteValuesDefault; }
public bool Equals(IListResult other) { if (other == null) return false; if (string.IsNullOrEmpty(other.Etag)) return false; return other.Etag == Etag; }
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); }
public bool Equals(IListResult other) { if (other == null) { return(false); } if (string.IsNullOrEmpty(other.Etag)) { return(false); } return(other.Etag == Etag); }
/// <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; }
/// <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); }
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); } } }
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); }
/// <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; }
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) { }
public static bool IsInvalid <TValue>(this IListResult <TValue> originalResult) { return(!originalResult.IsValid()); }
public static bool IsValid <TValue>(this IListResult <TValue> originalResult) { return(originalResult.Status == HttpStatusCode.OK); }