public List <DebtCard> GetDebtCards([FromRoute] int page = 1) { var qry = _context.DebtCards.OrderBy(p => p.ID); foreach (DebtCard a in qry) { _context.Entry(a).Navigation("LibrarySystem").Load(); } PagingList <DebtCard> DebtCardsList; if (page != 0) { DebtCardsList = PagingList.Create(qry, StringsPerPage, page); } else { DebtCardsList = PagingList.Create(qry, _context.DebtCards.Count() + 1, 1); } return(DebtCardsList.ToList()); }
public async Task <IActionResult> GetValidDebtCardsPages(bool?valid = true, int page = 1) { if (valid == false) { foreach (DebtCard a in _context.DebtCards) { _context.Entry(a).Navigation("LibrarySystem").Load(); } PagingList <DebtCard> DebtCardsList; if (page != 0) { DebtCardsList = PagingList.Create(_context.DebtCards.ToList(), StringsPerPage, page); } else { DebtCardsList = PagingList.Create(_context.DebtCards.ToList(), _context.DebtCards.ToList().Count() + 1, 1); } return(Ok(DebtCardsList.ToList())); } else { var qry = _context.DebtCards.OrderBy(p => p.ID); foreach (DebtCard a in qry) { _context.Entry(a).Navigation("LibrarySystem").Load(); } // //Вытаскиваем все Арены // List <Book> QryBooks = new List <Book>(); var corrId = string.Format("{0}{1}", DateTime.Now.Ticks, Thread.CurrentThread.ManagedThreadId); string request; byte[] responseMessage; using (var client = new HttpClient()) { client.BaseAddress = new Uri(URLBookService); client.DefaultRequestHeaders.Accept.Clear(); client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json")); string requestString = "api/Books"; HttpResponseMessage response = await client.GetAsync(requestString); request = "SERVICE: BookService \r\nGET: " + URLBookService + "/" + requestString + "\r\n" + client.DefaultRequestHeaders.ToString(); string responseString = response.Headers.ToString() + "\nStatus: " + response.StatusCode.ToString(); if (response.IsSuccessStatusCode) { responseMessage = await response.Content.ReadAsByteArrayAsync(); var Books = await response.Content.ReadAsStringAsync(); QryBooks = JsonConvert.DeserializeObject <List <Book> >(Books); } else { responseMessage = Encoding.UTF8.GetBytes(response.ReasonPhrase); } await LogQuery(request, responseString, responseMessage); } // //Вытаскиваем всех Артистов // List <Library> QryLibrarys = new List <Library>(); var corrId2 = string.Format("{0}{1}", DateTime.Now.Ticks, Thread.CurrentThread.ManagedThreadId); string request2; byte[] responseMessage2; using (var client = new HttpClient()) { client.BaseAddress = new Uri(URLLibraryService); client.DefaultRequestHeaders.Accept.Clear(); client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json")); string requestString2 = "api/Librarys"; HttpResponseMessage response2 = await client.GetAsync(requestString2); request2 = "SERVICE: BookService \r\nGET: " + URLLibraryService + "/" + requestString2 + "\r\n" + client.DefaultRequestHeaders.ToString(); string responseString2 = response2.Headers.ToString() + "\nStatus: " + response2.StatusCode.ToString(); if (response2.IsSuccessStatusCode) { responseMessage2 = await response2.Content.ReadAsByteArrayAsync(); var Librarys = await response2.Content.ReadAsStringAsync(); QryLibrarys = JsonConvert.DeserializeObject <List <Library> >(Librarys); } else { responseMessage2 = Encoding.UTF8.GetBytes(response2.ReasonPhrase); } await LogQuery(request2, responseString2, responseMessage2); } // //Проверить на валидность все концерты // List <DebtCard> ValidDebtCards = new List <DebtCard>(); foreach (DebtCard c in qry) { //находим название Арены с таким же, как в концерте Book FindedBook; foreach (Book a in QryBooks) { if (a.BookName == c.BookName) { FindedBook = a; if (a.PageCount >= c.PaymentPerDay) { if (a.Author.AuthorName == c.AuthorName) { Library Library = QryLibrarys.Where(x => x.LibraryName == c.LibraryName).FirstOrDefault(); if (Library != null) { ValidDebtCards.Add(c); } } } } } } PagingList <DebtCard> DebtCardsList; if (page != 0) { DebtCardsList = PagingList.Create(ValidDebtCards, StringsPerPage, page); } else { DebtCardsList = PagingList.Create(ValidDebtCards, ValidDebtCards.Count() + 1, 1); } return(Ok(DebtCardsList.ToList())); } }