public async Task <ResultOrHttpError <CaseworkerList, Error> > GetAllCaseworkerDataFromMomentumCoreAsync(string path, int pageNumber) { var pageSize = 100; pageNumber = pageNumber == 0 ? 1 : pageNumber; List <CaseworkerDataResponseModel> totalRecords = new List <CaseworkerDataResponseModel>(); var queryStringParams = $"pagingInfo.pageNumber={pageNumber}&pagingInfo.pageSize={pageSize}"; var response = await _meaClient.GetAsync(path + "?" + queryStringParams).ConfigureAwait(false); if (response.IsError) { return(new ResultOrHttpError <CaseworkerList, Error>(response.Error, response.StatusCode.Value)); } var content = response.Result; var caseworkerDataObj = JsonConvert.DeserializeObject <PUnitData>(content); var records = caseworkerDataObj.Data; foreach (var item in records) { var dataToReturn = new CaseworkerDataResponseModel(item.Id, item.DisplayName, item.GivenName, item.MiddleName, item.Initials, item.Email?.Address, item.Phone?.Number, item.CaseworkerIdentifier, item.Description, item.IsActive, item.IsBookable); totalRecords.Add(dataToReturn); } var responseData = new CaseworkerList() { PageNo = pageNumber, TotalNoOfPages = caseworkerDataObj.TotalPages, TotalSearchCount = caseworkerDataObj.TotalSearchCount, Result = totalRecords }; return(new ResultOrHttpError <CaseworkerList, Error>(responseData)); }
public async Task <ResultOrHttpError <CitizenList, Error> > GetAllActiveCitizenDataFromMomentumCoreAsync(string path, int pageNumber) { List <JToken> totalRecords = new List <JToken>(); List <string> JsonStringList = new List <string>(); var pageNo = pageNumber; var size = 100; var skip = (pageNo - 1) * size; var queryStringParams = $"term=Citizen&size={size}&skip={skip}&isActive=true"; var response = await _meaClient.GetAsync(path + "?" + queryStringParams).ConfigureAwait(false); if (response.IsError) { return(new ResultOrHttpError <CitizenList, Error>(response.Error, response.StatusCode.Value)); } var content = response.Result; int.TryParse(JObject.Parse(content)["totalCount"].ToString(), out int totalCount); if (pageNumber > (totalCount / size) + 1) { var error = new Error(_correlationId, new[] { "No Records are available for entered page number" }, "MEA"); Log.ForContext("CorrelationId", _correlationId) .ForContext("ClientId", _clientId) .Error("No Records are available for entered page number"); return(new ResultOrHttpError <CitizenList, Error>(error, HttpStatusCode.BadRequest)); } var jsonArray = JArray.Parse(JObject.Parse(content)["results"].ToString()); totalRecords.AddRange(jsonArray.Children()); foreach (var item in totalRecords) { var jsonToReturn = JsonConvert.SerializeObject(new { citizenId = item["id"], displayName = item["name"], givenName = (string)null, middleName = (string)null, initials = (string)null, address = (string)null, number = (string)null, caseworkerIdentifier = (string)null, description = item["description"], isBookable = true, isActive = true }); JsonStringList.Add(jsonToReturn); } var totalPages = (totalCount / size) + 1; var data = JsonStringList.Select(x => JsonConvert.DeserializeObject <CitizenDataResponseModel>(x)); var citizenList = new CitizenList(totalPages, totalCount, pageNo, data.ToList()); return(new ResultOrHttpError <CitizenList, Error>(citizenList)); }