public IActionResult GetByParams(string query, int page) { var hal = new ListItemsInHalJsonViewModel { Content = new List <Application.ViewModel.Get.UserViewModel> { new Application.ViewModel.Get.UserViewModel { Id = Guid.NewGuid(), Nome = "Foo", Username = "******" }, new Application.ViewModel.Get.UserViewModel { Id = Guid.NewGuid(), Nome = "Foo", Username = "******" } }, Total = 2, TotalPerPage = 2, ContentListName = "usuarios", SelfRouter = "api/users/q/{query}/page/{page}", ItemRouter = "api/users/{id}", Paramters = new Dictionary <string, string> { { "{query}", query }, { "{page}", page.ToString() } } }; return(Response(hal)); }
/** * Por questões de tempo acabei forçando o tipo no método, * tenho poucas coisas com HALJson por normalmente RestFul (somente Rest) não é minha realidade de trabalho =/ * @todo Corrigir esta quesão do next */ protected new IActionResult Response(ListItemsInHalJsonViewModel result) { if (_modelStateErrors.Any()) { return(BadRequest(new { success = false, errors = _modelStateErrors })); } var contentLinks = new List <Link>(); var embbedLinks = new List <Link>(); foreach (var user in (List <UserViewModel>)result.Content) { embbedLinks.Add(new Link("self", result.ItemRouter.Replace("{id}", user.Id.ToString()))); } var self = result.SelfRouter; var next = result.SelfRouter; foreach (var kp in result.Paramters) { if (kp.Key.Equals("{page}")) { next = self.Replace(kp.Key, (Convert.ToInt32(kp.Value) + 1).ToString()); } self = self.Replace(kp.Key, kp.Value); } contentLinks.Add(new Link("self", self)); contentLinks.Add(new Link("next", next)); return(this.HAL( new { total = result.Total, perPage = result.TotalPerPage }, contentLinks, result.ContentListName, (List <UserViewModel>)result.Content, embbedLinks)); }