public IHttpActionResult RateRestaurant(int id, RateInputModel ratingData)
        {
            var currentUserId = User.Identity.GetUserId();
            var restaurantBeingRated = this.Data.Restaurants.Find(id);
            if (restaurantBeingRated == null)
            {
                return this.NotFound();
            }
            if (currentUserId == restaurantBeingRated.OwnerId)
            {
                return this.BadRequest();
            }
            if (ratingData.Stars < 1 || ratingData.Stars > 10)
            {
                return this.BadRequest();
            }
            var currentUserRestaurantRating = restaurantBeingRated.Ratings
                .Where(rating => rating.UserId == currentUserId)
                .FirstOrDefault();

            if (currentUserRestaurantRating != null)
            {
                this.Data.Ratings.Remove(currentUserRestaurantRating);
            }

            this.Data.Ratings.Add(new Rating()
            {
                RestaurantId = restaurantBeingRated.Id,
                Stars = ratingData.Stars,
                UserId = currentUserId
            });
            this.Data.SaveChanges();

            return this.Ok();
        }
        public IHttpActionResult AddRating(int id, RateInputModel ratingData)
        {
            if (ratingData == null)
            {
                return BadRequest("Missing rating data.");
            }

            if (!ModelState.IsValid)
            {
                return BadRequest(ModelState);
            }

            if(ratingData.Stars < 1 || ratingData.Stars > 10)
            {
                return this.BadRequest("Incorrect stars");
            }

            var restaurant = db.Restaurants.Find(id);
            if (restaurant == null)
            {
                return this.NotFound();
            }

            var currentUser = User.Identity.IsAuthenticated;
            var userName = User.Identity.Name;

            if (!currentUser)
            {
                return this.Unauthorized();
            }

            var userId = db.Users
                .Where(u => u.UserName == userName)
                .Select(u => u.Id).FirstOrDefault();

            var ownerRestaurantId = db.Restaurants
                .Where(r => r.OwnerId == userId && r.Id == id)
                .Select(r => r.Id).FirstOrDefault();            

            
            if(ownerRestaurantId == id)
            {
                return this.BadRequest("The restaurant owner can not rates his own restaurant!!!");
            }

            var rating = new Rating()
            {
                UserId = userId,
                RestaurantId = id,
                Stars = ratingData.Stars
            };
            db.Ratings.Add(rating);
            db.SaveChanges();

            return this.Ok();
        }