public ActionResult Get(Guid ownerId, [FromQuery] AccountQueryStringParams accountParams) { try { var owner = _repositoryWrapper.Owner.GetOwnerById(ownerId); if (owner == null) { return(BadRequest("no owner found ")); } else { var accounts = _repositoryWrapper.Account.getAccountsByOwner(ownerId, accountParams); var metadata = new { accounts.TotalCount, accounts.PageSize, accounts.CurrentPage, accounts.TotalPages, accounts.HasNext, accounts.HasPrevious }; Response.Headers.Add("X-Pagination", JsonConvert.SerializeObject(metadata)); var accountsDto = _mapper.Map <IEnumerable <Account>, IEnumerable <AccountDto> >(accounts); return(Ok(accountsDto.SelectByFieldsQuery(accountParams.fields))); } } catch { return(StatusCode(StatusCodes.Status500InternalServerError, "try again later")); } }
public PagedList <Account> getAccountsByOwner(Guid ownerId, AccountQueryStringParams accountParams) { var accounts = FindByCondition(a => a.OwnerId.Equals(ownerId)).OrderByQueryOrDefault(accountParams.OrderBy, "DateCreated", false); var count = accounts.Count(); var accountsList = accounts.Paginate(accountParams.PageSize, accountParams.PageNumber).ToList(); return(new PagedList <Account>(accountsList, count, accountParams.PageNumber, accountParams.PageSize)); }
public ActionResult <OwnerDto> GetOwnerById(Guid ownerId, Guid id, [FromQuery] AccountQueryStringParams accountParams) { try { var owner = _repositoryWrapper.Owner.GetOwnerById(ownerId); if (owner == null) { return(NotFound()); } else { var account = _repositoryWrapper.Account.GetAccountById(id); var accountDto = _mapper.Map <AccountDto>(account); return(Ok(accountDto.shapeObject(accountParams.fields))); } } catch { return(StatusCode(StatusCodes.Status500InternalServerError, "try again later")); } }