public async Task <IActionResult> AddListing(ListingForAddDto l) { int userid = int.Parse(User.FindFirst(ClaimTypes.NameIdentifier).Value); var userfromrepo = await _repo.GetUser(userid); var listingtocreate = _mapper.Map <Listing>(l); if (userfromrepo != null) { userfromrepo.Listings.Add(listingtocreate); } if (await _repo.SaveAll()) { return(CreatedAtRoute("GetListing", new { id = listingtocreate.Id }, listingtocreate)); } return(BadRequest("Could not add listing")); }
public async Task <IActionResult> GetUser(int id) { var user = await _repo.GetUser(id); return(Ok(user)); }