public void Post([FromBody] Place place) { place.City = place.City.ToLower(); place.AverageRating = 0; _db.Places.Add(place); _db.SaveChanges(); }
public void Post([FromBody] Review review) { _db.Reviews.Add(review); Place place = _db.Places.Where(x => x.PlaceId == review.PlaceId).Include(x => x.Reviews).FirstOrDefault(); // if (place.Reviews.Count() != 0) { double averageRating = place.Reviews.Sum(y => y.Rating); averageRating = (averageRating / place.Reviews.Count()); place.AverageRating = averageRating; } else { place.AverageRating = 0; } _db.Entry(place).State = EntityState.Modified; _db.SaveChanges(); }
public User Create(User user, string password) { // validation if (string.IsNullOrWhiteSpace(password)) { throw new AppException("Password is required"); } if (_context.Users.Any(x => x.Username == user.Username)) { throw new AppException("Username \"" + user.Username + "\" is already taken"); } _context.Users.Add(user); _context.SaveChanges(); return(user); }
public void Post([FromBody] Review review) { _db.Reviews.Add(review); _db.SaveChanges(); City city = _db.Cities.Find(review.CityId); double averageRating = _db.Cities.Where(entry => entry.CityName == city.CityName) .Include(entry => entry.Reviews).SelectMany(entry => entry.Reviews).Average(x => x.Rating); city.OverallRating = averageRating; _db.SaveChanges(); }
public void Save() { _travelApiContext.SaveChanges(); }
public void Put(int id, [FromBody] Destination destination) { destination.DestinationId = id; _db.Entry(destination).State = EntityState.Modified; _db.SaveChanges(); }
public void Post([FromBody] Review review) { _db.Reviews.Add(review); _db.SaveChanges(); }
public void Post([FromBody] Place place) { _db.Places.Add(place); _db.SaveChanges(); }
public void Register([FromBody] User newUser) { _db.Users.Add(newUser); _db.SaveChanges(); }
public void Post([FromBody] Location location) { _db.Locations.Add(location); _db.SaveChanges(); }
public void Post([FromBody] City city) { _db.Cities.Add(city); _db.SaveChanges(); }
public void Post([FromBody] Country country) { _db.Countries.Add(country); _db.SaveChanges(); }
public void Post([FromBody] Rating rating) { _db.Ratings.Add(rating); _db.SaveChanges(); }
public void Post([FromBody] Review review) { review.Date = DateTime.Now; _db.Reviews.Add(review); _db.SaveChanges(); }