private EventModel GetEventModel(int id) { if (id == 0) { return(null); } var ev = _repo.GetEvent(id); var firstName = ev.HostFirstName; var lastName = ev.HostLastName; var host = _repo.GetUserByName(firstName, lastName); var hostModel = Mapper.Map <UserModel>(host); var eventModel = Mapper.Map <EventModel>(ev); eventModel.Host = hostModel; return(eventModel); }
public IActionResult Get(int id) { try { var ev = _repo.GetEvent(id); if (ev == null) { return(NotFound()); } var model = Mapper.Map <EventModel>(ev); model.Host = GetHostModel(ev); return(Ok(model)); } catch (Exception ex) { _logger.LogError($"Exception thrown while fetching event: {ex}"); } return(BadRequest("Could not fetch event")); }