public ActionResult <IEnumerable <DogDTO> > GetDogs([FromQuery] EntityResourceParameters parameters) { //ako ne postoji mapa za unet properti za odgovarajuce klase, vracamo gresku sa // statusnim kodom 400 if (!propertyMappingService.ValidMappingExistsFor <DogDTO, Dog>(parameters.OrderBy)) { return(BadRequest()); } if (parameters.PageSize == 0) { parameters.PageSize = dogService.GetAll().ToList().Count(); } var dogs = dogService.GetAll(parameters); var previousPageLink = dogs.HasPrevious ? CreateDogsResourceUri(parameters, ResourceUriType.PreviousPage) : null; var nextPageLink = dogs.HasNext ? CreateDogsResourceUri(parameters, ResourceUriType.NextPage) : null; var paginationMetadata = new { totalCount = dogs.TotalCount, pageSize = dogs.PageSize, currentPage = dogs.CurrentPage, totalPages = dogs.TotalPages, previousPageLink, nextPageLink }; Response.Headers.Add("X-Pagination", JsonSerializer.Serialize(paginationMetadata)); var dogsDTO = mapper.Map <IEnumerable <DogDTO> >(dogs); return(Ok(dogsDTO)); }
public IActionResult Index([FromQuery] string info, [FromQuery] bool search, [FromQuery] string txtName) { if (search) { var dogs = service.GetDogsByName(txtName).Result; ViewBag.Info = $"{dogs.ToList().Count} dogs found."; return(View(dogs)); } if (info != null) { ViewBag.Info = info; } return(View(service.GetAll().Result)); }
/// <summary> /// jqGrid datasource for dogs /// </summary> /// <param name="sord"></param> /// <param name="page"></param> /// <param name="rows"></param> /// <param name="searchString"></param> /// <returns></returns> public ActionResult DogDatasource(string id, string sidx, string sord, int page, int rows, string searchString, string sopt) { try { IEnumerable <Dog> Results = _dogService.GetAll(); int pageIndex = Convert.ToInt32(page) - 1; int pageSize = rows; //#4 Get Total Row Count int totalRecords = Results.Count(); var totalPages = (int)Math.Ceiling((float)totalRecords / (float)rows); //#5 Setting Sorting if (sord != null) { if (sord.ToUpper() == "DESC") { Results = Results.OrderByDescending(s => s.DogName); Results = Results.Skip(pageIndex * pageSize).Take(pageSize); } else { Results = Results.OrderBy(s => s.DogName); Results = Results.Skip(pageIndex * pageSize).Take(pageSize); } } //#6 Setting Search if (!string.IsNullOrEmpty(searchString)) { Results = Results.Where(m => m.DogName.Contains(searchString)); } //#7 Sending Json Object to View. var jsonData = new { total = totalPages, page, records = totalRecords, rows = Results }; return(Json(jsonData, JsonRequestBehavior.AllowGet)); } catch (Exception ex) { log.Error(ex); return(Json("Couldn't get list", JsonRequestBehavior.AllowGet)); } }
public ActionResult <IEnumerable <DogResponse> > GetAll() { var dogs = _dogService.GetAll(); return(Ok(dogs)); }
public IEnumerable <DogDto> GetDogs() { var dogs = _dogService.GetAll(); return(dogs); }
public ActionResult Dogs() { List <Dog> dogs = dogService.GetAll().ToList(); return(View(dogs)); }
public ActionResult <List <ResponseModel> > Get() { return(Ok(_dogService.GetAll())); }