Exemplo n.º 1
0
 public void Post([FromBody] Place place)
 {
     place.City          = place.City.ToLower();
     place.AverageRating = 0;
     _db.Places.Add(place);
     _db.SaveChanges();
 }
Exemplo n.º 2
0
        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();
        }
Exemplo n.º 3
0
        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);
        }
Exemplo n.º 4
0
        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();
        }
Exemplo n.º 5
0
 public void Save()
 {
     _travelApiContext.SaveChanges();
 }
 public void Put(int id, [FromBody] Destination destination)
 {
     destination.DestinationId    = id;
     _db.Entry(destination).State = EntityState.Modified;
     _db.SaveChanges();
 }
Exemplo n.º 7
0
 public void Post([FromBody] Review review)
 {
     _db.Reviews.Add(review);
     _db.SaveChanges();
 }
 public void Post([FromBody] Place place)
 {
     _db.Places.Add(place);
     _db.SaveChanges();
 }
Exemplo n.º 9
0
 public void Register([FromBody] User newUser)
 {
     _db.Users.Add(newUser);
     _db.SaveChanges();
 }
 public void Post([FromBody] Location location)
 {
     _db.Locations.Add(location);
     _db.SaveChanges();
 }
Exemplo n.º 11
0
 public void Post([FromBody] City city)
 {
     _db.Cities.Add(city);
     _db.SaveChanges();
 }
Exemplo n.º 12
0
 public void Post([FromBody] Country country)
 {
     _db.Countries.Add(country);
     _db.SaveChanges();
 }
Exemplo n.º 13
0
 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();
 }