/// <summary>
 /// This function is used to save tags if Category Titel does not exists in the tag table
 /// </summary>
 /// <param name="category"></param>
 public void TagsSaveIfNotExists(Category category)
 {
     var _tag = _db.Tags.Where(t => t.Name.Equals(category.Title));
     if (_tag.Count() == 0)
     {
         Tag tag = new Tag()
         {
             Name = category.Title
         };
         _db.Tags.Add(tag);
         _db.SaveChanges();
     }
 }
 public bool AddCategory(Category category)
 {
     try
     {
         _db.Categories.Add(category);
         _db.SaveChanges();
         return true;
     }
     catch (Exception ex)
     {
         return false;
     }
 }
        public bool UpdateCategory(Category category)
        {
            _db.Entry(category).State = EntityState.Modified;

            try
            {
                _db.SaveChanges();
                return true;
            }
            catch (Exception ex)
            {
                return false;
            }
        }
        // PUT api/Category/5
        public HttpResponseMessage PutCategory(int id, Category category)
        {
            if (!IsAuthorize("write"))
            {
                return Request.CreateResponse(HttpStatusCode.Unauthorized);
            }
            if(ModelState.IsValid && id == category.Id)
            {
                if(_facade.UpdateCategory(category))
                    return Request.CreateResponse(HttpStatusCode.OK, category);
                else
                    return Request.CreateResponse(HttpStatusCode.NotModified);

            }
            else
            {
                return Request.CreateResponse(HttpStatusCode.BadRequest);
            }
        }
 // POST api/Category
 public HttpResponseMessage PostCategory(Category item)
 {
     if (!IsAuthorize("write"))
     {
         return Request.CreateResponse(HttpStatusCode.Unauthorized);
     }
     if(ModelState.IsValid)
     {
         _facade.AddCategory(item);
         _facade.TagsSaveIfNotExists(item);
         HttpResponseMessage response = Request.CreateResponse(HttpStatusCode.Created, item);
         response.Headers.Location = new Uri(Url.Link("DefaultApi", new
         {
             id = item.Id
         }));
         return response;
     }
     else
     {
         return Request.CreateResponse(HttpStatusCode.BadRequest);
     }
 }