/// <summary> /// Initializes the new instance of a decrementing enumerator for a double linked collection. /// </summary> /// <param name="collection">The double linked collection to enumerate.</param> /// <param name="lower">The lower node to use as a reference for incremental enumeration.</param> /// <param name="upper">The upper node to use as a reference for incremental enumeration.</param> internal Decrementor(ListLinks <TList, TNode> collection, TNode upper = null, TNode lower = null) { if (collection != null) { _collection = collection; _lower = lower ?? _collection.Head; _upper = _node = upper ?? _collection.Tail; _current = null; } }
/// <summary> /// Initializes the new instance of an decrementing enumerable for a double linked collection. /// </summary> /// <param name="collection">The double linked collection to enumerate.</param> /// <param name="upper">The upper node to use as a reference for incremental enumeration.</param> /// <param name="lower">The lower node to use as a reference for incremental enumeration.</param> public Collection(ListLinks <TList, TNode> collection, TNode upper = null, TNode lower = null) { _collection = collection; if (lower == null || lower.Parent == collection) { _lower = lower; } else { throw new ArgumentException($"The lower node is not linked to requested list: {lower}.", nameof(lower)); } if (upper == null || upper.Parent == collection) { _upper = upper; } else { throw new ArgumentException($"The upper node is not linked to requested list: {upper}.", nameof(upper)); } }
/// <summary> /// Initializes the new instance of a decrementing enumerable for a double linked collection. /// </summary> /// <param name="collection">The double linked collection to enumerate.</param> public Collection(ListLinks <TList, TNode> collection) { _collection = collection; }
public async Task <ActionResult <CategoriesResponse> > GetCategories( [FromQuery] string code = null, [FromQuery] string name = null, [FromQuery] bool?status = null, [FromQuery] int?limit = null, [FromQuery] int?offset = null) { if ((limit != null && offset == null) || (limit == null && offset != null)) { return(BadRequest()); } if (limit <= 0 || offset <= 0) { return(BadRequest()); } List <Category> lst = null; ListLinks listLinks = null; if (limit == null) { lst = await _context.Categories.Where(c => (code == null || c.Code == code) && (name == null || c.Name == name) && (status == null || c.Status == status)).ToListAsync(); } else { var myLimit = limit ?? 0; var myOffset = offset ?? 0; var count = (await _context.Categories.Where(c => (code == null || c.Code == code) && (name == null || c.Name == name) && (status == null || c.Status == status)).ToListAsync())?.Count; lst = await _context.Categories.Where(c => (code == null || c.Code == code) && (name == null || c.Name == name) && (status == null || c.Status == status)).Skip((myOffset - 1) * myLimit).Take(myLimit).ToListAsync(); listLinks = new ListLinks { Base = $"{this.Request.Scheme}://{this.Request.Host}{this.Request.PathBase}" }; listLinks = CreateResponseListLinks(lst, myLimit, myOffset, count ?? 0); } var categories = _mapper.Map <List <DtoCategory> >(lst); var categoriesList = categories.Select(category => CreateLinksForCategory(category)); return(new CategoriesResponse { Value = categoriesList.ToList(), Meta = new DtoMeta { ResponseId = Guid.NewGuid(), Date = DateTimeOffset.UtcNow, Status = Status.Succeeded, }, Size = limit, Start = offset, _links = listLinks, }); }