// PUT api/RestaurantTag/5
        public IHttpActionResult PutRestaurantTag(int id, RestaurantTag restauranttag)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            if (id != restauranttag.RestaurantTagID)
            {
                return(BadRequest());
            }

            db.Entry(restauranttag).State = EntityState.Modified;

            try
            {
                db.SaveChanges();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!RestaurantTagExists(id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(StatusCode(HttpStatusCode.NoContent));
        }
        public async Task AddTagsToRestaurant(Restaurant restaurant, List <string> tags)
        {
            foreach (string tag in tags)
            {
                var dbTag = GetTagByName(tag);
                if (dbTag == null)
                {
                    // tag does not exist, add it
                    dbTag = new Tag
                    {
                        Name = tag.Trim().ToLower()
                    };

                    await _tagRepository.Add(dbTag);
                }

                // create the restaurant-tag link
                var restaurantTag = new RestaurantTag
                {
                    Restaurant   = restaurant,
                    RestaurantId = restaurant.RestaurantId,
                    Tag          = dbTag,
                    TagId        = dbTag.TagId
                };

                await _restaurantTagRepository.Add(restaurantTag);
            }
        }
        public async Task UpdateRestaurantTags(Restaurant restaurant, List <string> tags)
        {
            foreach (string tag in tags)
            {
                var dbTag = GetTagByName(tag);
                if (dbTag == null)
                {
                    // tag does not exist, add it
                    dbTag = new Tag
                    {
                        Name = tag.Trim().ToLower()
                    };

                    await _tagRepository.Add(dbTag);
                }

                // check to see if the link exists
                var dbRestaurantTag = _restaurantTagRepository.Get(rt => rt.RestaurantId == restaurant.RestaurantId && rt.TagId == dbTag.TagId).FirstOrDefault();
                if (dbRestaurantTag == null)
                {
                    // link does not exist, create it
                    var restaurantTag = new RestaurantTag
                    {
                        Restaurant   = restaurant,
                        RestaurantId = restaurant.RestaurantId,
                        Tag          = dbTag,
                        TagId        = dbTag.TagId
                    };

                    await _restaurantTagRepository.Add(restaurantTag);
                }
            }
        }
        public IHttpActionResult GetRestaurantTag(int id)
        {
            RestaurantTag restauranttag = db.RestaurantTags.Find(id);

            if (restauranttag == null)
            {
                return(NotFound());
            }

            return(Ok(restauranttag));
        }
        public IHttpActionResult PostRestaurantTag(RestaurantTag restauranttag)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            db.RestaurantTags.Add(restauranttag);
            db.SaveChanges();

            return(CreatedAtRoute("DefaultApi", new { id = restauranttag.RestaurantTagID }, restauranttag));
        }
        public IHttpActionResult DeleteRestaurantTag(int id)
        {
            RestaurantTag restauranttag = db.RestaurantTags.Find(id);

            if (restauranttag == null)
            {
                return(NotFound());
            }

            db.RestaurantTags.Remove(restauranttag);
            db.SaveChanges();

            return(Ok(restauranttag));
        }