public async Task <ActionResult <Location> > Post(Location location) { _db.Locations.Add(location); await _db.SaveChangesAsync(); return(CreatedAtAction(nameof(GetLocation), new { id = location.LocationId }, location)); }
public async Task <ActionResult <Review> > Post(Review review, int locationid) { var thisLocation = _db.Locations.Include(entry => entry.Reviews).FirstOrDefault(entry => entry.LocationId == locationid); review.LocationId = locationid; thisLocation.Reviews.Add(review); _db.Locations.Update(thisLocation); _db.Reviews.Add(review); await _db.SaveChangesAsync(); return(CreatedAtAction(nameof(GetReview), new { id = review.ReviewId }, review)); }
public async Task <ActionResult <Review> > Post(Review review, int locationid) { var thisLocation = _db.Locations.Include(entry => entry.Reviews).FirstOrDefault(entry => entry.LocationId == locationid); if (thisLocation != null) { review.LocationId = thisLocation.LocationId; thisLocation.Reviews.Add(review); _db.Locations.Update(thisLocation); await _db.SaveChangesAsync(); } else { return(BadRequest()); } // _db.Reviews.Add(review); // await _db.SaveChangesAsync(); // return CreatedAtAction("Post", new { id = message.GroupId}, thisGroup); return(CreatedAtAction(nameof(GetReview), new { id = review.LocationId }, thisLocation)); }