public ActionResult <List <GetReportRespond> > getAllReport(int from, int to, String orderby) { try{ GetAllReportRequest request = new GetAllReportRequest { From = from, To = to, OderBy = orderby }; return(Ok(_adminService.GetAllReport(request))); }catch (Exception e) { Console.WriteLine(e.Message); return(BadRequest(e.Message)); } }
public List <GetReportRespond> GetAllReport(GetAllReportRequest request) { int count = _reportRepository.Count(); List <GetReportRespond> list = new List <GetReportRespond>(); if (request.From < request.To || count < request.From || count < request.To) { throw new IndexOutOfRangeException(); } var read = _reportRepository.GetAllReport(count - request.To, request.OderBy); Report[] a = read.ToArray(); for (int i = count - request.From; i < count - request.To; i++) { list.Add(new GetReportRespond { Id = a[i].Id, Reporter = a[i].Reporter, Reason = a[i].Reason, Suspect = a[i].Suspect, Status = a[i].Status, Note = a[i].Note }); } return(list); }