public IHttpActionResult CreateNewMeal(CreateMealBindingModel mealBindingModel)
        {
            var userId = this.User.Identity.GetUserId();

            if (mealBindingModel == null)
            {
                return this.BadRequest("Data is missing");
            }

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

            var restaurant = this.Data.Restaurants.GetAll().FirstOrDefault(r => r.Id == mealBindingModel.RestaurantId);

            if (restaurant == null)
            {
                return this.BadRequest("Invalid restaurant data");
            }

            if (userId != restaurant.OwnerId)
            {
                return this.Unauthorized();
            }

            var newMeal = new Meal
                {
                    Name = mealBindingModel.Name, 
                    Price = mealBindingModel.Price, 
                    TypeId = mealBindingModel.TypeId, 
                    RestaurantId = mealBindingModel.RestaurantId
                };
            this.Data.Meals.Add(newMeal);
            this.Data.SaveChanges();

            var mealView = this.Data.Meals.GetAll()
                .Where(m => m.Id == newMeal.Id)
                .Select(MealViewModel.Create())
                .FirstOrDefault();

            var uriLocation = new
                {
                    controller = "meals", 
                    id = newMeal.Id
                };

            return this.CreatedAtRoute("DefaultApi", uriLocation, mealView);
        }
        private void PopulateDatabase()
        {
            // Register
            this.Register("uti");
            this.Register("guest");

            // Login
            var loginData = this.Login("uti");

            this.client.DefaultRequestHeaders.Add("Authorization", "Bearer " + loginData.Access_Token);

            // Create Restaurant
            var restaurant = new RestaurantBindingModel
                {
                    Name = "Pri uti", 
                    TownId = 2
                };

            var restaurantBody = new FormUrlEncodedContent(new[]
                {
                    new KeyValuePair<string, string>("name", restaurant.Name), 
                    new KeyValuePair<string, string>("townId", restaurant.TownId.ToString())
                });

            var restaurantResponse = this.client.PostAsync("api/restaurants", restaurantBody).Result;
            var restaurantId = restaurantResponse.Content.ReadAsAsync<RestaurantViewModel>().Result.Id;

            // Create Meals
            var mealOne = new CreateMealBindingModel
                {
                    Name = "musaka", 
                    Price = 4.5M, 
                    TypeId = 3, 
                    RestaurantId = restaurantId
                };

            var mealTwo = new CreateMealBindingModel
                {
                    Name = "tarator", 
                    Price = 2.5M, 
                    TypeId = 2, 
                    RestaurantId = restaurantId
                };

            var mealOneBody = new FormUrlEncodedContent(new[]
                {
                    new KeyValuePair<string, string>("name", mealOne.Name), 
                    new KeyValuePair<string, string>("price", mealOne.Price.ToString(CultureInfo.InvariantCulture)), 
                    new KeyValuePair<string, string>("typeId", mealOne.TypeId.ToString()), 
                    new KeyValuePair<string, string>("restaurantId", mealOne.RestaurantId.ToString())
                });

            var mealTwoBody = new FormUrlEncodedContent(new[]
                {
                    new KeyValuePair<string, string>("name", mealTwo.Name), 
                    new KeyValuePair<string, string>("price", mealTwo.Price.ToString(CultureInfo.InvariantCulture)), 
                    new KeyValuePair<string, string>("typeId", mealTwo.TypeId.ToString()), 
                    new KeyValuePair<string, string>("restaurantId", mealTwo.RestaurantId.ToString())
                });

            var mealOneResponse = this.client.PostAsync("api/meals", mealOneBody).Result;
            var mealTwoResponse = this.client.PostAsync("api/meals", mealTwoBody).Result;

            // Clean headers
            this.client.DefaultRequestHeaders.Remove("Authorization");
        }