/// <summary> /// Gets the type with the specified ID. /// </summary> /// <param name="id">The identifier.</param> /// <returns>The type, or null if not found.</returns> /// <exception cref="ArgumentNullException">id</exception> public WorkType GetWorkType(string id) { if (id == null) { throw new ArgumentNullException(nameof(id)); } using (var db = GetContext()) { EfWorkType ef = db.WorkTypes.Find(id); return(EfHelper.GetWorkType(ef)); } }
/// <summary> /// Gets the page of types matching the specified filter, /// or all of them when page size is 0. /// </summary> /// <param name="filter">The filter.</param> /// <returns>The types page.</returns> /// <exception cref="ArgumentNullException">filter</exception> public DataPage <WorkType> GetWorkTypes(WorkTypeFilter filter) { if (filter == null) { throw new ArgumentNullException(nameof(filter)); } using (var db = GetContext()) { IQueryable <EfWorkType> types = db.WorkTypes.AsQueryable(); if (!string.IsNullOrEmpty(filter.Name)) { types = types.Where(t => t.Name.Contains(filter.Name)); } int tot = types.Count(); // sort and page types = types.OrderBy(t => t.Name).ThenBy(t => t.Id); List <EfWorkType> pgTypes; if (filter.PageSize > 0) { pgTypes = types.Skip(filter.GetSkipCount()) .Take(filter.PageSize) .ToList(); } else { pgTypes = types.Skip(filter.GetSkipCount()).ToList(); } return(new DataPage <WorkType>( filter.PageNumber, filter.PageSize, tot, (from t in pgTypes select EfHelper.GetWorkType(t)).ToList())); } }