private INewsletterItem Convert(IContent content, string hostName = null) { var host = content as Host; var trip = content as Trip; if (host != null) { return(new NewsletterHostViewModel { Name = host.Name, ImageUrl = host.ImageUrl, Job = host.Job, }); } else if (trip != null) { return(new NewsletterTripViewModel { Name = trip.Name, Country = trip.Country, HostName = hostName ?? _hostService.GetById(trip.HostId)?.Name, ImageUrl = trip.ImageUrl, }); } return(null); }
public IActionResult GetById(int id) { var result = _hostService.GetById(id); if (result.Success) { return(Ok(result)); } return(BadRequest(result)); }
public async Task <IActionResult> GetHostsById( [HttpTrigger(AuthorizationLevel.Anonymous, "get", Route = "hosts/{id}")] HttpRequest req, string id, ILogger log) { try { log.LogInformation("Get hosts function called"); Host host = await _hostService.GetById(id); return((ActionResult) new OkObjectResult(host)); } catch (Exception ex) { var error = $"Gethosts failed: {ex.Message}"; log.LogError(error); return(new BadRequestObjectResult(error)); } }