public IActionResult CreateFavorite(CreateFavoriteModelWithCategories model) { try { //creates coordinates for the favorite var coordToCreate = new Coordinates(); coordToCreate.Latitude = model.Latitude; coordToCreate.Longitude = model.Longitude; coordToCreate.Truck_Id = model.Truck_Id; var newCoordinate = _coordService.CreateCoordinate(coordToCreate); //creates the favorite var modelWithoutCategories = _mapper.Map <CreateFavoriteModel>(model); var favoriteToCreate = _mapper.Map <Favorite>(modelWithoutCategories); favoriteToCreate.Coordinate_Id = newCoordinate.Id; favoriteToCreate.Coordinates = newCoordinate; var createdFav = _favService.CreateFavorite(favoriteToCreate); //creates initial categories of that favorite pulled from yelp API foreach (string category in model.Categories) { var newCategory = new CreateCategoryModel(); newCategory.Name = category; newCategory.Favorite_Id = createdFav.Id; var categoryToCreate = _mapper.Map <Category>(newCategory); _categoryService.CreateCategory(categoryToCreate); } return(Ok(createdFav)); } catch (AppException ex) { return(BadRequest(new { message = ex.Message })); } }