public async Task <IActionResult> GetAsync([FromRoute] Guid organizationuuid, [FromQuery] string sort = null, [FromQuery] string filter = null, [FromQuery] int start = 0, [FromQuery] int limit = 25) { try { //note: //org users and org roles are read from mh meta db! //This is where some env core objects are kept var users = await OrganizationContext.GetOrganizationAssetsAsync <MapHiveUser>(GetDefaultDbContext(), sort, filter, start, limit); if (users == null) { return(NotFound()); } var roles2users = await OrganizationContext.GetOrgRoles2UsersMapAsync(GetDefaultDbContext()); foreach (var user in users?.assets) { user.OrganizationRole = OrganizationContext.GetUserOrgRole(roles2users, user.Uuid); } HttpContext.AppendTotalHeader(users?.count ?? 0); return(Ok(users?.assets)); } catch (Exception ex) { return(HandleException(ex)); } }
/// <summary> /// Applies a total header as extracted from IRestResponse /// </summary> /// <param name="apiResponse"></param> protected void ApplyTotalHeader(IRestResponse apiResponse) { //this is a standard get list pass through, so for paging need the value of total var totalHeader = apiResponse.Headers.FirstOrDefault(x => x.Name == WebClientConfiguration.HeaderTotal); if (totalHeader != null) { int.TryParse(totalHeader.Value.ToString(), out var total); HttpContext.AppendTotalHeader(total); } }
/// <summary> /// Gets a list of objects; performs automated conversion of output into specified DTO /// </summary> /// <typeparam name="TRead">Type to read</typeparam> /// <typeparam name="TDto">DTO Type to convert the output into</typeparam> /// <param name="db">DbContext to be used; when not provided a default instance of TDbCtx will be used</param> /// <param name="sort"></param> /// <param name="filter"></param> /// <param name="start"></param> /// <param name="limit"></param> /// <returns></returns> protected virtual async Task <IActionResult> ReadAsync <TRead, TDto>(DbContext db, string sort = null, string filter = null, int start = 0, int limit = 25) where TRead : Base where TDto : class { //all stuff is instance based, so need to obtain one first var obj = (TRead)Activator.CreateInstance(typeof(TRead)); try { var filters = filter.ExtJsJsonFiltersToReadFilters(); //this is web service read call so read as no tracking - detached var data = await obj.ReadAsync(db, sort.ExtJsJsonSortersToReadSorters(), filters, start, limit, detached : true); if (data.Any()) { //got the data, so can get the count too. HttpContext.AppendTotalHeader(await obj.ReadCountAsync(db, filters)); //Note: this could and should be done in a more elegant way. but had no smart ideas at a time. //will come back to this at some stage... //do dto hocus pocus if needed if (typeof(TRead) != typeof(TDto)) { //Note: IDTO is on the DTO and is implemented on instance obviously. so need one var inst = Cartomatic.Utils.Dto.IDtoUtils.CrateIDtoInstance <TDto>(); return(Ok(data.Select(d => inst.ToDto(d)).ToList())); } else { return(Ok(data)); } } else { return(NotFound()); } } catch (Exception ex) { return(this.HandleException(ex)); } }
public async Task <IActionResult> Get([FromRoute] Guid organizationuuid, [FromQuery] string sort = null, [FromQuery] string filter = null, [FromQuery] int start = 0, [FromQuery] int limit = 25) { try { //Note: //main mh env objects are kept in the maphive_meta db! var apps = await OrganizationContext.GetOrganizationLinkableAppsAsync(GetDefaultDbContext(), sort, filter, start, limit); if (apps != null) { HttpContext.AppendTotalHeader(apps?.count ?? 0); return(Ok(apps?.applications)); } return(NotFound()); } catch (Exception ex) { return(this.HandleException(ex)); } }